Index: run/run.api.net.xml =================================================================== --- run/run.api.net.xml (revision 556599) +++ run/run.api.net.xml (working copy) @@ -22,6 +22,22 @@ + + + + + + + + + + + + + + + Runs all tests from api/security + + + + + + + + Property changes on: run/run.api.security.xml ___________________________________________________________________ Name: svn:executable + * Index: run/run.xml =================================================================== --- run/run.xml (revision 556599) +++ run/run.xml (working copy) @@ -233,11 +233,12 @@ + + - + run.api.io, run.api.net, run.vm, run.api.util, run.api.security, run.api.serialization"/> Index: run/run.vm.xml =================================================================== --- run/run.vm.xml (revision 556599) +++ run/run.vm.xml (working copy) @@ -40,6 +40,9 @@ + + + @@ -55,6 +58,9 @@ + + Index: run/run.api.serialization.xml =================================================================== --- run/run.api.serialization.xml (revision 0) +++ run/run.api.serialization.xml (revision 0) @@ -0,0 +1,31 @@ + + + + + + Runs all tests from api/security + + + + + + + + Property changes on: run/run.api.serialization.xml ___________________________________________________________________ Name: svn:executable + * Index: run/run.api.kernel.xml =================================================================== --- run/run.api.kernel.xml (revision 556599) +++ run/run.api.kernel.xml (working copy) @@ -24,7 +24,7 @@ + run.api.kernel.management, run.api.kernel.compiler" /> @@ -73,6 +73,12 @@ + + + + + + Index: run/run.normal.mode.settings.xml =================================================================== --- run/run.normal.mode.settings.xml (revision 556599) +++ run/run.normal.mode.settings.xml (working copy) @@ -471,6 +471,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -482,6 +504,21 @@ + + + + + + + + + + + + + + + @@ -533,6 +570,12 @@ + + + + + + Index: src/java/org/apache/harmony/test/reliability/share/JarFilesScanner.java =================================================================== --- src/java/org/apache/harmony/test/reliability/share/JarFilesScanner.java (revision 556599) +++ src/java/org/apache/harmony/test/reliability/share/JarFilesScanner.java (working copy) @@ -41,7 +41,7 @@ static ArrayList classFiles = new ArrayList(); // contains names of found class files static Boolean cache = false; - public ArrayList getJarFilesInJRE(){ + public static ArrayList getJarFilesInJRE(){ if (cache == false) { String rootDir = getDirToScanForJarFiles(); scanDirForJarFiles(rootDir); @@ -50,7 +50,7 @@ return jarFiles; } - public ArrayList getClassFilesInJRE(){ + public static ArrayList getClassFilesInJRE(){ if (cache == false) { getJarFilesInJRE(); @@ -74,11 +74,11 @@ return classFiles; } - String getDirToScanForJarFiles() { + static String getDirToScanForJarFiles() { return System.getProperty("java.home"); } - void scanDirForJarFiles(String rootDir) { + static void scanDirForJarFiles(String rootDir) { try { Index: src/java/org/apache/harmony/test/reliability/share/ClassMultiTestBase.java =================================================================== --- src/java/org/apache/harmony/test/reliability/share/ClassMultiTestBase.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/share/ClassMultiTestBase.java (revision 0) @@ -0,0 +1,117 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +/** + * GOAL: the test is intendent to process different operations on classes loaded + * from jar files in JRE folder + * + * passed parameters: + * parameter[0] - number of threads to launch for parallel loading and processing Classes + */ + +package org.apache.harmony.test.reliability.share; + +import java.util.ArrayList; +import org.apache.harmony.test.reliability.share.Test; +import org.apache.harmony.test.reliability.share.JarFilesScanner; + + +public abstract class ClassMultiTestBase extends Test implements Runnable{ + volatile boolean failed = false; + final static String classFilesExt = ".class"; + final static char slashCharDelimiter1 = '/'; + final static char slashCharDelimiter2 = '\\'; + final static char dotCharDelimiter = '.'; + final static int NUMBER_OF_THREADS = 3; + int numberOfThreads = NUMBER_OF_THREADS; + int classCounter = 0; + ArrayList jarFiles; + + public abstract void initCycle(); + public abstract void releaseCycle(); + public abstract void testContent(Class cls); + + public int test(String []args){ + parseParams(args); + jarFiles = new JarFilesScanner().getClassFilesInJRE(); + initCycle(); + + Thread[] thrds = new Thread[numberOfThreads]; + for (int i = 0; i< thrds.length; i++){ + thrds[i] = new Thread(this); + thrds[i].start(); + } + + for (int i = 0; i< thrds.length; i++){ + try { + thrds[i].join(); + } catch (InterruptedException e) { + failed = true; + log.add("Failed to join thread " + e); + } + } + + releaseCycle(); + + if (failed){ + return fail("FAILED"); + } + //System.out.println("Number of classes tested "+ classCounter); + return pass("OK"); + } + + + public void run(){ + for (int i=0; i= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + } + +} Property changes on: src/java/org/apache/harmony/test/reliability/share/ClassMultiTestBase.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/vm/classloading/ClassReflectionTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/vm/classloading/ClassReflectionTest.java (revision 556599) +++ src/java/org/apache/harmony/test/reliability/vm/classloading/ClassReflectionTest.java (working copy) @@ -45,14 +45,22 @@ import java.lang.reflect.GenericSignatureFormatError; import java.lang.reflect.MalformedParameterizedTypeException; import java.lang.reflect.Method; +import org.apache.harmony.test.reliability.share.ClassMultiTestBase; public class ClassReflectionTest extends ClassMultiTestBase{ public static void main(String[] args){ System.exit(new ClassReflectionTest().test(args)); } - - void testContent(Class cls) { + + public void initCycle() { + // do nothing + } + public void releaseCycle() { + // do nothing + } + + public void testContent(Class cls) { Constructor[] ctrs = null; try{ ctrs = cls.getConstructors(); Index: src/java/org/apache/harmony/test/reliability/vm/classloading/ClassCastTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/vm/classloading/ClassCastTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/vm/classloading/ClassCastTest.java (revision 0) @@ -0,0 +1,137 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +/** + * GOAL: Test Class cast functionality + * see additional description in ClassMultiBas + * + * The test does: + * a. finds all class files from JRE + * b. tries to load all these classes + * c. calls compileClass for every successfully loaded Class + * d. casting is done not more than RELEASE_CYCLE_TIME_LIMIT minutes (as it could take long on JRE) + * e. every loaded class is casted with Class.asSubclass to other loaded classes + * g. cast is checked with Class.isAssignableFrom function + * d. for every "java." class new Object is created by newInstance and + * checked that object has right Class with Class.isInstance() + * + * No hangs, fails, crashes or hangs are expected. + */ + +package org.apache.harmony.test.reliability.vm.classloading; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.harmony.test.reliability.share.ClassMultiTestBase; + +public class ClassCastTest extends ClassMultiTestBase{ + static final int RELEASE_CYCLE_TIME_LIMIT = 1; //minutes + Set syntMembers = null; + long timeStart = 0; + + public static void main(String[] args){ + System.exit(new ClassCastTest().test(args)); + } + + public void initCycle() { + syntMembers = new HashSet(); + timeStart = System.currentTimeMillis(); + } + public void releaseCycle() { + // do nothing + Iterator it1 = syntMembers.iterator(); + while (it1.hasNext()){ + long timePassed = (System.currentTimeMillis() - timeStart) / 1000 / 60; // time in minutes + if (timePassed > RELEASE_CYCLE_TIME_LIMIT){ + break; + } + Iterator it2 = syntMembers.iterator(); + Class c1 = (Class) it1.next(); + while (it2.hasNext()){ + Class c2 = (Class) it2.next(); + if (c1.equals(c2)){ + continue; + } + try{ + c1.asSubclass(c2); + }catch (ClassCastException e){ + // Expected + continue; + }catch(Throwable e){ + log.add("Unexpected cast exception: " + e.getMessage()); + return; + } + // class was casted properly: trying to find custed method in + // parent classes via reflection + if (!customCheckParent(c1,c2)){ + log.add("Failed to check cast: " + c1.getName() + " failed to cast to " + c2.getName()); + } + //System.out.println(c1.getName() + " casted to " + c2.getName()); + } + + // make newInstance only for "java." classes to avoid hangs, avoid "awt" and "swing" to avoid XServer up requirement + if (c1.getName().startsWith("java.") && !c1.getName().contains("awt") && !c1.getName().contains("swing")){ + Object o = null; + try { + o = c1.newInstance(); + } catch(IllegalAccessException e){ + // Expectable + continue; + } catch (InstantiationException e){ + // Expectable + continue; + } catch (ExceptionInInitializerError e){ + // Expectable + continue; + } catch (SecurityException e){ + // Expectable + continue; + }catch (Exception e){ + // Expectable - propogated exception from class default constructor + continue; + } + if (!c1.isInstance(o)){ + log.add("Failed to check instance of " + c1.getName()); + return; + } + //System.out.println("OK for " + c1.getName()); + } + + } + } + + boolean customCheckParent(Class c, Class parent){ + return parent.isAssignableFrom(c); + } + + public void testContent(Class cls) { + if (cls.getName().contains("$")){ + return; + } + synchronized(syntMembers){ + syntMembers.add(cls); + } + } + +} \ No newline at end of file Property changes on: src/java/org/apache/harmony/test/reliability/vm/classloading/ClassCastTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/vm/classloading/ClassMultiTestBase.java =================================================================== --- src/java/org/apache/harmony/test/reliability/vm/classloading/ClassMultiTestBase.java (revision 556599) +++ src/java/org/apache/harmony/test/reliability/vm/classloading/ClassMultiTestBase.java (working copy) @@ -1,131 +0,0 @@ -/* - * Copyright 2007 The Apache Software Foundation or its licensors, as applicable - * - * Licensed 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 Aleksey Ignatenko - * @version $Revision: 1.0 $ - */ - -/** - * NOTE: this class is not a test for running, it is a base class for other tests which - * process classes from "java.home"'s jar files. - * - * The class does: - * 1. Reads parameter, which is: - * param[0] - number of threads to launch for parallel classes processing - * param[1] - flag indicates what OS is used, true == linux, it is required not to initialize loaded classes as it requires - * XServer to be up. - * - * 2. Gets names of all classes from all jar files found in "java.home" and its subdirectories. - * - * 2. Starts param[0] threads. - * Each thread: - * For each class name: - * - tries to load the class by Class.forName() (classes are not initialized on linux because it requires XServer to be up) - * - if class could not be loaded for any reason, it is ignored, otherwise, - * - testContent() method which must be overridden in real tests is invoked. - * - * 3. If there are no unexpected exceptions, PASS status is returned, otherwise, FAIL - */ - -package org.apache.harmony.test.reliability.vm.classloading; - -import java.util.ArrayList; -import java.lang.reflect.*; -import java.lang.annotation.*; - -import org.apache.harmony.test.reliability.share.Test; -import org.apache.harmony.test.reliability.share.JarFilesScanner; - - -public class ClassMultiTestBase extends Test implements Runnable{ - volatile boolean failed = false; - final static String classFilesExt = ".class"; - final static char slashCharDelimiter1 = '/'; - final static char slashCharDelimiter2 = '\\'; - final static char dotCharDelimiter = '.'; - final static int NUMBER_OF_THREADS = 3; - int numberOfThreads = NUMBER_OF_THREADS; - int classCounter = 0; - ArrayList jarFiles; - - void testContent(Class cls) { - fail("The " + this.getClass().getName() + " class is for infra purposes only! - NOT TEST!"); - } - - public int test(String []args){ - parseParams(args); - jarFiles = new JarFilesScanner().getClassFilesInJRE(); - - - Thread[] thrds = new Thread[numberOfThreads]; - for (int i = 0; i< thrds.length; i++){ - thrds[i] = new Thread(this); - thrds[i].start(); - } - - for (int i = 0; i< thrds.length; i++){ - try { - thrds[i].join(); - } catch (InterruptedException e) { - failed = true; - log.add("Failed to join thread " + e); - } - } - - if (failed){ - return fail("FAILED"); - } - //System.out.println("Number of classes tested "+ classCounter); - return pass("OK"); - } - - - public void run(){ - for (int i=0; i= 1) { - numberOfThreads = Integer.parseInt(params[0]); - } - } - -} - Index: src/java/org/apache/harmony/test/reliability/vm/classloading/ClassAttributesTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/vm/classloading/ClassAttributesTest.java (revision 556599) +++ src/java/org/apache/harmony/test/reliability/vm/classloading/ClassAttributesTest.java (working copy) @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + /** * @author Aleksey Ignatenko * @version $Revision: 1.0 $ */ /** - * GOAL: the test checks that for each loaded class (from "java.home") invocation of java.lang.Class methods + * GOAL: the test checks that for each loaded class (from "java.home") invocation of java.lang.Class methods * in multiple threads running in parallel does not cause unexpected errors (crashes, hangs, exceptions). * * NOTE: see additional description in ClassMultiBase class. @@ -42,14 +42,22 @@ import java.lang.reflect.GenericSignatureFormatError; import java.lang.reflect.MalformedParameterizedTypeException; +import org.apache.harmony.test.reliability.share.ClassMultiTestBase; public class ClassAttributesTest extends ClassMultiTestBase{ public static void main(String[] args){ System.exit(new ClassAttributesTest().test(args)); } + + public void initCycle() { + // do nothing + } + public void releaseCycle() { + // do nothing + } - void testContent(Class cls) { + public void testContent(Class cls) { cls.getName(); cls.getAnnotations(); try{ Index: src/java/org/apache/harmony/test/reliability/vm/gc/WeakRefsTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/vm/gc/WeakRefsTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/vm/gc/WeakRefsTest.java (revision 0) @@ -0,0 +1,290 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.vm.gc; + +import java.util.Random; +import java.util.WeakHashMap; +import java.util.concurrent.Exchanger; +import java.nio.*; +import java.util.*; + +import org.apache.harmony.test.reliability.share.Test; + +/* + * Goal: Test GC weak refs support - how often GC collects weak refs when it is close to OOME. + * The test will show if weak refs support in GC is balanced. + * passed parameters: + * parameter[0] - number of threads to start + * + * The test Thread does the following: + * * creates numberOfThreads + * * in every thread: different objects are created by Random. + * + * No hangs, crashes or fails are expected. + * */ + +public class WeakRefsTest extends Test{ + static volatile boolean failed = false; + static final int NUMBER_OF_THREADS = 32; + static int numberOfThreads = NUMBER_OF_THREADS; + static final int TIME_LIMIT_FOR_ONE_ITERATION = 1; // minutes + volatile static boolean stopThreads = false; + + public static void main(String[] params){ + System.exit(new WeakRefsTest().test(params)); + } + + public int test(String[] params){ + parseParams(params); + + Thread[] thrds = new Thread[numberOfThreads]; + for (int i=0; i< numberOfThreads; i++){ + thrds[i] = new ObjectEmitterThreadEx(); + thrds[i].start(); + } + + try { + Thread.currentThread().sleep(TIME_LIMIT_FOR_ONE_ITERATION * 60 * 1000);// converted minutes to milliseconds + } catch (InterruptedException e1) { + return fail("Main thread was interrupted."); + } + + stopThreads = true; + + for (int i=0; i< numberOfThreads; i++){ + try { + thrds[i].join(); + } catch (InterruptedException e) { + failed = true; + } + } + + // force gc to see results of the test + System.gc(); + + if (failed == true){ + return fail("FAILED"); + } + return pass("OK"); + } + + public void parseParams(String[] params) { + + if (params.length >= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + } +} + +class ObjectEmitterThreadEx extends Thread{ + static final int ARRAY_SIZE_LIMIT = 777; + static final int NUMBER_OF_EMMITED_OBJECTS = 1024; + static Random rm = new Random(); + static Exchanger exc = new Exchanger(); + + public void run (){ + WeakHashMap whm = new WeakHashMap(); + while(!WeakRefsTest.stopThreads){ + try{ + whm.put(emitObject(), null); + }catch(Throwable e){ + GCTest.log.add("Failed to create object!"); + GCTest.failed = true; + return; + } + } + + } + + Object emitObject() throws OutOfMemoryError{ + Object ret = null; + switch(rm.nextInt(51)){ + // array types + case 0: + ret = new int[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 1: + ret = new char[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 2: + ret = new byte[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 3: + ret = new long[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 4: + ret = new float[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 5: + ret = new double[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 6: + ret = new boolean[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 7: + ret = new String[rm.nextInt(ARRAY_SIZE_LIMIT)]; + break; + case 8: + ret = new char[rm.nextInt(ARRAY_SIZE_LIMIT)].toString(); + break; + // simple types + case 9: + ret = new Boolean(true); + break; + case 10: + ret = new Byte((byte) rm.nextInt(32)); + break; + case 11: + ret = new Character('a'); + break; + case 12: + ret = new Double("3.54"); + break; + case 13: + ret = new Character('a'); + break; + case 14: + ret = new Float("3.54"); + break; + case 15: + ret = new Integer(rm.nextInt()); + break; + case 16: + ret = new Long(rm.nextLong()); + break; + // big chunks of memory, upto: 32K, 64K, 128K, 256K, 512K + case 17: + ret = new byte[rm.nextInt(32*1024)]; + break; + case 18: + ret = new byte[rm.nextInt(64*1024)]; + break; + case 19: + ret = new byte[rm.nextInt(128*1024)]; + break; + case 20: + ret = new byte[rm.nextInt(256*1024)]; + break; + case 21: + ret = new byte[rm.nextInt(512*1024)]; + break; + case 22: + ret = ByteBuffer.allocateDirect(rm.nextInt(64)); + break; + case 23: + ret = ByteBuffer.allocateDirect(rm.nextInt(128)); + break; + case 24: + ret = ByteBuffer.allocate(rm.nextInt(256)); + break; + case 25: + ret = ByteBuffer.allocate(rm.nextInt(512)); + break; + case 26: + ret = CharBuffer.allocate(rm.nextInt(64)); + break; + case 27: + ret = CharBuffer.allocate(rm.nextInt(128)); + break; + case 28: + ret = CharBuffer.allocate(rm.nextInt(256)); + break; + case 29: + ret = CharBuffer.allocate(rm.nextInt(512)); + break; + case 30: + ret = IntBuffer.allocate(rm.nextInt(64)); + break; + case 31: + ret = IntBuffer.allocate(rm.nextInt(128)); + break; + case 32: + int z = 3; + ret = z; + break; + case 33: + char z1 = 'a'; + ret = z1; + break; + case 34: + float z2 = (float) 3.14; + ret = z2; + break; + case 35: + double z3 = 3.14; + ret = z3; + break; + case 36: + long z4 = 314; + ret = z4; + break; + case 37: + ret = new Thread(); + break; + case 38: + ret = new StringBuffer(); + break; + case 39: + ret = new Exception(); + break; + case 40: + ret = new Error(); + break; + case 41: + ret = new Formatter(); + break; + case 42: + ret = new HashMap(); + break; + case 43: + ret = new HashSet(); + break; + case 44: + ret = new Hashtable(); + break; + case 45: + ret = new LinkedList(); + break; + case 46: + ret = new Properties(); + break; + case 47: + ret = new Random(); + break; + case 48: + ret = new Stack(); + break; + case 49: + ret = new Vector(); + break; + case 50: + ret = new WeakHashMap(); + break; + default: + ret = new byte[1]; + } + return null; + } + +} + Property changes on: src/java/org/apache/harmony/test/reliability/vm/gc/WeakRefsTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/kernel/compiler/JitCompilerTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/kernel/compiler/JitCompilerTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/kernel/compiler/JitCompilerTest.java (revision 0) @@ -0,0 +1,72 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +/** + * GOAL: Test j.l.Compiler functionality + * see additional description in ClassMultiBas + * + * The test does: + * a. finds all class files from JRE + * b. tries to load all these classes + * c. calls compileClass for every successfully loaded Class + * d. for every NUMBER_OF_CYCLE_TO_DISABLE_COMPILER-th iteration try + * to compile class in Compiler.disable(); mode + * + * No hangs, fails, crashes or hangs are expected. + * Note: due to spec to test JIT compiler "java.compiler" property is to be set + * and VM is to support j.l.Compiler functionality + */ + +package org.apache.harmony.test.reliability.api.kernel.compiler; + +import org.apache.harmony.test.reliability.share.ClassMultiTestBase; + +public class JitCompilerTest extends ClassMultiTestBase{ + int class_compiled_counter = 0; + final int NUMBER_OF_CYCLE_TO_DISABLE_COMPILER = 10; + + public static void main(String[] args){ + System.exit(new JitCompilerTest().test(args)); + } + + public void initCycle() { + // do nothing + } + public void releaseCycle() { + // do nothing + } + + public void testContent(Class cls) { + // for every NUMBER_OF_CYCLE_TO_DISABLE_COMPILER-th iteration + // try to compile class in Compiler.disable(); mode + if ((class_compiled_counter%NUMBER_OF_CYCLE_TO_DISABLE_COMPILER) == 0){ + Compiler.disable(); + Compiler.compileClass(cls); + Compiler.enable(); + } + + Compiler.compileClass(cls); + + class_compiled_counter++; + } + +} \ No newline at end of file Property changes on: src/java/org/apache/harmony/test/reliability/api/kernel/compiler/JitCompilerTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java (revision 0) @@ -0,0 +1,140 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.api.net; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.MalformedURLException; +import java.net.Proxy; +import java.net.URL; +import java.util.regex.Pattern; + +import org.apache.harmony.test.reliability.share.Test; + +/* + * Goal: Test HttpURLConnection functionality + * + * passed parameters: + * parameter[0] - urls for web pages you want to get, all urls are to be listed consequently + * via ";" with no blanks or tabs + * E.g http://harmony.apache.org/;http://issues.apache.org/jira/browse/HARMONY + * parameter[1] - proxy adress if any + * parameter[2] - proxy port if any + * The test does the following: + * - For every url from parameter[0] establishes HttpURLConnection and tries to GET + * web page from it and read some info about connection. + * + * No crash, hang or fail is excpected. + * + * Note: All input parameters are to be set properly as test could fail due to wrong + * set proxy or Url address. + * */ + +public class HttpConnectionTest extends Test{ + String[] testedUrlStrings = null; + Proxy prx = null; + + public static void main(String[] params){ + System.exit(new HttpConnectionTest().test(params)); + } + + public int test(String[] params){ + parseParams(params); + if (testedUrlStrings == null){ + return fail("Urls to test are not set"); + } + + for (int i=0; i= 1) { + String urls = params[0]; + Pattern p = Pattern.compile(";"); + testedUrlStrings = p.split(urls); + } + if (params.length >= 3) { + prx = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(params[1], Integer.parseInt(params[2]))); + } + + } +} Property changes on: src/java/org/apache/harmony/test/reliability/api/net/HttpConnectionTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/net/JarUrlConnectionTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/net/JarUrlConnectionTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/net/JarUrlConnectionTest.java (revision 0) @@ -0,0 +1,257 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.api.net; + +import java.io.File; +import java.io.IOException; +import java.net.JarURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.cert.Certificate; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Random; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +import org.apache.harmony.test.reliability.share.JarFilesScanner; + +import org.apache.harmony.test.reliability.share.Test; + +/* + * Goal: Test JavaUrlConnection functionality + * the idea is to create JavaUrlConnection for existing jar file in JRE + * + scan jar files and create JavaUrlConnection on jar entries + * and read some information about scanned jar files and entries + * passed parameters: + * parameter[0] - number of threads to start + * + * The test Thread does the following: + * * scans jar files in JRE + * * creates parameter[0] threads for every jar files found + * Every thread: + * * creates JavaUrlConnection for every jar file + * * reads some info about jar file + * * scans read jar files for entries and reads info about these entries + * + * */ + +public class JarUrlConnectionTest extends Test{ + static volatile boolean failed = false; + static final int NUMBER_OF_THREADS = 100; + static int numberOfThreads = NUMBER_OF_THREADS; + static ArrayList jarFiles = null; + + public static void main(String[] params){ + System.exit(new JarUrlConnectionTest().test(params)); + } + + public int test(String[] params){ + parseParams(params); + jarFiles = JarFilesScanner.getJarFilesInJRE(); + + if (jarFiles == null){ + return fail("Failed to scan jar files in JRE."); + } + + if (numberOfThreads > jarFiles.size()){ + numberOfThreads = jarFiles.size(); + } + + Thread[] thrds = new Thread[numberOfThreads]; + for (int i = 0; i= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + } +} + +class scanRunner extends Thread{ + Random rm = new Random(); + URL url = null; + + scanRunner(URL u){ + url = u; + } + + public void run (){ + JarURLConnection juc = null; + + String jarUrlString = "jar:" + url + "!/"; + //System.out.println(jarUrlString); + URL jurl = null; + try { + jurl = new URL(jarUrlString); + } catch (MalformedURLException e1) { + JarUrlConnectionTest.log.add("Failed to convert URI name to jar URL for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + try { + juc = (JarURLConnection)jurl.openConnection(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to open JarURLConnection for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + Attributes atts = null; + try { + atts = juc.getAttributes(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get Attributes for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + Attributes mAtts = null; + try { + mAtts = juc.getMainAttributes(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get Attributes for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + Certificate[] ct = null; + try { + ct = juc.getCertificates(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get certificates for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + Manifest msft = null; + try { + msft = juc.getManifest(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get manifest for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + JarFile jf = null; + try { + jf = juc.getJarFile(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get manifest for " + url); + JarUrlConnectionTest.failed = true; + return; + } + + Enumeration en = jf.entries(); + while (en.hasMoreElements()){ + JarEntry je = en.nextElement(); + je.getName(); + //System.out.println(je.getName()); + je.getCertificates(); + je.getExtra(); + je.getCrc(); + je.getTime(); + je.getComment(); + je.getCodeSigners(); + + // try to create JarURLConnection for JarEntries + String eUrlString = jarUrlString + je.getName(); + URL eUrl; + try { + eUrl = new URL(eUrlString); + } catch (MalformedURLException e) { + JarUrlConnectionTest.log.add("Failed to Create URL to jar entry " + eUrlString); + JarUrlConnectionTest.failed = true; + return; + } + JarURLConnection juce = null; + try { + juce = (JarURLConnection)eUrl.openConnection(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to Create JarURLConnection to jar entry " + eUrlString); + JarUrlConnectionTest.failed = true; + return; + } + try { + juce.getContent(); + } catch (IOException e) { + // ignore + } + try { + juce.getAttributes(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to getAttributes for " + eUrlString); + JarUrlConnectionTest.failed = true; + return; + } + + juce.getAllowUserInteraction(); + try { + juce.getCertificates(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get certificates for " + eUrlString); + JarUrlConnectionTest.failed = true; + return; + } + + try { + juce.getManifest(); + } catch (IOException e) { + JarUrlConnectionTest.log.add("Failed to get manifest for " + eUrlString); + JarUrlConnectionTest.failed = true; + return; + } + + } + + } + +} + Property changes on: src/java/org/apache/harmony/test/reliability/api/net/JarUrlConnectionTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/net/DatagramTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/net/DatagramTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/net/DatagramTest.java (revision 0) @@ -0,0 +1,223 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.api.net; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Random; +import java.net.InetAddress; + +import org.apache.harmony.test.reliability.share.Test; + +/* + * Goal: Test datagram packets send/receive operations + * passed parameters: + * parameter[0] - number of threads to start to send packets + * + * The test Thread does the following: + * parameter[1] number of receiver threads is started, every thread: + * * starts receiving data by DatagramSocket + + * parameter[0] number of sender threads is started, every thread: + * * starts sending datagram packets to localhost with predefined port numbers + * + * The test is stopped after TIME_FOR_ONE_ITERATION_TO_WORK timeout + * + * No hangs, crashes or fails are expected + * */ + +public class DatagramTest extends Test{ + static volatile boolean failed = false; + static final int NUMBER_OF_THREADS = 30; + static int numberOfThreads = NUMBER_OF_THREADS; + volatile static boolean stopThreads = false; + final static int STARTING_PORT_NUMBER = 8100; + final static int NUMBER_OF_TRIES_TO_CREATE_SOCKET = 1000; + final static int NUMBER_OF_RECEIVERS = 10; + final static int TIME_FOR_ONE_ITERATION_TO_WORK = 1; //minutes + int[] portNumbers = null; + + public static void main(String[] params){ + System.exit(new DatagramTest().test(params)); + } + + public int test(String[] params){ + parseParams(params); + stopThreads = false; + Thread[] rthrds = new Thread[NUMBER_OF_RECEIVERS]; + Thread[] sthrds = new Thread[numberOfThreads]; + portNumbers = new int[NUMBER_OF_RECEIVERS]; + for (int i = 0; i= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + } +} + +class receiveRunner extends Thread{ + Random rm = new Random(); + int port = 0; + DatagramSocket ds = null; + static final int NUMBER_BYTES_TO_RECEIVE = 100; + DatagramTest base = null; + + receiveRunner(int p, DatagramTest b){ + base = b; + port = p; + initialize(); + } + + int initialize(){ + int counter = 0; + while (counter < DatagramTest.NUMBER_OF_TRIES_TO_CREATE_SOCKET){ + try { + ds = new DatagramSocket(port + counter); + } catch (SocketException e) { + //DatagramTest.log.add("Failed to create DatagramSocket on port " + port); + counter++; + continue; + } + break; + } + if (ds != null){ + return (port + counter); + }else{ + return -1; + } + } + + public void run (){ + while (!DatagramTest.stopThreads){ + byte buf[] = new byte[NUMBER_BYTES_TO_RECEIVE]; + DatagramPacket dp = new DatagramPacket(buf, buf.length); + try { + ds.receive(dp); + } catch (IOException e) { + // possible + } + byte[] data = dp.getData(); + dp.getLength(); + String msg = new String(data); + //System.out.println(msg); + dp.getOffset(); + dp.getPort(); + } + ds.close(); + } + +} + +class sendRunner extends Thread{ + Random rm = new Random(); + DatagramSocket ds = null; + DatagramTest base = null; + + sendRunner(DatagramTest b){ + base = b; + try { + ds = new DatagramSocket(); + } catch (SocketException e) { + DatagramTest.stopThreads = true; + DatagramTest.log.add("Failed to create DatagramSocket in " + getId() + " thread"); + DatagramTest.failed = true; + } + } + + public void run (){ + while (!DatagramTest.stopThreads){ + String msg = "Thread " + getId() + " sends you Hello"; + DatagramPacket dp; + int port = base.portNumbers [rm.nextInt(DatagramTest.NUMBER_OF_RECEIVERS)]; + try { + dp = new DatagramPacket(msg.getBytes(), msg.getBytes().length ,InetAddress.getLocalHost(), port); + } catch (UnknownHostException e) { + DatagramTest.stopThreads = true; + DatagramTest.log.add("Failed to create DatagramPacket in " + getId() + " thread, localhost, port " + port); + DatagramTest.failed = true; + return; + } + + try { + ds.send(dp); + } catch (IOException e) { + DatagramTest.stopThreads = true; + DatagramTest.log.add("Failed to send packet in " + getId() + " thread, localhost, port " + port); + DatagramTest.failed = true; + } + } + ds.close(); + } + +} + Property changes on: src/java/org/apache/harmony/test/reliability/api/net/DatagramTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/net/MultiConnectTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/net/MultiConnectTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/net/MultiConnectTest.java (revision 0) @@ -0,0 +1,177 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.api.net; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.net.InetAddress; + +import org.apache.harmony.test.reliability.share.Test; + +/* + * Goal: Test making connections to many ports on localHost + * passed parameters: + * parameter[0] - number of scanner threads to start + * parameter[1] - number of ports opened simultaneously + * + * The test Thread does the following: + * parameter[1] number of server threads are started, every thread: + * * has own unique port number to process requests + * * starts receiving connections by ServerSocket.accept() method in a cycle + * * cycle is numberOfAcceptedRequests times + + * parameter[0] number of sender threads is started, every thread: + * * starts creating socket conections to localHost by every reserved port number + * + * No hangs, crashes or fails are expected + * + * Note: choose input parameters values properly to avoid "max allowed connections exceeded" error to appear + * */ + +public class MultiConnectTest extends Test{ + static volatile boolean failed = false; + static final int NUMBER_OF_THREADS = 10; + static int numberOfThreads = NUMBER_OF_THREADS; + final static int STARTING_PORT_NUMBER = 8100; + static int numberOfPortsToOpen = 2000; + static int numberOfAcceptedRequests = 1000; + static ServerRunner[] sPorts = null; + + public static void main(String[] params){ + System.exit(new MultiConnectTest().test(params)); + } + + public int test(String[] params){ + parseParams(params); + + sPorts = new ServerRunner[numberOfPortsToOpen]; + for (int i=0; i= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + if (params.length >= 2) { + numberOfPortsToOpen = Integer.parseInt(params[1]); + } + + } +} + +class ServerRunner extends Thread{ + int port = 0; + int counter = 0; + ServerRunner(int p){ + port = p; + start(); + } + public void run (){ + ServerSocket ss = null; + try { + ss = new ServerSocket(port); + } catch (IOException e1) { + // Ignore - the port could already be used + return; + } + while (counter < MultiConnectTest.numberOfAcceptedRequests){ + try { + ss.accept(); + } catch (IOException e) { + MultiConnectTest.log.add("Server thread " + getId() + " could not accept request: " + e.getMessage()); + MultiConnectTest.failed = true; + return; + } + counter++; + } + try { + ss.close(); + } catch (IOException e) { + MultiConnectTest.log.add("Failed to close ServerSocket on port " + port); + MultiConnectTest.failed = true; + return; + } + + } + +} + + +class portScannerRunner extends Thread{ + + public void run (){ + + ArrayList connections = new ArrayList(); + for (int i=0; i= 1) { + numberOfThreads = Integer.parseInt(params[0]); + } + + } +} + +class ServerRunner1 extends Thread{ + int port = 0; + int counter = 0; + boolean started = false; + ServerRunner1(int p){ + port = p; + start(); + } + public void run (){ + ServerSocket ss = null; + try { + ss = new ServerSocket(port); + } catch (IOException e1) { + // Ignore - the port could already be used + return; + } + started = true; + while (counter < SingleConnectTest.numberOfAcceptedRequests){ + try { + ss.accept(); + } catch (IOException e) { + SingleConnectTest.log.add("Server thread " + getId() + " could not accept request: " + e.getMessage()); + SingleConnectTest.failed = true; + return; + } + counter++; + } + try { + ss.close(); + } catch (IOException e) { + SingleConnectTest.log.add("Failed to close ServerSocket on port " + port); + SingleConnectTest.failed = true; + return; + } + + } + +} + + +class portScannerRunner1 extends Thread{ + + public void run (){ + + ArrayList connections = new ArrayList(); + while (true){ + Socket sc = null; + try { + sc = new Socket(InetAddress.getLocalHost(), SingleConnectTest.portStarted); + connections.add(sc); + } catch (UnknownHostException e) { + SingleConnectTest.log.add("Failed to locate localhost."); + SingleConnectTest.failed = true; + return; + } catch (IOException e) { + // Ignore - server could already down or max allowed connections number is reached + break; + + } + + try { + sc.close(); + } catch (IOException e) { + SingleConnectTest.log.add("Failed to close socket to localhost by port " + (SingleConnectTest.portStarted) + " : " + e.getMessage()); + SingleConnectTest.failed = true; + } + } + + } + +} + Property changes on: src/java/org/apache/harmony/test/reliability/api/net/SingleConnectTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/security/SecurityClassRelatedTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/security/SecurityClassRelatedTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/security/SecurityClassRelatedTest.java (revision 0) @@ -0,0 +1,108 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Aleksey Ignatenko + * @version $Revision: 1.0 $ + */ + +package org.apache.harmony.test.reliability.api.security; + +import java.lang.reflect.Member; +import java.security.Principal; +import java.util.Iterator; +import java.util.Set; + +import javax.security.auth.Subject; + +import org.apache.harmony.test.reliability.share.ClassMultiTestBase; + +/** + * GOAL: Test security related functionality on the basis of loaded classed + * see additional description in ClassMultiBas + * + * The test does: + * a. finds all class files from JRE + * b. tries to load all these classes + * c. eprforms sveral security related operations like checkMemberAccess on every + * loaded class + * + * No hangs, fails, crashes or hangs are expected. + * Note: testContent is able to be extended to any other operations avalaible + * with j.l.Class + */ + +public class SecurityClassRelatedTest extends ClassMultiTestBase{ + SecurityManager sm = null; + Subject sbj = null; + + public static void main(String[] args){ + System.exit(new SecurityClassRelatedTest().test(args)); + } + + public void initCycle() { + sm = new SecurityManager(); + sbj = new Subject(); + } + public void releaseCycle() { + // do nothing + } + + public void testContent(Class cls) { + sm.checkAccess(Thread.currentThread()); + + try{ + sm.checkMemberAccess(cls, Member.PUBLIC); + } catch(SecurityException e){ + // Expected + } catch (Throwable e){ + log.add("Failed to checkMemberAccess on class " + cls.getName() + " Reason: " + e.getMessage()); + } + + try{ + sm.checkMemberAccess(cls, Member.DECLARED); + } catch(SecurityException e){ + // Expected + } catch (Throwable e){ + log.add("Failed to checkMemberAccess on class " + cls.getName() + " Reason: " + e.getMessage()); + } + + Set prc = sbj.getPrincipals(cls); + Iterator it = prc.iterator(); + while(it.hasNext()){ + Principal p = (Principal) it.next(); + p.getName(); + } + + Set pc = sbj.getPrivateCredentials(cls); + it = pc.iterator(); + while(it.hasNext()){ + Object o = it.next(); + o.hashCode(); + } + + + Set puc = sbj.getPublicCredentials(cls); + it = puc.iterator(); + while(it.hasNext()){ + Class c = (Class) it.next(); + c.getName(); + } + + } + +} \ No newline at end of file Property changes on: src/java/org/apache/harmony/test/reliability/api/security/SecurityClassRelatedTest.java ___________________________________________________________________ Name: svn:executable + * Index: src/java/org/apache/harmony/test/reliability/api/serialization/SerializableClassesTest.java =================================================================== --- src/java/org/apache/harmony/test/reliability/api/serialization/SerializableClassesTest.java (revision 0) +++ src/java/org/apache/harmony/test/reliability/api/serialization/SerializableClassesTest.java (revision 0) @@ -0,0 +1,454 @@ +/* + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable + * + * Licensed 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 Alexey Ignatenko + * @version $Revision: 1.1 $ + */ + +package org.apache.harmony.test.reliability.api.serialization; + +import org.apache.harmony.test.reliability.share.JarFilesScanner; +import org.apache.harmony.test.reliability.share.Test; +import java.io.File; +import java.io.NotSerializableException; +import java.io.OutputStream; +import java.io.InputStream; +import java.io.FileOutputStream; +import java.io.ObjectOutputStream; +import java.io.FileInputStream; +import java.io.ObjectInputStream; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Hashtable; + +/* + * Goal: check that serialization of instances of J2SE serializable classes + * works as expected (ho crashes, hangs, etc.) in multi-threaded environment. + * + * The test does: + * + * 1. Reads parameters: + * param[1] - number of serialization threads + * param[2] - number of deserialization threads + * param[3] - directory where serizliation files will be created + * + * 2. Starts param[1] "controlling" threads, each thread: + * + * 1. Starts single serialization thread, which: + * + * a. Instantiates serializable classes. If instance of a class can not be created, + * then, it is ignored, otherwise, + * + * b. Writes created object into .ser file. + * + * 2. Waits for completion of the serializing thread. If serialization passed ok, then: + * + * 3. Starts param[2] deserialization threads, each of the threads: + * + * a. Reads an object from file. + * + * b. Checks that its class is the same as the class of the original (serialized) object. + * + * 4. Finally, removes created .ser file. + * + */ + +public class SerializableClassesTest extends Test { + + int NUMBER_OF_THREADS = 3; + int NUMBER_OF_SUBTHREADS = 10; + String OUT_DIR_NAME = "."; + Class jlSerializableClass = null; + + volatile boolean failed = false; + + public static void main(String[] args) { + System.exit(new SerializableClassesTest().test(args)); + } + + public int test(String[] params) { + + parseParams(params); + try { + jlSerializableClass = Class.forName("java.io.Serializable"); + } catch (ClassNotFoundException e1) { + log.add("Failed to load java.io.Serializable class"); + e1.printStackTrace(); + return fail(""); + } + failed = false; + + Thread thrds[] = new Thread[NUMBER_OF_THREADS]; + + // run NUMBER_OF_THREADS of threads, each of the RunSerializationThread thread + // does serialization of objects of serializable classes and then starts + // NUMBER_OF_SUBTHREADS of threads, each deserializing the objects + + for (int i = 0; i < thrds.length; i++) { + thrds[i] = new RunSerializationThread(this); + thrds[i].start(); + } + + for (int j = 0; j < thrds.length; j++) { + try { + thrds[j].join(); + } catch (InterruptedException e) { + log.add("" + e.getMessage() + " exception while joining " + j + "-th thread"); + failed = true; + } + } + + if (failed) { + return fail("FAILED"); + } + return pass("OK"); + } + + + public void parseParams(String[] params) { + if (params.length >= 1) { + NUMBER_OF_THREADS = Integer.parseInt(params[0]); + } + if (params.length >= 2) { + NUMBER_OF_SUBTHREADS = Integer.parseInt(params[1]); + } + if (params.length >= 3) { + OUT_DIR_NAME = params[2]; + } + } +} + +class RunSerializationThread extends Thread { + + SerializableClassesTest base; + + RunSerializationThread(SerializableClassesTest base){ + this.base = base; + } + + public void run(){ + Hashtable ht = new Hashtable(); + + // First, do serialization into a file in a single SerializerThread thread + + SerializerThread serializerThread = new SerializerThread(base, base.OUT_DIR_NAME); + + serializerThread.start(); + try { + serializerThread.join(); + } catch (InterruptedException ie){ + } + + // If serialization passed with no problems, then, Second step - start + // NUMBER_OF_SUBTHREADS of threads which do deserialization from single file + // in parallel + + if (serializerThread.failed == false){ + + SerThread[] t = new SerThread[base.NUMBER_OF_SUBTHREADS]; + + for (int i = 0; i < t.length; ++i){ + t[i] = new DeSerializerThread(base, serializerThread.getSerFileName()); + t[i].start(); + } + + for (int i = 0; i < t.length; ++i){ + try { + t[i].join(); + } catch (InterruptedException ie){ + } + } + + } else { + base.log.add("Thread " + this.getId() + ": no deserialization due to failure in serialization"); + } + + // Finally, remove created by the serizliation thread (SerializerThread) files + + serializerThread.deleteSerFile(); + } +} + +abstract class SerThread extends Thread { + + SerializableClassesTest base; + + ArrayList classNames; + + volatile boolean failed = false; + + SerThread(SerializableClassesTest base){ + this.base = base; + } + + // Receives a list of classes whose instances to be created and serialized + void getClassNames() { + classNames = ClassContainer.getSerializableClassNames(); + } + + + public void run(){ + getClassNames(); + try { + createStreams(); + int instantiated = 0, noninstantiated = 0; + for (int i = 0; i < classNames.size(); ++i){ + Object o; + try { + o = instantiate(classNames.get(i)); + if (o == null){ + continue; + } + ++instantiated; + } catch (Throwable ex) { + // ex.printStackTrace(); + // System.out.println(" Failed to instantiate: " + classNames.get(i)); + ++noninstantiated; + continue; + } + process(classNames.get(i), o); // <-- this is where serialization and deserialization runs + } + // System.out.println("Instantiated " + instantiated + + // ", failed to create instance " + noninstantiated + " classes"); + } catch (Throwable t){ + // t.printStackTrace(); + base.log.add("Thread " + this.getId() + ", unexpected exception: " + t + ", with message: " + t.getMessage()); + t.printStackTrace(); + base.failed = true; + failed = true; + } finally { + closeStreams(); + } + } + + abstract void process(String className, Object object) throws Throwable; + + Object instantiate(String className) throws Throwable { + Class c = Class.forName(className); + if (!checkSerializableAndNotAbstract(c)){ + return null; + } + Object o = null; + try{ + o = c.newInstance(); + }catch (Throwable e){ + // Ignore + return null; + } + //System.out.println(className); + return o; + } + + // Functions checks that class has Serializable interface and not abstract + boolean checkSerializableAndNotAbstract(Class c){ + + Class []intfs = c.getInterfaces(); + // try to find jlSerializableClass in interfaces + for (int i = 0; i < intfs.length; i++){ + if (intfs[i].equals(base.jlSerializableClass)){ + int md = c.getModifiers(); + if (Modifier.isAbstract(md)){ + return false; + } + return true; + } + } + + // jlSerializableClass not found - try to do find it in base class + Class baseCls = c.getSuperclass(); + if (baseCls != null){ + return checkSerializableAndNotAbstract(baseCls); + } + + return false; + } + + abstract void createStreams() throws Exception; + abstract void closeStreams(); +} + + +class SerializerThread extends SerThread { + ObjectOutputStream oos; + OutputStream os; + String fileName; + String outDir; + + SerializerThread(SerializableClassesTest base, String outDir){ + super(base); + this.outDir = outDir; + } + + void process(String className, Object object) throws Throwable { + try { + oos.writeObject(object); + // store class and its serialized object in order to compare class of deserialized + // object - later, in DeSerializerThread-s + //System.out.println(object.getClass().getName() + " : " + fileName); + } catch (NullPointerException e){ + // skip + } catch (NotSerializableException e){ + // skip - the test is not intendent to check NotSerializableException + } catch (Throwable t) { + base.log.add("Thread " + this.getId() + ": serialization of " + className + ": unexpected exception " + t); + throw t; + } + } + + void createStreams() throws Exception { + this.oos = new ObjectOutputStream(createOutputStream()); + } + + OutputStream createOutputStream() throws Exception { + this.fileName = createSerFile().getAbsolutePath(); + return (this.os = new FileOutputStream(fileName)); + } + + File createSerFile(){ + File f = null; + synchronized (base){ + f = new File(new File(outDir).getAbsolutePath() + File.separator + + "SerializableClassesTest" + File.separator + this.getId() + "_" + this.hashCode() + "_file.ser"); + if (f.exists()){ + f.delete(); + } else { + File f2 = new File(f.getParent()); + f2.mkdirs(); + } + } + return f; + } + + String getSerFileName(){ + return this.fileName; + } + + void deleteSerFile(){ + File f = new File(fileName); + synchronized(base){ + f.delete(); + } + } + + void closeStreams(){ + if (os != null){ + try { + this.os.close(); + } catch (IOException ioe){ + } + } + if (oos != null) { + try { + this.oos.close(); + } catch (IOException ioe){ + } + } + } +} + +class DeSerializerThread extends SerThread { + + ObjectInputStream ois; + InputStream is; + String fileName; + + DeSerializerThread(SerializableClassesTest base, String fileName){ + super(base); + this.fileName = fileName; + } + + void process(String className, Object object) throws Throwable { + try { + Object deserializedObject = null; + try{ + deserializedObject = ois.readObject(); + } catch(IOException e){ + // skip + return; + } + if (deserializedObject == null){ + return; + } + + synchronized(deserializedObject){ // just for additional testing, no special meaning + Thread.yield(); + if (className == deserializedObject.getClass().getName()){ + base.log.add("Thread " + this.getId() + ", deserialization of: " + className + + ": readObject() returned instance of " + deserializedObject.getClass() + + "instead of expected " + className + " : " + fileName); + base.failed = true; + failed = true; + } + //deserializedObject.notifyAll(); + } + } catch (Throwable t) { + base.log.add("Deserialization of " + className + ": unexpected exception " + t); + throw t; + } + } + + void createStreams() throws Exception { + this.ois = new ObjectInputStream(createInputStream()); + } + + InputStream createInputStream() throws Exception { + return (this.is = new FileInputStream(this.fileName)); + } + + void closeStreams(){ + if (ois != null){ + try { + this.ois.close(); + } catch (IOException ioe){ + } + } + if (is != null){ + try { + this.is.close(); + } catch (IOException ioe){ + } + } + } +} + + +class ClassContainer { + + static ArrayList serializableClassNamesAL = null; + + static synchronized ArrayList getSerializableClassNames() { + if (serializableClassNamesAL == null){ + serializableClassNamesAL = initAL(); + } + return serializableClassNamesAL; + } + + static ArrayList initAL() { + ArrayList al = JarFilesScanner.getClassFilesInJRE(); + for (int i = 0; i< al.size(); i++){ + String nm = al.get(i); + nm = nm.replace("/", "."); + nm = nm.replace("\\", "."); + nm = nm.replace(".class", ""); + al.set(i, nm); + } + return al; + } + +} Property changes on: src/java/org/apache/harmony/test/reliability/api/serialization/SerializableClassesTest.java ___________________________________________________________________ Name: svn:executable + *