You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2007/06/08 18:35:10 UTC

svn commit: r545554 [4/13] - in /harmony/enhanced/buildtest/branches/2.0/tests/reliability: ./ run/ src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/harmony/ src/java/org/apache/harmony/test/ src/java/org/apache/harmony/test/reliab...

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/ShtdwnHooksCornerCaseTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/ShtdwnHooksCornerCaseTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/ShtdwnHooksCornerCaseTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/ShtdwnHooksCornerCaseTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,631 @@
+/*
+ * Copyright 2006 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 Tatyana V. Doubtsova
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.hooks;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Goal: Check various unusual cases of operating with shutdown hooks expecting there will be
+ *       no hang, abnormal completion or other unexpected behavior.
+ *
+ * The test does:
+ *
+ *      1. Reads parameters:
+ *            args[0] is a path to vm to start via Runtime.exec().
+ *            args[1] is a path to the directory to specify in -classpath option for 
+ *                    the vm started via Runtime.exec() in tests to find test classes.
+ *
+ *      2. For each of 9 classes (each representing some shutdown hook usage case) runs 
+ *         each via Runtime.exec(<vm> -classpath <classes dir> <class> <number of hooks>).
+ *
+ *      3. 9 cases/classes are:
+ *           * Hooks are added in finalize() method.
+ *           * Hooks try to add new hooks while running, expect IllegalStateException.
+ *           * Hooks try to remove themselves while running, expect IllegalStateException.
+ *           * Hooks call System.gc() in its run() method, expecting no crash/hang/etc.
+ *           * Hooks call Runtime.runFinalization() in its run() method, expecting no crash/hang/etc.
+ *           * Hooks call System.exit() in its run() method, expecting no crash/hang/etc.
+ *           * Hooks call Runtime.halt() in its run() method, expecting no crash/hang/etc.
+ *           * All hooks but one complete normally, the other calls Runtime.halt() in its run()
+ *             method, expecting no crash/hang/etc.
+ *           * Hooks create new objects, call runFinalization(). It is expected that all created
+ *             objects are finalized.
+ *
+ *      4. The main class waits for exec()-ed process completion, destroys the process if it 
+ *         hung, analizes exit code and process output (if necessary) to check that hooks worked ok.
+ */
+
+public class ShtdwnHooksCornerCaseTest extends Test {
+
+    static final int EXIT_CODE = 55;
+
+    static final int HALT_CODE = 44;
+
+    static final int BYTE_ARRAY_SIZE = 2000;
+
+    static final int N_OF_HOOKS = 100;
+
+    static final int SLEEP_TIMEOUT = 50;
+
+    static final int ITERATIONS = 300;
+
+    static final String ok = "ok";
+
+    static final String delimiter = ":";
+
+    String classpathDir = ".";
+
+    String vmPath = "";
+
+    static final String CLASSPATH_OPT = "-classpath";
+
+    // This must be the same name as package name of this class
+
+    static final String package_name = "org.apache.harmony.test.reliability.api.kernel.hooks.";
+
+
+    // These are names of the classes to run by java in another process.
+    // The classes add various shutdown hooks and exit, thus initiating running hooks.
+    // See class descriptions near class declarations.
+
+    static final String AddHookViaFinalizationClass = package_name + "AddHookViaFinalization";
+    static final String AddHookWhileHookRunningClass = package_name + "AddHookWhileHookRunning";
+    static final String RmHookWhileHookRunningClass = package_name + "RmHookWhileHookRunning";
+    static final String RunFinalizationWhileHookRunningClass = package_name + "RunFinalizationWhileHookRunning";
+    static final String SysGCWhileHookRunningClass = package_name + "SysGCWhileHookRunning";
+    static final String SysExitWhileHookRunningClass = package_name + "SysExitWhileHookRunning";
+    static final String HaltWhileHookRunningClass = package_name + "HaltWhileHookRunning";
+    static final String SysExitAndHaltWhileHookRunningClass = package_name + "SysExitAndHaltWhileHookRunning";
+    static final String ObjectsCreatedInHooksFinalizedClass = package_name + "ObjectsCreatedInHooksFinalized";
+
+
+    public static void main(String[] args) {
+        System.exit(new ShtdwnHooksCornerCaseTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        boolean passed = true; 
+        boolean status = false;
+
+        // Run successively 9 different cases of shutdown hooks:
+            
+        status = runApp(AddHookViaFinalizationClass);
+        passed = passed & status;
+        // log.add("Application added hooks in finzalize() method. Test passed?: " + status + "\n");
+
+        status = runApp(AddHookWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("Hooks were added while running hooks, expecting IllegalStateException. Test passed?: " + status + "\n");
+
+        status = runApp(RmHookWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("Hooks delete themselves while running, expecting IllegalStateException. Test passed?: " + status + "\n");
+
+        status = runApp(RunFinalizationWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("Runtime.runFinalization() was called while hooks running. Test passed?: " + status + "\n");
+
+        status = runApp(SysGCWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("System.gc() was called while hooks running. Test passed?: " + status + "\n");
+
+        //          This case is excluded from the test as incorrect, because, due to J2SE 1.5 Runtime.exit() spec
+        //          "...If this method is invoked after the virtual machine has begun its shutdown
+        //          sequence then if shutdown hooks are being run this method will block indefinitely..."
+            
+        /*            status = runApp(SysExitWhileHookRunningClass);
+         passed = passed & status;
+         log.add("System.exit() was called in hooks while hooks running. Test passed?: " + status + "\n");
+         */
+        status = runApp(HaltWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("Runtime.halt() was called in hooks while hooks running. Test passed?: " + status + "\n");
+
+        status = runApp(SysExitAndHaltWhileHookRunningClass);
+        passed = passed & status;
+        // log.add("All hooks completed normally but one called Runtime.halt() while hook running. " +
+        //        "Test passed?: " + status + "\n");
+
+        status = runApp(ObjectsCreatedInHooksFinalizedClass);
+        passed = passed & status;
+        // log.add("Hooks create objects. Were all objects finalized?: " + status + "\n");
+
+        if (!passed) {
+            return fail("Failed");
+        }
+
+        return pass("OK");
+    }
+
+
+
+    boolean runApp(String className) {
+
+        int n_of_hooks = N_OF_HOOKS;
+
+        // Run class specified by className via runtime whose path is passed 
+        // as test argument, stored in 'vmPath' variable.
+
+        // Command line to run is:
+        // <vmPath> -classpath <classes dir> <className> <number of hooks to register>
+
+        String[] cmd = createCmdLine(className, n_of_hooks);
+
+        // log.add("Running: " + cmd[0] + " " + cmd[1] + " " + cmd[2] + " " + cmd[3] + " " + cmd[4]);
+
+        boolean passed = true;
+
+        try {
+
+            Process p = Runtime.getRuntime().exec(cmd);
+
+            // The process is started, experiments show that the process can hang.
+            // To manage hanging we wait for ITERATIONS*SLEEP_TIMEOUT milliseconds
+            // periodically checking whether the process has finished (ITSE is not 
+            // thrown). If the process hangs, we destroy the process.
+
+            int ev = 0;
+            boolean process_finished = false;
+
+            for (int i = 0; i < ITERATIONS; ++i) {
+                try {
+                    Thread.sleep(SLEEP_TIMEOUT);
+                } catch (InterruptedException ie){
+                }
+
+                try {
+                    ev = p.exitValue();
+                    process_finished = true;
+                    break;
+                } catch (IllegalThreadStateException itse){
+                }
+            }
+
+            if (!process_finished) {
+                p.destroy();
+                log.add("Process was destroyed after " + (ITERATIONS * SLEEP_TIMEOUT)/1000 + " seconds, hanging?...");
+                passed = false;
+
+            } else {
+
+                // The process exited (did not hang), let check its exit value.
+                // Should be either 0 (normal completion) or expected for some executed 
+                // classes exit value.
+
+                if (ev != 0 && ev != EXIT_CODE && ev != HALT_CODE) {
+                    log.add("Process returned " + ev + ", instead of expected 0 or " + EXIT_CODE + " or " + HALT_CODE);
+                    passed = false;
+                }
+
+                passed &= checkOutput(p, className, n_of_hooks);
+            }
+        
+        } catch (Exception e){
+            e.printStackTrace();
+            log.add("Unexpected exception while exec()");
+            passed = false;
+        }
+
+        return passed;
+    }
+
+    boolean checkOutput(Process p, String className, int n_of_hooks) {
+
+        // For each of the three classes, which check whether or not some exception is thrown 
+        // in the hooks, we check output from the hooks - if it is as expected 
+        // then the exception was thrown as expected.
+
+        if (!AddHookWhileHookRunningClass.equals(className) && 
+            !RmHookWhileHookRunningClass.equals(className) &&
+            !ObjectsCreatedInHooksFinalizedClass.equals(className)) {
+            return true;
+        }
+
+        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();
+            log.add("IOException while reading from process InputStream");
+            return false;
+        }
+
+        byte[] bb = new byte[i];
+        System.arraycopy(b, 0, bb, 0, bb.length);
+
+        // Convert read bytes into string using default encoding:
+
+        String s = new String(bb);
+
+        // log.add(s);
+
+        String[] ss = s.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) {
+            if (ObjectsCreatedInHooksFinalizedClass.equals(className)) {
+                log.add(ss.length + " objects created in hooks were finalized instead of " + n_of_hooks);
+            } else {
+                log.add(ss.length + " hooks threw IllegalStateException instead of expected " + n_of_hooks);
+            }
+            return false;
+        }
+
+        return true;
+    }
+
+    String[] createCmdLine(String className, int n_of_hooks_to_start) {
+        String[] s = new String[5];
+        s[0] = vmPath;
+        s[1] = CLASSPATH_OPT;
+        s[2] = classpathDir;
+        s[3] = className;
+        s[4] = "" + n_of_hooks_to_start;
+        return s;
+    }
+
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            vmPath = params[0];
+        }
+
+        if (params.length >= 2) {
+            classpathDir = params[1];
+        }
+    }
+
+}
+
+
+
+    // ---------------------  Case 1: Add hook in finalize() ---------------
+
+    // This class started by VM via main(args) creates some objects (SomeObject) to be finalized, 
+    // however, in finalize() methods of the objects we add hooks, so that the hooks 
+    // are added when finalization process is running.
+
+class AddHookViaFinalization {
+
+    public static void main(String[] args){
+        int n_of_hooks = Integer.parseInt(args[0]);
+
+        for (int i = 0; i < n_of_hooks; ++i) {
+            createSomeObjects();
+
+            if (i % 10 == 0) {
+                Runtime.getRuntime().runFinalization();
+            }
+        }
+    }
+
+    static void createSomeObjects() {
+        new SomeObject();
+    }
+
+}
+
+
+class SomeObject {
+
+    public SomeObject() {
+
+        // This is just to stimulate gc:
+
+        byte[] b = new byte[ShtdwnHooksCornerCaseTest.BYTE_ARRAY_SIZE];
+    }
+
+    protected void finalize() {
+
+        // Add some simple hook, expecting no abnormal completion or exceptions:
+
+        Runtime.getRuntime().addShutdownHook(new SomeHook());
+    }
+
+}
+
+    // Some hook class - does nothing.
+
+class SomeHook extends Thread {
+
+    public void run() {
+    }
+
+}
+
+    // --------------------- Case 2: 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){
+
+            // why synchronized? - to avoid a mess when several simultaneously running
+            // threads write "OK" status into stdout.
+
+            synchronized (obj) {
+                System.out.print(ShtdwnHooksCornerCaseTest.ok + ShtdwnHooksCornerCaseTest.delimiter);
+            }
+        }
+    }
+}
+
+    // --------------------- Case 3: 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){
+
+            // why synchronized? - to avoid a mess when several simultaneously running
+            // threads write "OK" status into stdout.
+
+            synchronized (obj) {
+                System.out.print(ShtdwnHooksCornerCaseTest.ok + ShtdwnHooksCornerCaseTest.delimiter);
+            }
+        }
+    }
+}
+
+    // --------------------- Case 4: Run Runtime.runFinalization() while hook running ---------------
+
+    // This class adds hooks which call Runtime.runFinalization() method, expecting no 
+    // abnormal completion or unexpected behavior.
+
+class RunFinalizationWhileHookRunning {
+
+    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_RunFinalizationWhileHookRunning());
+        }
+    }
+}
+
+class Hook_RunFinalizationWhileHookRunning extends Thread {
+
+    public void run() {
+        Runtime.getRuntime().runFinalization();
+    }
+
+}
+
+
+    // --------------------- Case 5: Run System.gc() while hook running ---------------
+
+    // This class adds hooks which call System.gc() method, expecting no 
+    // abnormal completion or unexpected behavior.
+
+class SysGCWhileHookRunning {
+
+    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_SysGCWhileHookRunning());
+        }
+    }
+}
+
+class Hook_SysGCWhileHookRunning extends Thread {
+
+    public void run() {
+        System.gc();
+    }
+
+}
+
+
+    // --------------------- Case 6: Run System.exit() while hook running ---------------
+
+    // This class adds hooks which call System.exit(), expecting no hanging or 
+    // abnormal completion or other unexpected behavior.
+    // This case is excluded from the test as incorrect, because, due to J2SE 1.5 Runtime.exit() spec
+    //  "...If this method is invoked after the virtual machine has begun its shutdown
+    //  sequence then if shutdown hooks are being run this method will block indefinitely..."
+
+    /*
+     class SysExitWhileHookRunning {
+
+     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_SysExitWhileHookRunning());
+     }
+     }
+     }
+
+     class Hook_SysExitWhileHookRunning extends Thread {
+
+     public void run() {
+     System.exit(ShtdwnHooksCornerCaseTest.EXIT_CODE);
+     }
+
+     }
+     */
+
+    // --------------------- Case 7: Run Runtime.halt() while hook running ---------------
+
+    // This class adds hooks which call Runtime.halt(), expecting no hanging or 
+    // abnormal completion or other unexpected behavior.
+
+class HaltWhileHookRunning {
+
+    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_HaltWhileHookRunning());
+        }
+    }
+}
+
+class Hook_HaltWhileHookRunning extends Thread {
+
+    public void run() {
+        Runtime.getRuntime().halt(ShtdwnHooksCornerCaseTest.HALT_CODE);
+    }
+
+}
+
+
+    // --------------------- Case 8: All hooks complete normally, but one calls Runtime.halt() ---------------
+
+    // This class adds hooks, half of them call System.exit() another half - Runtime.halt(), 
+    // expecting no hanging or abnormal completion or other unexpected behavior.
+
+class SysExitAndHaltWhileHookRunning {
+
+    public static void main(String[] args){
+
+        int n_of_hooks = Integer.parseInt(args[0]);
+
+        for (int i = 0; i < n_of_hooks; ++i) {
+            if (i == n_of_hooks / 2){
+                Runtime.getRuntime().addShutdownHook(new Hook_HaltWhileHookRunning());
+            } else {
+                Runtime.getRuntime().addShutdownHook(new SomeSleepingHook());
+            }
+        }
+    }
+}
+
+
+    // Some hook class - does nothing.
+
+class SomeSleepingHook extends Thread {
+
+    public void run() {
+        synchronized (this) {
+            try {
+                this.wait();
+            } catch (InterruptedException ie){
+            }
+        }
+    }
+
+}
+
+
+    // --------------------- Case 9: Check finalization is called for objects created by hooks ---------------
+
+    // This class adds hooks which create new objects. It is expected that the objects
+    // will be sooner or later all finalized before VM actually exits (each object prints 
+    // OK status in its finalize() method).
+
+class ObjectsCreatedInHooksFinalized {
+
+    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_ObjectsCreatedInHooksFinalized());
+        }
+        Runtime.getRuntime().runFinalizersOnExit(true);
+    }
+}
+
+class Hook_ObjectsCreatedInHooksFinalized extends Thread {
+
+    public void run() {
+        m();
+        Thread.yield();
+        Runtime.getRuntime().runFinalization();
+    }
+
+    void m() {
+        new ObjectToFinalize();
+    }
+
+}
+
+
+class ObjectToFinalize {
+
+    static Object obj = new Object();
+
+    public ObjectToFinalize() {
+        byte[] b = new byte[ShtdwnHooksCornerCaseTest.BYTE_ARRAY_SIZE];
+    }
+
+    protected void finalize() {
+        synchronized(obj){
+            System.out.print(ShtdwnHooksCornerCaseTest.ok + ShtdwnHooksCornerCaseTest.delimiter);
+        }
+    }
+}
+
+
+
+
+
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/ShtdwnHooksCornerCaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/management/SystemResourceOrientedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/management/SystemResourceOrientedTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/management/SystemResourceOrientedTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/management/SystemResourceOrientedTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,376 @@
+/*
+ * 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.kernel.management;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.lang.management.*;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+/**
+ *  Goal: check j.l.management package allows to gather system resource info in MT runtime
+ *        The test does:
+ *        1. Reads parameters, which are:
+ *           param[0] - number of threads
+ *           param[1] - number of iterations
+ *           param[2] - classFolder where to get loaded class
+ *           param[3] - number of classes to load per one test run
+ *        2. Creates param[0]-sized array of threads and starts them. 4 types of Threads are created 
+ *           1 - MemWorkerThread - creates different size object in a loop
+ *           2-  ProcWorkerThread - performs some Math operations
+ *           3-  CLassloadingWorkerThread - loads param[2] number of classes with 
+ *               UserDefined classloader
+ *           4-  SuspendResumeSleepWorkerThread - sleeps in a loop
+ *        3. The main thread performs almost all admitted operations from j.l.management 
+ *        5. The main thread sets flag to stop running threads and joins them.
+ * 
+ *        No hang, fail or crash is excpected.
+ *    
+ */
+
+public class SystemResourceOrientedTest extends Test {
+    static final int NUMBER_OF_THREADS = 30;
+    static final int NUMBER_OF_ITERATIONS = 20; 
+    static int numberOfIterations = NUMBER_OF_ITERATIONS;
+    static int numberOfThreads = NUMBER_OF_THREADS;
+    static final int NUMBER_OF_LOADED_CLASSES = 1000;
+    static volatile int numberOfLoadedClasses = NUMBER_OF_LOADED_CLASSES;    
+    static String classFolder = System.getProperty("java.class.path");
+    volatile public static boolean failed = false; 
+    volatile static boolean stopThreads = false; 
+
+    public static void main(String[] args) {
+        System.exit(new SystemResourceOrientedTest().test(args));
+    }
+
+    public int test(String[] params) {
+        parseParams(params);
+
+        Thread thrds[] = new Thread[numberOfThreads];
+        for (int i = 0; i< numberOfThreads; i++){
+            thrds[i] = newThread(i);
+            thrds[i].start();
+        }
+        
+        // process testing of j.l.management
+        
+        for (int t=0; t<numberOfIterations; t++){
+            // class loading
+            ClassLoadingMXBean cmb = ManagementFactory.getClassLoadingMXBean();
+            cmb.isVerbose();
+            long l1 = cmb.getTotalLoadedClassCount();
+            long l2 = cmb.getLoadedClassCount();
+            long l3 = cmb.getUnloadedClassCount();
+            if ((l2 + l3) > l1){
+                failed = true;
+                log.add("Number of currently loaded and unloaded classes more than number of totally loaded classes since JVM started.");
+                break;
+            }
+            
+            // methods compiled with JIT info 
+            CompilationMXBean mmb = ManagementFactory.getCompilationMXBean();
+            if (mmb.isCompilationTimeMonitoringSupported()){
+                mmb.getName();
+                mmb.getTotalCompilationTime();
+            }
+            
+            // GC info
+            List<GarbageCollectorMXBean> gcmb = ManagementFactory.getGarbageCollectorMXBeans();
+            for (int i = 0; i<gcmb.size();i++){
+                GarbageCollectorMXBean gcm = gcmb.get(i);
+                gcm.getCollectionCount();
+                gcm.getCollectionTime();
+            }
+            
+            // memory pools inside JVM
+            List<MemoryManagerMXBean> mmmb = ManagementFactory.getMemoryManagerMXBeans();
+            for (int i=0; i< mmmb.size(); i++){
+                MemoryManagerMXBean m = mmmb.get(i);
+                if (m.isValid()){
+                    String names[] = m.getMemoryPoolNames();
+                    for (int j=0;j<names.length;j++){
+                        // do something
+                        names[j].hashCode();
+                    }
+                    m.getName();
+                }
+            }
+            
+            // java heap
+            MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
+            mb.gc();
+            mb.getHeapMemoryUsage();
+            mb.getNonHeapMemoryUsage();
+            mb.getObjectPendingFinalizationCount();
+            
+            // OS
+            OperatingSystemMXBean omb = ManagementFactory.getOperatingSystemMXBean();
+            omb.getArch();
+            omb.getAvailableProcessors();
+            omb.getName();
+            omb.getVersion();
+            
+            // Runtime
+            RuntimeMXBean rmb = ManagementFactory.getRuntimeMXBean();
+            rmb.getBootClassPath();
+            rmb.getClassPath();
+            rmb.getInputArguments();
+            rmb.getLibraryPath();
+            rmb.getManagementSpecVersion();
+            rmb.getName();
+            rmb.getSpecName();
+            rmb.getSpecVendor();
+            rmb.getStartTime();
+            rmb.getUptime();
+            rmb.getSystemProperties();
+            rmb.getVmName();
+            rmb.getVmVendor();
+    
+            // thread
+            ThreadMXBean tmb = ManagementFactory.getThreadMXBean();
+            tmb.findMonitorDeadlockedThreads();
+            long[] ths = tmb.getAllThreadIds();
+            tmb.getCurrentThreadCpuTime();
+            tmb.getCurrentThreadUserTime();
+            tmb.getDaemonThreadCount();
+            tmb.getPeakThreadCount();
+            tmb.getThreadCount();
+            tmb.getThreadInfo(ths);
+            tmb.getTotalStartedThreadCount();
+            tmb.isCurrentThreadCpuTimeSupported();
+            tmb.isThreadContentionMonitoringEnabled();
+            tmb.isThreadContentionMonitoringSupported();
+            tmb.isThreadCpuTimeEnabled();
+            tmb.isThreadCpuTimeSupported();
+            tmb.resetPeakThreadCount();
+            
+        }
+        
+        // stop threads
+        stopThreads = true;
+
+        for (int i = 0; i< numberOfThreads; i++){
+            try {
+                thrds[i].join();
+            } catch (InterruptedException e) {
+                failed = true;
+                log.add("Main Thread was interrupted");
+            }
+        }
+        
+        if (failed){
+            return fail("");
+        }else{
+            return pass("OK");
+        }
+            
+    }
+    
+    static Thread newThread(int i){
+        Thread ret = null;
+        switch(i%4){
+            case 0:
+                ret = new MemWorkerThread(); 
+                break;
+            case 1:
+                ret = new ProcWorkerThread(); 
+                break;
+            case 2:
+                ret = new SuspendResumeSleepWorkerThread(); 
+                break;
+            case 3:
+                ret = new CLassloadingWorkerThread(); 
+                break;
+        }
+        return ret;
+    }
+    
+
+    public void parseParams(String[] params) {
+        if (params.length >= 1) {
+            numberOfThreads = Integer.parseInt(params[0]);
+        }
+        if (params.length >= 2) {
+            numberOfIterations = Integer.parseInt(params[1]);
+        }
+        if (params.length >= 3) {        
+            classFolder = params[2];
+        }
+        if (params.length >= 4) {        
+            numberOfLoadedClasses = Integer.parseInt(params[3]);
+        }
+        
+    }
+
+}
+
+class MemWorkerThread extends Thread{
+    static final int ARRAY_SIZE_LIMIT = 100;
+    static final int TIME_SLEEP_IF_NEEDED = 1;
+    public void run(){
+        while(!SystemResourceOrientedTest.stopThreads){
+            Object obj = emitObject();
+            if (obj == null){
+                try {
+                    Thread.sleep(TIME_SLEEP_IF_NEEDED);
+                } catch (InterruptedException e) {
+                    SystemResourceOrientedTest.failed = true;
+                    SystemResourceOrientedTest.log.add("thread " + this.getId() + " was interrupted!");
+                    return;
+                }
+            }else{
+                obj = null;
+            }
+        }
+    }
+    
+    Object emitObject(){
+        Random rm = new Random();
+        Object ret = null;
+        // generate different objects
+        switch(rm.nextInt(10)){
+            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("");
+                break;
+            default:
+                ret = null;
+        }
+        return ret;
+    }
+    
+}
+
+class ProcWorkerThread extends Thread{
+    static Random rm = new Random();
+    static final int TIME_SLEEP_IF_NEEDED = 10;
+    public void run(){
+        while(!SystemResourceOrientedTest.stopThreads){
+            // make some Math operations
+            Math.cos(rm.nextInt());
+            Math.log(rm.nextDouble());
+            Math.sqrt(rm.nextDouble());
+        }
+    }
+}
+
+class SuspendResumeSleepWorkerThread extends Thread{
+    static final int THREAD_SLEEP_TIME = 1000;
+    public void run(){
+        while(!SystemResourceOrientedTest.stopThreads){
+            try {
+                Thread.sleep(THREAD_SLEEP_TIME);
+            } catch (InterruptedException e) {
+                SystemResourceOrientedTest.failed = true;
+                SystemResourceOrientedTest.log.add("thread " + this.getId() + " was interrupted!");
+                return;
+            }
+        }
+    }
+}
+
+class CLassloadingWorkerThread extends Thread{
+    static final int THREAD_SLEEP_TIME = 1000;
+    public void run(){
+        while(!SystemResourceOrientedTest.stopThreads && SystemResourceOrientedTest.numberOfLoadedClasses > 0){
+            SystemResourceOrientedTest.numberOfLoadedClasses--;        
+            try {
+                Thread.sleep(THREAD_SLEEP_TIME);
+            } catch (InterruptedException e) {
+                SystemResourceOrientedTest.failed = true;
+                SystemResourceOrientedTest.log.add("thread " + this.getId() + " was interrupted!");
+                return;
+            }
+            
+            String classPath = SystemResourceOrientedTest.classFolder + File.separator + 
+                this.getClass().getPackage().getName().replace(".", File.separator) +
+                File.separator + "ManTestClass.class";
+            ClassLoader cl = new CstmLoader(classPath);
+            try {
+                cl.loadClass("SOME_NAME");
+            } catch (ClassNotFoundException e) {
+                SystemResourceOrientedTest.failed = true;
+                SystemResourceOrientedTest.log.add("Faile dto load class " + classPath);
+                return;
+            }
+        }
+    }
+}
+
+
+class CstmLoader extends ClassLoader {
+    String classFile = null;
+
+    CstmLoader(String file){
+        classFile = file;
+    }
+
+    private byte[] loadBinary(String className){
+        byte[] b = null;
+        try {
+            FileInputStream fis = new FileInputStream(classFile);
+            b = new byte[fis.available()];
+            fis.read(b);
+            fis.close();
+        } catch (Exception e) {
+            return null;
+        }
+        
+        return b;
+    }
+    
+    protected Class<?> findClass(String name) throws ClassNotFoundException {
+    byte[] b = loadBinary(name);
+    if (b == null){
+    throw new ClassNotFoundException();
+}
+    return defineClass(b, 0, b.length);
+}
+}
+
+class ManTestClass{
+    int t;
+}
\ No newline at end of file

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/management/SystemResourceOrientedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectCloneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectCloneTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectCloneTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectCloneTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.object;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by Object.clone() operation.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize in a cycle and number of clones
+ *       2. Excutes a cycle of param[0] iterationss, on each iteration:
+ *            creates param[0] number of clones for the different objects
+ */
+
+public class ObjectCloneTest extends Test implements Cloneable {
+
+    public static int NUMBER_OF_ITERATIONS = 1000;
+
+    static {
+        for(int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            try {
+                new Cloner().clone();
+            } catch(CloneNotSupportedException e) {
+                e.printStackTrace();
+            }
+        }
+
+        for(int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            _clone();
+        }
+    }
+
+
+    public static void main(String[] args) {
+        System.exit(new ObjectCloneTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for(int i = 0; i < NUMBER_OF_ITERATIONS; i++) {                                                      
+            ObjectCloneTest t = new ObjectCloneTest();
+            t.test_clone();
+            static_test_clone(t);
+            static_clone();
+        }
+
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+    }
+
+    Object test_clone() {
+        Object obj = null;    
+
+        for(int i = 0; i < ObjectCloneTest.NUMBER_OF_ITERATIONS; i++) {
+            try {
+                obj = new Cloner().clone();
+            } catch(CloneNotSupportedException e) {
+                e.printStackTrace();
+            }
+        }
+
+        for(int i = 0; i < ObjectCloneTest.NUMBER_OF_ITERATIONS; i++) {
+            obj = _clone();
+        }
+        return obj;
+    }
+
+
+    static Object _clone() {
+        Object obj = null;    
+        try {
+            obj = new Cloner().clone();
+        } catch(CloneNotSupportedException e) {
+            e.printStackTrace();
+        }
+        return obj;
+    }
+
+    static Object static_test_clone(ObjectCloneTest t) {
+
+        Object obj = null;    
+        for(int i = 0; i < ObjectCloneTest.NUMBER_OF_ITERATIONS; i++) {
+            try {
+                obj = t.clone();
+            } catch(CloneNotSupportedException e) {
+                e.printStackTrace();
+            }
+        }
+        return obj;
+    }
+
+ 
+
+    static Object  static_clone(){
+        Object obj = null;    
+        for(int i = 0; i < ObjectCloneTest.NUMBER_OF_ITERATIONS; i++) {
+            try {
+                obj = new Cloner().clone();
+            } catch(CloneNotSupportedException e) {
+                e.printStackTrace();
+            }
+        }
+        return obj;
+    }
+
+}
+
+class Cloner implements Cloneable{
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectCloneTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectFinalizeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectFinalizeTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectFinalizeTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectFinalizeTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.object;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by Object.finalize() operation.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize in a cycle
+ *       2. Excutes a cycle of param[0] iterations, on each iteration:
+ *            creates the new Finalizer object
+ *    3. The finalize() (called by the garbage collector) does:  
+ *                - invokes method in the finalize 
+ *            - assigns the string to the class variable
+ *            - invokes super.finalize()
+ */
+
+public class ObjectFinalizeTest extends Test {
+
+    public int NUMBER_OF_ITERATIONS = 1000000;
+
+
+    public static void main(String[] args) {
+        System.exit(new ObjectFinalizeTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+
+            new Finalizer();
+
+            if (i % 10000 == 0) {
+                System.gc();
+                // log.add("Iteration: " + i);
+            }
+        }
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+
+    }
+
+}
+
+class Finalizer extends Thread {
+    String str = "";
+    int id;
+
+    String toStr() {
+        return Integer.toString(id++);
+    }
+
+    Finalizer() {
+        str = toStr();
+    }
+    public void finalize() throws Throwable {
+        str = toStr();
+        super.finalize();
+    }
+
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectFinalizeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectGetclassHashcodeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectGetclassHashcodeTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectGetclassHashcodeTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectGetclassHashcodeTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.object;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by Object.getClass() / hashCode() / equals() operations.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize in a cycle
+ *       2. Excutes a cycle of param[0] iterations, on each iteration:
+ *            get the runtime class of an object
+ *          check result using hashCode() / equals()
+ */
+
+public class ObjectGetclassHashcodeTest extends Test {
+
+    public String packageName = "org.apache.harmony.test.reliability.api.kernel.object";
+    public String classPath = "";
+    
+    public int NUMBER_OF_ITERATIONS = 100000;
+
+
+    public static void main(String[] args) {
+        System.exit(new ObjectGetclassHashcodeTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        classPath = packageName + "." +"ObjectGetclassHashcodeTest";
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            try {
+                if (!testObj(classPath)) {
+                    return fail("Failed : Iteration = " + i);
+                }
+            } catch(ClassNotFoundException e) {
+                log.add(e.toString());
+                return fail("Failed");
+            }
+        }
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+    }
+
+    public boolean testObj(String classPath)  throws ClassNotFoundException {
+
+        boolean result = true;
+
+        Class   t1 = Class.forName(classPath);
+
+        Class   t2 = (new ObjectGetclassHashcodeTest()).getClass();
+
+        Class   t3 = ObjectGetclassHashcodeTest.class;
+
+        Class   s1 = (new String()).getClass();
+        
+        Class   s2 = Class.forName("java.lang.String");
+        
+        Class   s3 = (new java.lang.String()).getClass();
+
+        Class   s4 = java.lang.String.class;
+
+
+        if(!checkObj(s1, s2)) {
+            result = false;
+        }
+        if(!checkObj(s2, s3)) {
+            result = false;
+        }
+        if(!checkObj(s3, s4)) {
+            result = false;
+        }
+        if(!checkObj(t1, t2)) {
+            result = false;
+        }
+        if(!checkObj(t2, t3)) {
+            result = false;
+        }
+        return result;
+    }
+
+    public boolean checkObj( Object obj1, Object obj2 ) {
+        boolean result = true;
+        if( obj1.hashCode() != obj2.hashCode() ) {
+            log.add("Check hashCode: Classes are different!");
+            result = false;
+
+        }
+
+        if(!obj1.equals(obj2)) {
+            log.add("Check equals: Classes are different!");
+            result = false;
+        }
+        return result;
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/object/ObjectGetclassHashcodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/PackageGetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/PackageGetTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/PackageGetTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/PackageGetTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.pckg;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.MalformedURLException;
+
+
+/**
+ * Goal: find resource leaks or intermittent failures caused by Package.getName() / getImplementationTitle() / 
+ * getImplementationVendor() / getImplementationVersion() / isSealed operations.
+ *
+ * The test does:
+ *    1. Reads parameters, which are:
+ *          param[0] - number of iterations to call/initialize in a cycle
+ *    2. Excutes a cycle of param[0] iterations, on each iteration:
+ *          calls 'get' methods of an package
+ *          check result 
+ */
+
+public class PackageGetTest extends Test {
+
+    public int NUMBER_OF_ITERATIONS = 1000000;
+
+    static String pkgName = "auxiliary";    
+
+    static String name = "auxiliary.Test";    
+
+    static String urlstr = "jar:file:test.jar!/";
+
+    public static void main(String[] args) {
+        System.exit(new PackageGetTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        URL url = null;
+
+        try {
+            url = new URL(urlstr);
+        } catch(MalformedURLException e) {
+            log.add(e.toString());
+            return fail("Failed");
+        }
+
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            if (!checkGetPackage(url, pkgName, name)) {
+                return fail("Failed.");
+            }
+            if (i % 10000 == 0) {
+                System.gc();
+                // log.add("Iteration: " + i);
+            }
+        }
+        
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }
+    }
+
+    public boolean checkGetPackage(URL url, String pkg, String className)  {
+
+        boolean result = true;
+
+        URL[] urls = new URL[] {url};
+
+        URLClassLoader classLoader = new URLClassLoader(urls);
+
+        Class loadClass = null;
+        try {
+            loadClass = classLoader.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            e.printStackTrace();
+        }
+        
+        Package p = loadClass.getPackage();
+
+        if(!p.getName().equals(pkg)) {
+            log.add("Failed:package name = " + p.getName());        
+        }
+
+        if(p.getImplementationTitle() != null) {
+            log.add("implementation Title should be equals null ");
+            result = false;
+        }
+        if(p.getImplementationVendor() != null) {
+            log.add("implementation Vendor should be equals null ");
+            result = false;
+        }
+        if(p.getImplementationVersion() != null) {
+            log.add("implementation Version should be equals null ");
+            result = false;
+        }
+        if(p.getSpecificationTitle() != null) {
+            log.add("Specification Title should be equals null ");
+            result = false;
+        }
+        if(p.getSpecificationVendor() != null) {
+            log.add("Specification Vendor should be equals null ");
+            result = false;
+        }
+        if(p.getSpecificationVersion() != null) {
+            log.add("Specification Version should be equals null ");
+            result = false;
+        }
+
+        if(p.isSealed() != p.isSealed(url)) {
+            log.add("Failed: isSealed shold be equals isSealed_url");        
+            result = false;
+        }
+        return result;
+    }
+
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/PackageGetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/Test.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/Test.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/Test.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package auxiliary;
+
+public class Test {
+}

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/test.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/test.jar?view=auto&rev=545554
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/pckg/auxiliary/test.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InsensitiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InsensitiveTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InsensitiveTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InsensitiveTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.string;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.Arrays;
+
+/**
+ * Goal: find resource leaks caused by String.CASE_INSENSITIVE_ORDER field.
+ *
+ * The test does:
+ *  - sets String.CASE_INSENSITIVE_ORDER
+ *  - check result using TreeSet.addAll/TreeSet.removeAll methods
+ */
+
+public class InsensitiveTest extends Test {
+
+    public static void main(String[] args) {
+        System.exit(new InsensitiveTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+
+        String[] b = {"a", "b", "c", "d", "e", "f", "g"};
+
+        if(addRemString(b, false, b).size() != 0) {
+            return fail("Failed. size should be 0");
+        }
+
+        for(int j = 0; j < b.length; j++) {
+            if(!addRemString(b, true, b[j].toUpperCase()).equals(addRemString(b, false, b[j]))) {
+                return fail("Failed. The Sets should be equals.");
+            }
+        }
+
+
+        return pass("OK");
+    }
+
+
+    public Set addRemString(String[] a, boolean flag, String... str) {
+
+    Set<String> s = new TreeSet<String>();
+
+    if(flag) {
+    s = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+}
+    
+    s.addAll(Arrays.asList(a));
+    s.removeAll(Arrays.asList(str));
+    return s;
+}
+
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InsensitiveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.string;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.Random;
+
+
+/**
+ * Goal: find resource leaks or other problems caused by invocation of String.intern() method.
+ *
+ * Idea: being run in a cycle in a single JVM the test will lead to creation big number of different string 
+ *       objects, references to which are lost and they can be finalized and removed from the pull of
+ *       of internal string representations. There can be an errors cuased by creation and invocation of 
+ *       intern() for big number of String objects and working in parallel GC.
+ *
+ * The test does:
+ *     1. Creates a random string.
+ *     2. In static or instance contexts, in a cycle for N_OF_SAME_STRINGS times:
+ *             a. Creates a new string with the given content via new String(random string).
+ *             b. Calls intern().
+ *             c. Looses references to the created String object.
+ */
+
+public class InternTest extends Test {
+
+    static final int N_OF_SAME_STRINGS = 100;
+
+
+    public static void main(String[] args) {
+        System.exit(new InternTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+    
+        instanceContextStrManipulation();
+
+        staticContextStrManipulation();
+
+        return pass("OK");
+    }
+
+
+
+    public void instanceContextStrManipulation() {
+
+        String str = getRandomString();
+
+        for (int i = 0; i < N_OF_SAME_STRINGS; i++) {
+
+            str = new String(str);
+
+            str.intern();
+        }
+            
+    }
+
+    public static void staticContextStrManipulation() {
+
+        String str = getRandomString();
+
+        for (int i = 0; i < N_OF_SAME_STRINGS; i++) {
+
+            str = new String(str);
+
+            str.intern();
+        }
+            
+    }
+
+    static Random rnd = new Random(10);
+
+    static String getRandomString() {
+
+        char[] c = new char[rnd.nextInt(Character.MAX_VALUE)];
+
+        for (int j = 0; j < c.length; ++j){
+            c[j] = (char)rnd.nextInt(Character.MAX_VALUE);
+        }
+
+        return new String(c);
+    }
+
+}
+
+
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternThreadingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternThreadingTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternThreadingTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternThreadingTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.string;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.Random;
+
+
+/**
+ *  Goal: find resource leaks and/or race conditions in pool of internal string representations
+ *
+ *  Idea: first, make string pool big enough to make intern() operations long-executing, then, 
+ *        run many threads each calling intern() for the same string, expecting several threads
+ *        will run intern() simultaneously. If there is a race condition, it will be revealed.
+ * 
+ *  The test does:
+ *        1. In class static initializer create N_OF_POOL_STRINGS strings each of 
+ *           STRING_LENGTH length - to make string pool big enough (slow working).
+ *
+ *        2. Start N_OF_THREADS threads, each thread:
+ *           calls s.intern() for the same string 's', expecting to stimulate race condition.
+ *           calls s.intern() from within syncronized(s), expecting there can be a lock.
+ *           checks that the content of s remains the same as well as its intern reference 
+ *           despite of all invocations.
+ *
+ */
+
+public class InternThreadingTest extends Test {
+
+    static Random rnd = new Random(10);
+
+    static final int N_OF_THREADS = 50;
+
+    static final int STRING_LENGTH = 200;
+
+    static final int N_OF_POOL_STRINGS = 50000;
+
+    static String[] many_strings = new String[N_OF_POOL_STRINGS];
+
+
+    // we initialize big number of strings and add them into pool of internal
+    // representations. What for? - to make pool big enough to take long time 
+    // when searching for an entry - when new entry is added or just returned.
+
+    static {
+  
+        for (int i = 0; i < many_strings.length; ++i){
+
+            // fill-in internal string pool with random-content strings each of
+            // STRING_LENGTH length:
+ 
+            many_strings[i] = getRandomString();
+            many_strings[i].intern();
+        }
+    }
+ 
+    public static void main(String[] args) {
+        System.exit(new InternThreadingTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        Thread[] t = new Thread[N_OF_THREADS];
+
+        char[] c = getRandomCharArray();
+
+        for (int i = 0; i < t.length; ++i) {
+
+            // why passing char array? - to avoid operations with Strings which
+            // can call intern() inside, before we need this in this test...
+
+            t[i] = new InternStringThread(c);
+            t[i].start();
+        }
+
+        for (int i = 0; i < t.length; ++i) {
+            try {
+                t[i].join();
+            } catch (InterruptedException ie) {
+            }
+        }
+
+        return pass("OK");
+    }
+
+
+ 
+    static String getRandomString() {
+        return new String(getRandomCharArray());
+    }
+
+    static char[] getRandomCharArray() {
+
+        char[] c = new char[rnd.nextInt(STRING_LENGTH)];
+
+        for (int j = 0; j < c.length; ++j){
+            c[j] = (char)rnd.nextInt(Character.MAX_VALUE);
+        }
+
+        return c;
+    }
+
+}
+
+
+class InternStringThread extends Thread {
+
+    char[] c;
+
+    public InternStringThread(char[] c) {
+        this.c = c;
+    }
+
+    public void run() {
+
+        // THIS IS THE KEY CALL - we expect that each of started thread 
+        // calls s.intern() for the same-content string, expecting will
+        // run into string pool race:
+
+        String s = new String(c);
+        String intern_string = s.intern();
+
+        String str;
+
+        // just in case - lets see what happens if we call intern() while keeping
+        // lock of the string... :
+
+        synchronized(intern_string){
+            str = intern_string.intern();
+        }
+
+        if (str != intern_string) {
+            throw new RuntimeException("Wrong intern returned!");
+        }
+
+        if (!s.equals(str)) {
+            throw new RuntimeException("Wrong string content!");
+        }
+
+        // create more entries in string pool in multi-threading environment,
+        // expecting racing in pool will appear:
+
+        //InternThreadingTest.getRandomString().intern();
+
+    }
+     
+}
+
+
+
+
+
+
+
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/InternThreadingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/StringInternTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/StringInternTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/StringInternTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/StringInternTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2006 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 Nikolay Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.string;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+/*
+ * Goal: find resource leaks or other problems caused by invocation of String.intern() method.
+ *
+ * Idea: being run in a cycle in a single JVM the test will lead to creation big number of different strings 
+ *         references to which are lost and they can be finalized and removed from a pull of internal string representations.
+ *         There can be failure caused by operations done in intern() and internal representation clean-up by GC.
+ *
+ * The test does:
+ *    1. Creates a string.
+ *    2. Invokes intern().
+ *
+ */
+
+
+
+public class StringInternTest extends Test {
+
+    public int NUMBER_OF_ITERATIONS = 1000;
+
+    String s = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
+
+    public static void main(String[] args) {
+        System.exit(new StringInternTest().test(args));
+    }
+
+    public int test(String[] params) {
+        for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
+            String str = String.valueOf(i) + s;
+            str.intern();
+        }
+        return pass("OK");
+    }
+
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/string/StringInternTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/thread/Calculation/CalcTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/thread/Calculation/CalcTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/thread/Calculation/CalcTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/thread/Calculation/CalcTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2006 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 Igor A. Pyankov
+ * @version $Revision: 1.1 $
+ */
+package org.apache.harmony.test.reliability.api.kernel.thread.Calculation;
+import org.apache.harmony.test.reliability.share.Test;
+
+/**
+ * Goal: check that VM works correctly with nested thread.
+ *       Each set of nested threads calculate factorial fucntion.
+ * The test does:
+ *     1. Reads parameters, which are:
+ *        param[0] - number of task which calculate factorial
+ *        param[1] - argument factorial fucntion.
+ *        (result is value of long, so there is no point 
+ *        in seting param[1] more then 20 since 21! is overflow long)               
+ *     2. Starts param[0] threads, which starts the next one and so on ...
+ *     3. Each thread (except the last), being started:
+ *         a. Calculates intermediate result
+ *         b. Starts next thread and pass calculated results and auxilary variables to it                 
+ *         d. Finishes 
+ *     4. Last thread save results into array    
+ *
+ */
+
+public class CalcTest extends Test {
+    int depth = 20;
+    volatile int started = 0;
+    volatile int tasks = 20;    
+    volatile Object lock = new Object();
+    long[] results;
+    long sample;
+
+    public static void main(String[] args) {
+        System.exit(new CalcTest().test(args));
+    }
+
+    public int test(String[] params) {
+
+        parseParams(params);
+        started = 0;
+        sample = 1L;
+        results = new long[tasks];
+        
+        for (int i = 0; i < depth;) {
+            sample *= ++i;
+        }               
+          
+        // create param[0] tasks
+        for (int i = 0; i < tasks; i++) {
+            CreateTask(i, depth, 1L, lock);
+        }
+
+        // wait for finish
+        while (started > 0) {}
+        
+        // check result
+        for (int i = 0; i < tasks; i++) {
+            if (results[i] != sample) {
+                log.add("Thread #" + i + " got wrong result " + results[i]
+                    + " instead of " + sample);
+                return fail("Test failed");
+            }
+        }
+
+        return pass("OK");
+    }
+
+    public void parseParams(String[] params) {
+        if (params.length >= 1) {
+            tasks = Integer.parseInt(params[0]);
+            if (params.length >= 2) {
+                depth = Integer.parseInt(params[1]);
+            }
+        }
+    }
+
+
+    synchronized protected void CreateTask( int resultindex,  int iteration, long value, Object lock) {        
+        CalcTask task = new CalcTask(this, resultindex, iteration, value, lock);
+    }
+}
+
+class CalcTask extends Thread {
+    CalcTest parent;
+    int iteration;
+    long value;
+    Object lock;
+    int resultindex;
+    
+    public CalcTask ( CalcTest parent, int resultindex, int iteration, long val, Object lock) {
+        this.parent = parent;
+        this.iteration = iteration;
+        this.value = val;
+        this.lock = lock;
+        this.resultindex = resultindex;
+        setDaemon(true);
+        setPriority(Thread.NORM_PRIORITY);
+        synchronized (lock) {
+            parent.started++;
+        }    
+        start();
+    }
+
+    public void run() {
+                 
+        if (iteration > 0) {
+            value *= iteration--;
+            parent.CreateTask(resultindex, iteration, value, lock);
+        } else {
+            //CalcTest.log.add("value= " + value);
+            parent.results[resultindex] = value; 
+        }
+        synchronized (lock) {
+            parent.started--;
+        }   
+    }
+}
+

Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/thread/Calculation/CalcTest.java
------------------------------------------------------------------------------
    svn:eol-style = native