Index: vm/tests/kernel/java/lang/ClassTestGetResourceAsStream.java =================================================================== --- vm/tests/kernel/java/lang/ClassTestGetResourceAsStream.java (revision 463094) +++ vm/tests/kernel/java/lang/ClassTestGetResourceAsStream.java (working copy) @@ -44,8 +44,7 @@ /** * The method throws NullPointerException if argument is null */ -//Commented because 6793 bug isn't fixed - public void te_st1() { + public void test1() { try { Void.class.getResourceAsStream(null); fail("Error1: NullPointerException is not thrown for null argument"); Index: vm/tests/kernel/java/lang/RuntimeAdditionalTest12.java =================================================================== --- vm/tests/kernel/java/lang/RuntimeAdditionalTest12.java (revision 463094) +++ vm/tests/kernel/java/lang/RuntimeAdditionalTest12.java (working copy) @@ -152,12 +152,17 @@ is4.close(); pi3.destroy(); pi4.destroy(); - pi3.exitValue(); - pi4.exitValue(); + try { + pi3.exitValue(); + } catch (IllegalThreadStateException _) { + } + try { + pi4.exitValue(); + } catch (IllegalThreadStateException _) { + } cmnd1 = RuntimeAdditionalTest0.cm + " /C ps -ef"; Process pi5 = Runtime.getRuntime().exec(cmnd1); - BufferedReader br = new BufferedReader(new InputStreamReader(pi5 - .getInputStream())); + BufferedReader br = new BufferedReader(new InputStreamReader(pi5.getInputStream())); boolean flg = true; String procValue = null; while ((procValue = br.readLine()) != null) { @@ -180,6 +185,7 @@ } } }catch(Exception e){ + e.printStackTrace(); fail("ERROR (test_14): unexpected exception: "+e.toString()); } } Index: vm/tests/kernel/java/lang/RuntimeAdditionalTest40.java =================================================================== --- vm/tests/kernel/java/lang/RuntimeAdditionalTest40.java (revision 463094) +++ vm/tests/kernel/java/lang/RuntimeAdditionalTest40.java (working copy) @@ -99,7 +99,7 @@ is.read(bbb); os4.write(bbb); //**/RuntimeAdditionalTest0.doMessage("XXXXXXXXXXXXXX2!\n"); - while (ia != is4.available()) { + while (ia != is4.available() && flg4 == false) { os4.flush(); } //**/RuntimeAdditionalTest0.doMessage("XXXXXXXXXXXXXX3!\n"); @@ -222,6 +222,7 @@ static boolean flg3 = false; + static boolean flg4 = false; public void test_38() { System.out.println("==test_38==="); if (RuntimeAdditionalTest0.os.equals("Unk")) { @@ -263,6 +264,7 @@ ppp3.destroy(); ppp4.destroy(); t1.interrupt(); + flg4 = true; t3.join(); t2.join(); t1.join(); Index: vm/tests/kernel/java/lang/RuntimeAdditionalTest44.java =================================================================== --- vm/tests/kernel/java/lang/RuntimeAdditionalTest44.java (revision 0) +++ vm/tests/kernel/java/lang/RuntimeAdditionalTest44.java (revision 0) @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Tatyana V.Doubtsova, Serguei S.Zapreyev + * @version $Revision$ + */ +package java.lang; +import junit.framework.TestCase; +public class RuntimeAdditionalTest44 extends TestCase { + + public void test_44() { + RunningThread t = new RunningThread(); + t.start(); + while (!t.started) { + Thread.yield(); + } + + try { + Runtime.getRuntime().addShutdownHook(t); + fail("FAILED: addShutdownHook(running thread) does not throw IllegalArgumentException"); + } catch (IllegalArgumentException _){ + } + + synchronized (t.obj) { + t.may_wakeup = true; + t.obj.notify(); + } + + while(!t.ended){ + Thread.yield(); + } + + try { + t.join(); + } catch (InterruptedException ie){ + } + } +} +class RunningThread extends Thread { + volatile boolean started = false; + volatile boolean ended = false; + volatile boolean may_wakeup = false; + Object obj = new Object(); + public void run() { + synchronized (obj) { + while (!may_wakeup) { + try { + started = true; + obj.wait(); + } catch (InterruptedException ie){ + } + } + } + ended = true; + } +} Index: vm/tests/kernel/java/lang/reflect/MethodTest.java =================================================================== --- vm/tests/kernel/java/lang/reflect/MethodTest.java (revision 463094) +++ vm/tests/kernel/java/lang/reflect/MethodTest.java (working copy) @@ -260,8 +260,6 @@ /** * */ -//Commented because of the drlvm issue -/* public void test_invoke_Obj_Obj() { class X { @@ -279,10 +277,46 @@ fail("Error2: " + e.toString()); } } -*/ + /** * */ + public void test_invoke_Obj_Obj_2() { + int sz = 500000; + Object obj = null; + Class cls = null; + Method m; + try { + cls = Class.forName("java.lang.reflect.AuxiliaryClass"); + obj = cls.newInstance(); + } catch (Throwable e) { + e.printStackTrace(); + fail("Test failed during class creation: Unexpected error: "+e); + } + int pp = 0; + for (int j = 0; j < sz; j++) { + try { + m = cls.getMethod("get", (Class[])null); + int ans = ((Integer) (m.invoke(obj, (Object[])null))).intValue(); + fail("Test failed: Expected error was not thrown:" +ans + +" stepNumb: "+ j +" method name: " + + m.getDeclaringClass().getName()+"."+m.getName()); + } catch (InvocationTargetException e) { + pp++; + } catch (Throwable e) { + e.printStackTrace(); + fail("Test failed: Unexpected error: "+e); + } + } + if(pp != sz) { + fail("test_invoke_Obj_Obj_2 test failed"); + } + } + + + /** + * + */ public void test_toString_Obj() { class X { public X first(X a9) { @@ -294,9 +328,9 @@ Method m = X.class.getDeclaredMethod("first", new Class[] { X.class }); assertEquals("Error1 ", - "public java.lang.reflect.MethodTest$9X " + - "java.lang.reflect.MethodTest$9X.first(" + - "java.lang.reflect.MethodTest$9X)", + "public java.lang.reflect.MethodTest$10X " + + "java.lang.reflect.MethodTest$10X.first(" + + "java.lang.reflect.MethodTest$10X)", m.toString()); } catch (Exception e) { fail("Error2: " + e.toString()); Index: vm/tests/kernel/java/lang/reflect/FieldTest.java =================================================================== --- vm/tests/kernel/java/lang/reflect/FieldTest.java (revision 463094) +++ vm/tests/kernel/java/lang/reflect/FieldTest.java (working copy) @@ -85,16 +85,14 @@ /** * */ -//Commented because of the drlvm issue -/* public void test_get_Obj() { - class X { + class X1 { public int Xfld = 777; } - X x = new X(); + X1 x = new X1(); x.Xfld = 333; try { - Field f1 = X.class.getField("Xfld"); + Field f1 = X1.class.getField("Xfld"); assertTrue("Error1: x.Xfld should be equal 333", ((Integer) (f1 .get(x))).intValue() == 333); } catch (Exception e) { @@ -102,7 +100,7 @@ fail("Error2: " + e.toString()); } try { - Field f1 = X.class.getField("Xfld"); + Field f1 = X1.class.getField("Xfld"); f1.get(null); fail("Error3: NullPointerException should be risen just above"); } catch (NullPointerException _) { @@ -111,7 +109,7 @@ fail("Error4: " + e.toString()); } } -*/ + /** * */ @@ -379,11 +377,9 @@ /** * */ -//Commented because of the drlvm issue -/* public void test_set_Obj_Obj() { - class X { - X xx; + class X2 { + X2 xx; int Yfld = 777; @@ -391,13 +387,13 @@ return Yfld; }; } - X x = new X(); + X2 x = new X2(); try { - Field f1 = X.class.getDeclaredField("Yfld"); + Field f1 = X2.class.getDeclaredField("Yfld"); f1.set(x, new Integer(345)); assertTrue("Error1", x.m() == 345); - f1 = X.class.getDeclaredField("xx"); + f1 = X2.class.getDeclaredField("xx"); f1.set(x, x); assertTrue("Error2", x.xx.Yfld == 345); assertTrue("Error3", x.xx.m() == 345); @@ -411,7 +407,7 @@ fail("Error6: " + e.toString()); } } -*/ + /** * */ Index: vm/tests/kernel/java/lang/reflect/ConstructorTest.java =================================================================== --- vm/tests/kernel/java/lang/reflect/ConstructorTest.java (revision 463094) +++ vm/tests/kernel/java/lang/reflect/ConstructorTest.java (working copy) @@ -234,30 +234,28 @@ /** * */ -//Commented because of the drlvm issue -/* public void test_newInstance_Obj() { - class X { - public X() { + class X1 { + public X1() { return; } - public X(X a9) { + public X1(X1 a9) { return; } } - X x = new X(new X()); + X1 x = new X1(new X1()); try { - Constructor m = X.class.getDeclaredConstructor(new Class[] { - java.lang.reflect.ConstructorTest.class, X.class }); + Constructor m = X1.class.getDeclaredConstructor(new Class[] { + java.lang.reflect.ConstructorTest.class, X1.class }); Object o = m.newInstance(new Object[] { - new java.lang.reflect.ConstructorTest(), new X() }); - assertTrue("Error1", o instanceof X); + new java.lang.reflect.ConstructorTest(), new X1() }); + assertTrue("Error1", o instanceof X1); } catch (Exception e) { fail("Error2: " + e.toString()); } } -*/ + /** * */ Index: vm/tests/kernel/java/lang/reflect/AuxiliaryClass.java =================================================================== --- vm/tests/kernel/java/lang/reflect/AuxiliaryClass.java (revision 0) +++ vm/tests/kernel/java/lang/reflect/AuxiliaryClass.java (revision 0) @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Serguei S.Zapreyev + * @version $Revision$ + */ + +package java.lang.reflect; + +import junit.framework.TestCase; +/* + * Created on 10.12.2006 + * + * This AuxiliaryClass class is used to support + * MethodTest.test_invoke_Obj_Obj_2() test case + */ + +public class AuxiliaryClass { + public int get() throws Throwable { + int t1 = 1; + int t2 = 0; + return t1/t2; + } +} Index: vm/tests/kernel/java/lang/RuntimeAdditionalTest45.java =================================================================== --- vm/tests/kernel/java/lang/RuntimeAdditionalTest45.java (revision 0) +++ vm/tests/kernel/java/lang/RuntimeAdditionalTest45.java (revision 0) @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Tatyana V.Doubtsova, Serguei S.Zapreyev + * @version $Revision$ + */ +package java.lang; +import junit.framework.TestCase; +import java.io.IOException; +import java.io.InputStream; +import java.io.File; +public class RuntimeAdditionalTest45 extends TestCase { + static final int N_OF_HOOKS = 10; + static final String ok = "ok"; + static final String delimiter = ":"; + + public void test_45() { + runApp("java.lang.AddHookWhileHookRunning"); + runApp("java.lang.RmHookWhileHookRunning"); + } + + void runApp(String className) { + String[] cmd = createCmdLine(className); + + try { + Process p = Runtime.getRuntime().exec(cmd); + p.waitFor(); + checkOutput(p); + } catch (Exception e){ + e.printStackTrace(); + fail("Unexpected exception while exec()"); + } + } + + void checkOutput(Process p) { + // we check output from the hooks - if it is as expected + // then the exception was thrown as expected. + + InputStream is = p.getInputStream(); + int read_byte = 0; + int i = 0; + byte[] b = new byte[N_OF_HOOKS * 5 * 10]; + + try { + while ((read_byte = is.read()) > 0) { + b[i++] = (byte)read_byte; + } + } catch (IOException ioe) { + ioe.printStackTrace(); + fail("IOException while reading from process InputStream"); + } + + byte[] bb = new byte[i]; + System.arraycopy(b, 0, bb, 0, bb.length); + String[] ss = new String(bb).split(delimiter); + + // Check that number of "ok:" strings is equal to the number of hooks which + // printed these strings as indicator of that checks done in the hooks passed. + if (ss.length != N_OF_HOOKS) { + fail(ss.length + " hooks threw IllegalStateException instead of expected " + N_OF_HOOKS); + } + } + + String[] createCmdLine(String className) { + String ttt = System.getProperty("vm.boot.class.path") + (System.getProperty("java.class.path").length() > 0 ? + File.pathSeparator + System.getProperty("java.class.path") : ""); + String[] s = new String[6]; + s[0] = System.getProperty("java.home")+System.getProperty("file.separator")+"bin"+System.getProperty("file.separator")+"java";; + s[1] = "-Xbootclasspath/a:"+ttt; + s[2] = "-classpath"; + s[3] = "." + File.pathSeparator + ttt; + s[4] = className; + s[5] = "" + N_OF_HOOKS; + return s; + } +} + +// Some hook class - does nothing. + +class SomeHook extends Thread { + public void run() { + } +} + +// --------------------- Case 1: Add hook while hook running --------------- + +// This class started by Vm via main(args) add hooks which, being running try to add +// some hook, expecting that ISE is thrown. + +class AddHookWhileHookRunning { + public static void main(String[] args){ + int n_of_hooks = Integer.parseInt(args[0]); + for (int i = 0; i < n_of_hooks; ++i) { + Runtime.getRuntime().addShutdownHook(new Hook_AddHookWhileHookRunning()); + } + } +} + +class Hook_AddHookWhileHookRunning extends Thread { + static Object obj = new Object(); + + public void run() { + try { + Runtime.getRuntime().addShutdownHook(new SomeHook()); + } catch (IllegalStateException ise){ + synchronized (obj) { // to avoid a mess when several simultaneously running threads write "ok" status into stdout. + System.out.print(RuntimeAdditionalTest45.ok + RuntimeAdditionalTest45.delimiter); + } + } + } +} + +// --------------------- Case 2: Remove hook while hook running --------------- + +// This class started by Vm via main(args) add hooks which, being running try to remove +// itself, expecting that ISE is thrown. + +class RmHookWhileHookRunning { + public static void main(String[] args){ + int n_of_hooks = Integer.parseInt(args[0]); + for (int i = 0; i < n_of_hooks; ++i) { + Runtime.getRuntime().addShutdownHook(new Hook_RmHookWhileHookRunning()); + } + } +} + +class Hook_RmHookWhileHookRunning extends Thread { + static Object obj = new Object(); + + public void run() { + try { + Runtime.getRuntime().removeShutdownHook(this); + } catch (IllegalStateException ise){ + synchronized (obj) { // to avoid a mess when several simultaneously running threads write "ok" status into stdout. + System.out.print(RuntimeAdditionalTest45.ok + RuntimeAdditionalTest45.delimiter); + } + } + } +} + Index: vm/tests/kernel/java/lang/ClassTestGetResource.java =================================================================== --- vm/tests/kernel/java/lang/ClassTestGetResource.java (revision 463094) +++ vm/tests/kernel/java/lang/ClassTestGetResource.java (working copy) @@ -192,11 +192,10 @@ /** * The method throws NullPointerException if argument is null */ -//Commented because 6793 bug isn't fixed - public void te_st6() { + public void test_6() { try { Void.class.getResource(null); - fail("Error1: NullPointerException is not thrown for null argument"); // #6793 + fail("Error1: NullPointerException is not thrown for null argument"); } catch (NullPointerException _) { } } Index: vm/tests/kernel/java/lang/RuntimeAdditionalTest34.java =================================================================== --- vm/tests/kernel/java/lang/RuntimeAdditionalTest34.java (revision 463094) +++ vm/tests/kernel/java/lang/RuntimeAdditionalTest34.java (working copy) @@ -107,6 +107,6 @@ eeee.printStackTrace(); fail("ERROR (test_33): unexpected exception."); } - RuntimeAdditionalTest0.killCat(); + //RuntimeAdditionalTest0.killCat(); } } \ No newline at end of file Index: vm/tests/kernel/java/lang/PackageTest.java =================================================================== --- vm/tests/kernel/java/lang/PackageTest.java (revision 463094) +++ vm/tests/kernel/java/lang/PackageTest.java (working copy) @@ -188,10 +188,10 @@ public void test_getSpecificationVersion_V() { //System.out.println("test_getSpecificationVersion_V"); Package p = java.lang.Character.class.getPackage(); - if (p == null) + if (!vendor.equals("Intel DRL") && p == null) return; String s = p.getSpecificationVersion(); - if (s == null) + if (!vendor.equals("Intel DRL") && s == null) return; assertTrue("unexpected specification version: " + s, s.matches("([0-9]+?\\.)\\*?[0-9]+?")); @@ -212,8 +212,7 @@ /** * */ -// Commented because of the drvm issue. - public void te_st_isCompatibleWith_Str_1() { + public void test_isCompatibleWith_Str_1() { //System.out.println("test_isCompatibleWith_Str_1"); Package p = Package.getPackage("java.lang"); if (p == null) @@ -278,8 +277,7 @@ /** * */ -// Commented because of the drvm issue. - public void te_st_isSealed_URL_2() { + public void test_isSealed_URL_2() { //System.out.println("test_isSealed_URL_2"); try { Package p = Package.getPackage("java.lang"); Index: vm/tests/kernel/java/lang/ClassLoaderTest.java =================================================================== --- vm/tests/kernel/java/lang/ClassLoaderTest.java (revision 463094) +++ vm/tests/kernel/java/lang/ClassLoaderTest.java (working copy) @@ -644,7 +644,7 @@ //assertTrue("Error1", tcl.findLoadedClass("javax.imageio.IIOImage") // .getName().equals("javax.imageio.IIOImage")); } catch (ClassNotFoundException _) { - } catch (Throwable e) { + } catch (Throwable e) {e.printStackTrace(); fail("Error2: " + e.toString()); } @@ -918,7 +918,6 @@ new a3().main(new String[] { "" }); } - /** * */ @@ -952,6 +951,35 @@ fail("Error3"); } } + + /** + * + */ + public void test_findResource_Str_2() { + class LCL extends ClassLoader { + // only for special case + + public Class findClass(String name) { + return null; + } + + public java.net.URL findResource(String name) { + return super.findResource(name); + } + + public LCL() { + super(); + } + } + + LCL tcl = new LCL(); + // TEST CASE #1: + try { + assertTrue("Error1", tcl.findResource(null) == null); + } catch (NullPointerException _) { + fail("Error2"); + } + } /** * @@ -988,6 +1016,13 @@ } catch (Exception _) { fail("Error3"); } + + try { + tcl.findResources(null); + } catch (NullPointerException _) { + fail("Error5"); + } catch (java.io.IOException _) { + } } /** @@ -1275,12 +1310,11 @@ ClassLoader cl = ClassLoader.getSystemClassLoader(); // TEST CASE #1: -// Commented because of the drlvm issue. -// try { -// cl.getResource(null); -// fail("Error1: NullPointerException is not thrown for null argument"); -// } catch (NullPointerException _) { -// } + try { + cl.getResource(null); + fail("Error1: NullPointerException is not thrown for null argument"); + } catch (NullPointerException _) { + } // TEST CASE #2: assertTrue("Error1: unexpected:" @@ -1335,12 +1369,11 @@ ClassLoader cl = ClassLoader.getSystemClassLoader(); // TEST CASE #1: -// Commented because of the drlvm issue. -// try { -// cl.getResourceAsStream(null); -// fail("Error1: NullPointerException is not thrown for null argument"); -// } catch (NullPointerException _) { -// } + try { + cl.getResourceAsStream(null); + fail("Error1: NullPointerException is not thrown for null argument"); + } catch (NullPointerException _) { + } // TEST CASE #2: byte magic[] = new byte[4]; @@ -1520,12 +1553,11 @@ ClassLoader.getSystemClassLoader(); // TEST CASE #1: -// Commented because of the drlvm issue. -// try { -// ClassLoader.getSystemResource(null); -// fail("Error1: NullPointerException is not thrown for null argument"); -// } catch (NullPointerException _) { -// } + try { + ClassLoader.getSystemResource(null); + fail("Error1: NullPointerException is not thrown for null argument"); + } catch (NullPointerException _) { + } // TEST CASE #2: assertTrue("Error1: unexpected:" @@ -1582,12 +1614,11 @@ ClassLoader.getSystemClassLoader(); // TEST CASE #1: -// Commented because of the drlvm issue. -// try { -// ClassLoader.getSystemResourceAsStream(null); -// fail("Error1: NullPointerException is not thrown for null argument"); -// } catch (NullPointerException _) { -// } + try { + ClassLoader.getSystemResourceAsStream(null); + fail("Error1: NullPointerException is not thrown for null argument"); + } catch (NullPointerException _) { + } // TEST CASE #2: byte magic[] = new byte[4];