harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r545554 [3/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...
Date Fri, 08 Jun 2007 16:35:10 GMT
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/ExecEnvTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/ExecEnvTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/ExecEnvTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/ExecEnvTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,314 @@
+/*
+ * 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 Oleg Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.args;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.Random;
+
+/**
+ * Goal: check that Runtime.exec() passes big number of big-size environment variables
+ * 
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ *      1) args[0] - number of iterations and maximum number of environment variables; muliplied by
+ *         'Multiplier' (typically 10) it is maximum size of enviroment variable value (number of chars).
+ *      2) args[1] - path to VM executable file
+ *
+ * 3. Creates arrays of arrays of environment variables.
+ *    Size of the array is args[0]
+ *    Each array's array size is form 1 to args[0]
+ *    Maximum size of environment variable/array element is from 1 to args[0] * 10 + 1.
+ *
+ * 4. Iterates through array of environemnt variables.
+ *
+ * 5. On each iteration invokes Runtime.exec(String[] cmd, String env) with command line to start 
+ *    VM along with a number of environment variables and EnvApp class and 1 parameter, which is
+ *    number of set environment variables. Typically, the command to execute looks like:
+ *   <vm> App <param (is equal to the number of passed environment variables)>
+ *
+ */
+
+
+public class ExecEnvTest extends Test {
+
+    static Random r = new Random(10);
+     
+    String vmPath = "";
+
+    String classPath = "";
+
+    String appName = "org.apache.harmony.test.reliability.api.kernel.args.EnvApp";
+
+    static String ENV_PREFIX = "env";
+
+    int N_OF_ITERATIONS = 10;
+
+    static int Multiplier = 10;
+
+    public static final int ERROR_NO_ARGS = 0xFFFF;
+
+
+    public static void main(String[] args) {
+        System.exit(new ExecEnvTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        boolean failed = false;
+    
+        parseParams(params);
+
+        // environment variables to start a process with
+
+        String[][] env = createEnvSets();
+
+        // parameters to pass to EnvApp on each iteration
+
+        String[][] appParams = createAppParamsSets(env);
+            
+        // for each set of environment variables:
+        String[] s = new String[2];
+
+        s[0] = "-classpath";
+        s[1] = classPath; 
+
+        for (int i = 0; i < env.length; ++i) {
+
+            String[] cmdLine = createCmdLine(vmPath, s, appName, appParams[i]);
+
+            // for (int x = 0; x < cmdLine.length; ++x) {
+            //       log.add(" " + cmdLine[x]);
+            // }
+            // log.add("");
+
+            // for (int x = 0; x < env[i].length; ++x) {
+            //       log.add(" " + env[i][x]);
+            // }
+            // log.add("");
+
+            try {
+
+                // start VM and EnvApp along with next environment variable set
+
+                Process p = Runtime.getRuntime().exec(cmdLine, env[i]);
+
+                p.waitFor();
+ 
+                if (p.exitValue() != 0 && p.exitValue() != env[i].length) {
+                    log.add("Started process returned unexpected exit code " + p.exitValue() +
+                        " instead of " + env[i].length); 
+                    failed = true;
+                }
+
+                // System.out.println("Exit value: " + p.exitValue());
+
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                log.add("Iteration: env index is " + i);
+                log.add("env variables number is "  + env[i].length + 
+                    "\n" + "maximum length of the last env string is " + 
+                    (getStringSize(env[i].length + 1) + 1) + " chars");
+                return fail("Failed");
+            }
+        }
+
+        if (failed) {
+            return fail("Failed");
+        }
+
+        return pass("OK");
+    }
+
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            N_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }        
+
+        if (params.length >= 2) {
+            vmPath = params[1];
+        }        
+        if (params.length >= 3) {
+            classPath =  params[2];
+        }        
+
+    }
+
+    String[] createCmdLine(String vmPath, String[] vmOptions, String appName, String[] appParams) {
+
+        String[] cmdLine = new String[1 + vmOptions.length +  1 + appParams.length];
+
+        // cmdLine should be: <vm> <vm option> <vm properties> App <param> .. <param>
+
+        cmdLine[0] = vmPath;
+        System.arraycopy(vmOptions, 0, cmdLine, 1, vmOptions.length);
+
+        cmdLine[vmOptions.length + 1] = appName;
+
+        System.arraycopy(appParams, 0, cmdLine, 1 + vmOptions.length + 1, appParams.length);
+
+        return removeEmptyStrings(cmdLine);
+
+    }
+
+
+    String[] removeEmptyStrings(String[] s){
+        int j = 0;
+        String[] ss = new String[s.length];
+
+        for (int i = 0; i < s.length; ++i){
+            if ("".equals(s[i])) {
+                continue;
+            }
+            ss[j++] = s[i];
+        }
+
+        String[] str = new String[j];
+
+        System.arraycopy(ss, 0, str, 0, str.length);
+
+        return str;
+    }
+
+
+    String[][] createEnvSets() {
+            
+        String[][] env = new String[N_OF_ITERATIONS][];
+
+        for (int i = 0; i < env.length; ++i) {
+
+            env[i] = createRndStrArray(i + 1);
+
+        }
+        // returned array is:
+        // {"env0=x"}
+        // {"env0=y", .. , "env2=v..v"};  v..v is 21 random chars
+        //  ..
+        // {"env0=z", .. , "env<N_OF_ITERATIONS>=w..w"}; w..w is (N_OF_ITERATIONS * 10 + 1) random chars 
+
+        return env;
+
+    }
+
+    String[][] createAppParamsSets(String[][] env) {
+        
+        String[][] appParams = new String[env.length][];
+
+        for (int i = 0; i < appParams.length; ++i) {
+
+            appParams[i] = new String[1];
+            appParams[i][0] = "" + env[i].length;
+
+        }
+
+        return appParams;
+    }
+
+    String[] createRndStrArray(int length) {
+
+        String[] s = new String[length];
+
+        for (int i = 0; i < s.length; ++i) {
+            s[i] = ENV_PREFIX + i + "=\"" + createRndStr(getStringSize(i) + 1) + "\"";
+        }
+        return s;
+    }
+
+
+    String createRndStr(int length) {
+
+        char[] ch = new char[length];
+
+        for (int i = 0; i < length; ++i) {
+                 
+            while (true) {
+
+                // looking for ASCII chars only:
+
+                char c = (char)((char) r.nextInt(90) + ((char) 33));
+                if (Character.isJavaIdentifierPart(c)) {
+                    ch[i] = c;
+                    break;
+                }
+            }
+
+        }
+
+        return new String(ch);
+    }
+
+
+    public static int getStringSize(int size) {
+        return size * Multiplier;
+    }
+}
+
+
+class EnvApp {
+
+    public static void main(String[] args) {
+
+        // first, check whether the parameter is passed into the EnvApp:
+        if (args.length == 0) {
+
+            System.exit(100);
+
+        }
+
+        // second, read the parameter which must be a number of passed environment variables:
+
+        int i = Integer.parseInt(args[0]);
+
+        for (int j = 0; j < i; ++j) {
+
+            //String env = System.getenv(ExecEnvTest.ENV_PREFIX + j);
+            String env = System.getProperty("-Dprop" + j);
+
+            // third, check that each of the environment variable is in place
+
+            if (env == null) {
+
+                System.exit(-1 * j);
+
+            }
+
+            // finally, variable's length is as expected
+
+            if (env.length() != (ExecEnvTest.getStringSize(j) + 3)) {
+
+                System.exit(-10 * env.length());
+
+            }
+
+        }
+
+        System.exit(i);
+
+    }
+
+}

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/VMCLPropertiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/VMCLPropertiesTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/VMCLPropertiesTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/args/VMCLPropertiesTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,325 @@
+/*
+ * 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 Oleg Oleinik
+ * @version $Revision: 1.4 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.args;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.Random;
+
+
+/**
+ * Goal: check that Runtime.exec() / VM process big number of big-size runtime properties (-D<property>)
+ * 
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ *      1) args[0] - number of iterations and maximum number of properties and muliplied by
+ *         'Multiplier' (typically 10) is a maximum size of property (number of chars).
+ *      2) args[1] - path to VM executable file
+ *      3) args[2] - VM options separated by 'VM_OPTS_SEPARATOR' (typically, ":").
+ *
+ * 2. Creates an array of VM options to iterate through.
+ *
+ * 3. Creates arrays of arrays of properties.
+ *    Size of the array is args[0]
+ *    Each array's size is form 1 to args[0]
+ *    Maximum size of property/array element is from 1 to args[0] * 10.
+ *
+ * 4. Iterates through VM options and for each VM option iterates through array of properties.
+ *
+ * 5. On each iteration invokes Runtime.exec() with command line to start VM with option, and properties
+ *   run App class and pass 1 parameter. Typically, the command to execute looks like:
+ *   <vm> <vm option> <-Dproperty>..<-Dproperty> App <param (is equal to the number of passed properties)>
+ *
+ */
+
+
+public class VMCLPropertiesTest extends Test {
+
+    static Random r = new Random(10);
+     
+    public static final int EXIT_VALUE = 0xFFFFF;
+
+    String vmPath = "";
+
+    String vmOpts = "";
+
+    String classPath = "";
+
+    String appName = "org.apache.harmony.test.reliability.api.kernel.args.AppProp";
+
+    int N_OF_ITERATIONS = 10;
+
+    int Multiplier = 10;
+
+    String VM_OPTS_SEPARATOR = ":";
+
+    public static String PROPERTY_LITERAL = "-D";
+
+    public static String PROPERTY_PREFIX = "prop";
+
+
+    public static int ERROR_NO_ARGS = -100000;
+
+    public static void main(String[] args) {
+        System.exit(new VMCLPropertiesTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        boolean failed = false;
+    
+        parseParams(params);
+
+        String[][] vmOptions = createVMOptsSets(vmOpts, classPath);
+
+        String[][] vmProperties = createVmPropertiesSets();
+
+        String[][] appParams = createAppParamsSets(vmProperties);
+            
+        for (int i = 0; i < vmOptions.length; ++i) {
+
+            for (int j = 0; j < vmProperties.length; ++j) {
+
+                String[] cmdLine = createCmdLine(vmPath, vmOptions[i], vmProperties[j], appName, appParams[j]);
+
+                // for (int x = 0; x < cmdLine.length; ++x) {
+                // log.add(cmdLine[x] + " ");
+                // }
+                // log.add("");
+
+                try {
+
+                    Process p = Runtime.getRuntime().exec(cmdLine);
+
+                    p.waitFor();
+                    int toRead = p.getInputStream().available();
+                    byte[] out = new byte[toRead];
+                    p.getInputStream().read(out, 0, toRead);
+                    // log.add(new String(out));
+                    toRead = p.getErrorStream().available();
+                    out = new byte[toRead];
+                    p.getErrorStream().read(out, 0, toRead);
+                    // log.add(new String(out));
+
+                    if (p.exitValue() != 0 && p.exitValue() != vmProperties[j].length) {
+                        log.add("Started process returned unexpected exit code (problem?) " + p.exitValue() +
+                            " instead of " + vmProperties[j].length); 
+                        failed = true;
+                    }
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    log.add("Iteration: vm args index is " + i + ", properties index is " + j);
+                    log.add("\n" + "VM argument: " + vmOptions[i][0] + "\n" +
+                        "VM properties number is "  + vmProperties[j].length + 
+                        "\n" + "maximum length of the last property string is " + 
+                        (getStringSize(vmProperties[j].length + 1) + 1) + " chars");
+                    return fail("Failed");
+                }
+            }
+        }
+
+        if (failed) {
+            return fail("Failed");
+        }
+
+        return pass("OK");
+    }
+
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            N_OF_ITERATIONS = Integer.parseInt(params[0]);
+        }        
+
+        if (params.length >= 2) {
+            vmPath = params[1];
+        }        
+
+        if (params.length >= 3) {
+            vmOpts =  params[2];
+        }        
+
+        if (params.length >= 4) {
+            classPath =  params[3];
+        }        
+
+    }
+
+
+    String[] createCmdLine(String vmPath, String[] vmOptions, String[] vmProperties, String appName, String[] appParams) {
+
+        String[] cmdLine = new String[1 + vmOptions.length + vmProperties.length + 1 + appParams.length];
+
+        // cmdLine should be: <vm> <vm option> <vm properties> App <param> .. <param>
+
+        cmdLine[0] = vmPath;
+        System.arraycopy(vmOptions, 0, cmdLine, 1, vmOptions.length);
+
+        System.arraycopy(vmProperties, 0, cmdLine, vmOptions.length + 1, vmProperties.length);
+
+        cmdLine[vmOptions.length + vmProperties.length + 1] = appName;
+
+        System.arraycopy(appParams, 0, cmdLine, 1 + vmOptions.length + vmProperties.length + 1, appParams.length);
+
+        return removeEmptyStrings(cmdLine);
+
+    }
+
+    String[] removeEmptyStrings(String[] s){
+        int j = 0;
+        String[] ss = new String[s.length];
+
+        for (int i = 0; i < s.length; ++i){
+            if ("".equals(s[i])) {
+                continue;
+            }
+            ss[j++] = s[i];
+        }
+
+        String[] str = new String[j];
+
+        System.arraycopy(ss, 0, str, 0, str.length);
+
+        return str;
+    }
+
+    String[][] createAppParamsSets(String[][] vmProperties) {
+        
+        String[][] appParams = new String[vmProperties.length][];
+
+        for (int i = 0; i < appParams.length; ++i) {
+
+            appParams[i] = new String[1];
+            appParams[i][0] = "" + vmProperties[i].length;
+
+        }
+
+        return appParams;
+    }
+
+    String[][] createVmPropertiesSets() {
+        
+        String[][] vmProps = new String[N_OF_ITERATIONS][];
+
+        for (int i = 0; i < vmProps.length; ++i) {
+
+            vmProps[i] = createRndStrArray(i + 1);
+
+        }
+
+        return vmProps;
+    }
+
+
+    String[] createRndStrArray(int length) {
+
+        String[] s = new String[length];
+
+        for (int i = 0; i < s.length; ++i) {
+            s[i] = PROPERTY_LITERAL + PROPERTY_PREFIX + i + "=\"" + createRndStr(getStringSize(i) + 1) + "\"";
+        }
+        return s;
+    }
+
+
+    String createRndStr(int length) {
+
+        char[] ch = new char[length];
+
+        for (int i = 0; i < length; ++i) {
+                 
+            while (true) {
+                char c = (char) r.nextInt(0xffff);
+                if (Character.isJavaIdentifierPart(c)) {
+                    ch[i] = c;
+                    break;
+                }
+            }
+
+        }
+
+        return new String(ch);
+    }
+
+
+    String[][] createVMOptsSets(String vmOpts, String classPath) {
+
+        // we do not create cobination of several vm options, just, one option at each run
+        // first, extract options from input parameter:
+
+        String[] vmopts = vmOpts.split(VM_OPTS_SEPARATOR);
+
+        String[][] s = new String[vmopts.length][];
+
+        for (int i = 0; i < s.length; ++i){
+            s[i] = new String[3];
+            s[i][0] = "-classpath";
+            s[i][1] = classPath; 
+            s[i][2] = vmopts[i];
+        }
+
+        return s;
+    }
+
+
+    int getStringSize(int size) {
+        return size * Multiplier;
+    }
+
+}
+
+class AppProp {
+
+    public static void main(String[] args) {
+
+        if (args.length == 0) {
+
+            System.exit(100);
+
+        }
+
+        int i = Integer.parseInt(args[0]);
+
+        for (int j = 0; j < i; ++j) {
+
+            // System.out.println(System.getProperty(VMCLPropertiesTest.PROPERTY_PREFIX + j));
+
+            if (System.getProperty("-Dprop" + j) == null) {
+
+                System.exit(-1 * j);
+
+            }
+
+        }
+
+        System.exit(i);
+
+    }
+
+}
+
+

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ExecApplication.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ExecApplication.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ExecApplication.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ExecApplication.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,305 @@
+/*
+ * 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 V. Bannikov
+ * @version $Revision: 1.2 $
+ */
+package org.apache.harmony.test.reliability.api.kernel.exec;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
+class ExecApplication extends Thread {
+
+    private static int id = 10;
+
+    private String firstarg = "StartaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaEND";
+
+    private static String secondarg = "10";
+
+    private static String[] appname = { "org.apache.harmony.test.reliability.api.kernel.exec.ShutdownHookApp" };
+
+    public static String classrootdir = "";
+
+    public static String testedruntime = "java";
+
+    private final static String filein = "inputstreamfile";
+
+    private final static String fileerr = "errorstreamfile";
+
+    private final static String currthread = "Current Thread : Thread-";
+
+    String separator = File.separator;
+
+    public Process process = null;
+
+    public ExecApplication(String appname) {
+        Runtime runtime = Runtime.getRuntime();
+        String twoarg = firstarg + " " + secondarg;
+        String str = cmdArg(appname, twoarg);
+        try {
+            process = runtime.exec(str);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        start();
+    }
+
+    public static int getCnt() {
+        return id;
+    }
+
+    public static void setId(int newid) {
+        id = newid;
+    }
+
+    public static void setSecondarg(String arg) {
+        secondarg = arg;
+    }
+
+    public String getFirstArg() {
+        return firstarg;
+    }
+
+    public String getSecondArg() {
+        return secondarg;
+    }
+
+    public static String getAppName(int i) {
+        return appname[i];
+    }
+
+    public static String fileNameforIn() {
+        return filein;
+    }
+
+    public static String fileNameforErr() {
+        return fileerr;
+    }
+
+    public static String currThreadStr() {
+        return currthread;
+    }
+
+    public void processDestroy() {
+        this.process.destroy();
+    }
+
+    public String cmdArg(String appname, String arg) {
+        String str = testedruntime + " " + "-cp" + " " + classrootdir + " " + appname + " " + arg;
+
+        return str;
+    }
+
+    public int processWaitFor(Process process) {
+        int exitvalue = 0;
+        try {
+            exitvalue = process.waitFor();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        return exitvalue;
+    }
+
+    public InputStream processInputStream(Process process) {
+        InputStream inputstream = process.getInputStream();
+        return inputstream;
+    }
+
+    public InputStream processErrorStream(Process process) {
+        InputStream errorstream = process.getErrorStream();
+        return errorstream;
+    }
+    
+    public OutputStream processOutputStream(Process process) {
+        OutputStream outputstream = process.getOutputStream();
+        return outputstream;
+    }
+
+    public void readInputStream(InputStream in, String filename) {
+        String line;
+        BufferedReader bufReader = new BufferedReader(new InputStreamReader(in));
+        PrintWriter prnWriter = null;
+
+        try {
+            prnWriter = new PrintWriter(new BufferedWriter(new FileWriter(
+                filename)));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        try {
+            while ((line = bufReader.readLine()) != null) {
+                prnWriter.println(line);
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                prnWriter.close();
+                bufReader.close();
+                in.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public void writeToFileInputStream(String filename, Process process) {
+        InputStream in = processInputStream(process);
+        readInputStream(in, filename);
+    }
+
+    public void writeToFileErrorStream(String filename, Process process) {
+        InputStream error = processErrorStream(process);
+        readInputStream(error, filename);
+    }
+
+    public String readLineFromFile(String filename, int linenumber) {
+        String str = new String();
+        BufferedReader bufReader = null;
+
+        try {
+            bufReader = new BufferedReader(new FileReader(filename));
+            for (int i = 0; i < linenumber; i++) {
+                str = bufReader.readLine();
+                if (str == null) {
+                    // System.out.println("end of the stream has been reached ");
+                    return str;
+                }
+            }
+        } catch (FileNotFoundException e) {
+            System.out.println("Read the content of the file" + filename + ". The file does not exist");
+            e.printStackTrace();
+        } catch (IOException ee) {
+            System.out.println("Read a line of text: I/O error occurs");
+            ee.printStackTrace();
+        } finally {
+            try {
+                bufReader.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return str;
+
+    }
+
+    public boolean checkLine(String line1, String line2) {
+        return line1.equals(line2);
+    }
+
+    public boolean checkSomeLine(String filename, String chekedline, int cntline) {
+        int strcounter = 0;
+        String line;
+        boolean result = false;
+        while (readLineFromFile(filename, strcounter++) != null) {
+            line = readLineFromFile(filename, strcounter);
+            if (line != null) {
+                if (checkLine(line, chekedline)) {
+                    return result = true;
+                }
+            }
+        }
+        if (!result) {
+            System.out.println("Line is not found in the file " + filename
+                + ". Number of lines = " + strcounter);
+        }
+        strcounter = strcounter - 2;
+        if (strcounter != cntline) {
+            System.out.println("Invalid number of lines in the file "
+                + filename + ". Number of lines = " + strcounter);
+            result = false;
+        }
+        return result;
+    }
+
+    public boolean checkSomeLine(String filename, String linestartswith,
+        String lineendswith, int cntline) {
+        int strcounter = 0;
+        String line;
+        boolean result = false;
+        while (readLineFromFile(filename, strcounter++) != null) {
+            line = readLineFromFile(filename, strcounter);
+            if (line != null) {
+                for (int i = 0; i <= cntline; i++) {
+                    if (checkLine(line, linestartswith, lineendswith)) {
+                        result = true;
+                        break;
+                    }
+                }
+
+            }
+        }
+        if (!result) {
+            System.out.println("Invalid number of lines in the file "
+                + filename + ". Number of lines = " + strcounter);
+        }
+        return result;
+    }
+
+    public boolean checkLine(String line, String startwith, String endwith) {
+        boolean result = false;
+        if (line.startsWith(startwith) && line.endsWith(endwith)) {
+            result = true;
+        }
+        return result;
+    }
+
+    public static boolean deleteFiles(String directory, String filename) {
+        boolean result = true;
+        File dir = new File(directory);
+        File[] listFiles = dir.listFiles();
+        String fln;
+        for (int i = 0; i < listFiles.length; i++) {
+            fln = listFiles[i].getName();
+            if (fln.equals(filename)) {
+                if (!listFiles[i].delete()) {
+                    System.out.println("delete " + fln + " : failed");
+                    return false;
+                }
+
+            }
+        }
+        return result;
+    }
+
+    int exitvalue = 0;
+
+    public void run() {
+        if (process != null) {
+            exitvalue = processWaitFor(process);
+            if (exitvalue != 104) {
+                System.out.println("the exit value = " + exitvalue
+                    + " The exit value of the process should be 104.");
+            }
+        }
+    }
+}
+

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/RunExec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/RunExec.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/RunExec.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/RunExec.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,163 @@
+/*
+ * 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 V. Bannikov
+ * @version $Revision: 1.3 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.exec;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.io.File;
+
+/**
+ * 
+ *    Idea: The test checks VM initialization and shutdown correctness, also, 
+ *  Runtime.exec() and other System methods are checked. 
+ *  Details: new java is started in the loop using exec(). 
+ *  It loads some short multi-threaded application, where each thread outputs 
+ *  large string output steam. Application also sets shutdown hooks.
+ *  When application is completed, it is checked that shutdown hooks 
+ *  were executed and all input/output streams received correct data.
+ *
+ */
+
+public class RunExec extends Test {
+
+    int cnt = ExecApplication.getCnt();
+    String ins = ExecApplication.fileNameforIn();
+    String err = ExecApplication.fileNameforErr();
+    String ins_i;
+    String err_i;
+    String line;
+    int secarg = 0;
+    int strcounter;
+
+    public int test(String params[]) {
+        String userdir = System.getProperty("java.io.tmpdir") + File.separator + "reliability_exec";
+        File temp = new File(userdir);
+        temp.mkdir();
+
+        if (params.length >= 1) {
+            ExecApplication.setId(Integer.parseInt(params[0]));
+        }        
+
+        if (params.length >= 2) {
+            ExecApplication.setSecondarg(params[1]);
+        }        
+
+        if (params.length >= 3) {
+            ExecApplication.classrootdir = params[2];
+        }        
+
+        if (params.length >= 4) {
+            ExecApplication.testedruntime = params[3];
+        }        
+
+        String longstr = ShutdownHookApp.getLongString();
+
+        for (int i = 0; i < cnt; i++) {
+            ExecApplication ex = new ExecApplication(ExecApplication.getAppName(0));
+            secarg = Integer.parseInt(ex.getSecondArg());
+            ins_i = userdir + File.separator + ins + i;
+            err_i = userdir + File.separator + err + i;
+
+            ex.writeToFileInputStream(ins_i, ex.process);
+            ex.writeToFileErrorStream(err_i, ex.process);
+            if (!ex.checkSomeLine(err_i, ex.getFirstArg(), secarg)) {            
+
+                return fail("Check line from file " + err_i
+                    + " : failed");
+            }
+
+            if (!ex.checkSomeLine(ins_i, longstr, secarg)) {
+                return fail("Check line from file " + ins_i
+                    + " : failed");
+            }
+
+            for (int j = 1; j < secarg; j++) {
+                if (!ex.checkSomeLine(ins_i, ExecApplication.currThreadStr(), Integer
+                    .toString(j), secarg)) {
+                    return fail("Check line from file " + ins_i
+                        + " : failed");
+                }
+            }
+        }
+
+        //log.add("userdir = " + userdir);
+
+        String deletedfile;
+
+        for (int j = 0; j < cnt; j++) {
+            deletedfile = ins + j;
+            if (!ExecApplication.deleteFiles(userdir, deletedfile)) {
+                return fail("Can't delete file: " + deletedfile);
+            }
+            deletedfile = err + j;
+            if (!ExecApplication.deleteFiles(userdir, deletedfile)) {
+                return fail("Can't delete file: " + deletedfile);
+            }
+        }
+
+        for (int i = 0; i < cnt; i++) {
+            ExecApplication ex = new ExecApplication(ExecApplication.getAppName(0));
+            secarg = Integer.parseInt(ex.getSecondArg());
+            ins_i =  userdir + File.separator + ins + i;
+            err_i =  userdir + File.separator + err + i;
+            ex.writeToFileInputStream(ins_i, ex.process);
+            ex.writeToFileErrorStream(err_i, ex.process);
+            ex.processDestroy();
+            if (!ex.checkSomeLine(err_i, ex.getFirstArg(), secarg)) {
+                return fail("Check line from file " + err_i
+                    + " : failed");
+
+            }
+
+            if (!ex.checkSomeLine(ins_i, longstr, secarg)) {
+                return fail("Check line from file " + ins_i
+                    + " : failed");
+            }
+
+            for (int j = 1; j < secarg; j++) {
+                if (!ex.checkSomeLine(ins_i, ExecApplication.currThreadStr(), Integer
+                    .toString(j), secarg)) {
+                    return fail("Check line from file " + ins_i
+                        + " : failed");
+                }
+            }
+        }
+
+        for (int j = 0; j < cnt; j++) {
+            deletedfile = ins + j;
+            if (!ExecApplication.deleteFiles(userdir, deletedfile)) {
+                return fail("Can't delete file: " + deletedfile);
+            }
+            deletedfile = err + j;
+            if (!ExecApplication.deleteFiles(userdir, deletedfile)) {
+                return fail("Can't delete file: " + deletedfile);
+            }
+        }
+
+        return pass("OK");
+    }
+
+    public static void main(String args[]) {
+        System.exit(new RunExec().test(args));
+    }
+}

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ShutdownHookApp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ShutdownHookApp.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ShutdownHookApp.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/exec/ShutdownHookApp.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,119 @@
+/*
+ * 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 V. Bannikov
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.exec;
+
+public class ShutdownHookApp {
+
+    private static int CNT = 10;
+
+    final static int sleep = 10;
+
+    private String argument = "";
+
+    private final static String longstring = "STARTssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "ssssssssssssssssssssssssssssssssssssssssssssssssssssss"
+        + "sssssssssssssssssssssssssssssssssssssssssssssssssssEND";
+
+    public static String getLongString() {
+        return longstring;
+    }
+
+    public static void systemExit() {
+        Runtime.getRuntime().exit(100);
+    }
+
+    void ShutdownHookApp() {
+        Thread thread = (Thread) new ThreadShutdownHookApp();
+        Runtime runtime = Runtime.getRuntime();
+        runtime.addShutdownHook(thread);
+        return;
+    }
+
+    void prnLongString() {
+        System.out.println(longstring);
+    }
+
+    void prnError() {
+        System.err.println(argument);
+    }
+
+    void prnCurrentThread() {
+        System.out.println("Current Thread : "
+            + Thread.currentThread().getName());
+    }
+
+    class ThreadShutdownHookApp extends Thread {
+        ThreadShutdownHookApp() {
+            super();
+        }
+
+        public void run() {
+            prnLongString();
+            prnError();
+            prnCurrentThread();
+        }
+    }
+
+    public int test(String args[]) {
+        if (args.length > 0) {
+            argument = args[0];
+        }
+        if (args.length > 1) {
+            CNT = Integer.parseInt(args[1]);
+        }
+
+        for (int i = 0; i < CNT; i++) {
+            try {
+                ShutdownHookApp();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            try {
+                Thread.currentThread().sleep(sleep);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+        }
+
+        return 104;
+    }
+
+    public static void main(String args[]) {
+        System.exit(new ShutdownHookApp().test(args));
+    }
+}
+

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmPropertiesHooksTest.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/AddRmPropertiesHooksTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmPropertiesHooksTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmPropertiesHooksTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,429 @@
+/*
+ * 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 Oleg Oleinik
+ * @version $Revision: 1.1 $
+ */
+
+package org.apache.harmony.test.reliability.api.kernel.hooks;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.Properties;
+
+/**
+ * Goal: test and find incorrectness in add/set/remove operations with shutdown 
+ *       hooks and properties.
+ *
+ * The test does:
+ *
+ *     1. Reads parameters:
+ *         param[0] - number of properties to play with
+ *         param[1] - number of hooks to play with
+ *
+ *     2. Plays with properties:
+ *        a. Adds param[0] properties via setProperty(), checks the properties are set
+ *           removes properties.
+ *        b. Adds param[0] properties via setProperties(), checks the properties are set,
+ *           removes properties.
+ *
+ *     3. Plays with hooks:
+ *        a. Creates, adds, removes param[1] hooks which are non-started Threads.
+ *        b. Creates, adds, removes param[1] hooks which are finished Threads.
+ *        c. Creates, adds, removes param[1] hooks which are being running Threads.
+ */
+
+public class AddRmPropertiesHooksTest extends Test {
+
+        int N_OF_PROPERTIES = 1000;
+
+        int N_OF_HOOKS = 200;
+
+	public static void main(String[] args) {
+            System.exit(new AddRmPropertiesHooksTest().test(args));
+	}
+
+
+        public int test(String[] args) {
+
+            boolean prop_status = true;
+            boolean hooks_status = true;
+
+            parseParams(args);
+
+            prop_status = playWithProperties();
+
+            hooks_status = playWithShutdownHooks();
+
+            if (prop_status != true || hooks_status != true) {
+                return fail("Failed");
+            }
+            
+            return pass("OK");
+	}
+
+        boolean playWithShutdownHooks() {
+
+            boolean passed = true;
+
+            Thread[] hooks = createNormalHooks();
+
+            passed = addNormalHooks(hooks);
+
+            removeNormalHooks(hooks);
+
+            addRemoveExecutedHooks(createExecutedHooks());
+
+            passed = passed & addRemoveBeingRunningHooks();
+
+            return passed;
+        }
+
+        boolean addRemoveBeingRunningHooks() {
+
+            boolean passed = true;
+
+            Thread[] t = createRunningThreads();
+
+            for (int i = 0; i < t.length; ++i) {
+
+                try {
+
+                    Runtime.getRuntime().addShutdownHook(t[i]);
+                    passed = false;
+
+                    // looks like hook was unexpectedly added, lets remove added hook
+
+                    Runtime.getRuntime().removeShutdownHook(t[i]); 
+
+                } catch (IllegalArgumentException iae){
+                }
+            }
+
+            waitForRunningThreads(t);
+
+            if (!passed){
+                log.add("addShutdownHook(running thread) does not throw IllegalArgumentException");
+            }
+            return passed;
+        }
+
+
+        Thread[] createRunningThreads() {
+
+            RunningThread[] t = new RunningThread[N_OF_HOOKS];
+
+            for (int i = 0; i < t.length; ++i) {
+
+                t[i] = new RunningThread();
+                t[i].start();
+
+                while (!t[i].started) {
+                    Thread.yield();
+                }
+            }
+            return t;
+        }
+
+
+        void waitForRunningThreads(Thread[] t){
+
+            for (int i = 0; i < t.length; ++i){
+
+                synchronized (((RunningThread)t[i]).obj) {
+
+                    ((RunningThread)t[i]).may_wakeup = true;
+
+                    ((RunningThread)t[i]).obj.notify();
+
+                }
+
+                while(!((RunningThread)t[i]).ended){
+
+                    Thread.yield();
+
+                }
+
+                try {
+                    t[i].join();
+                } catch (InterruptedException ie){
+                }
+
+            }
+        }
+
+        
+        Thread[] createExecutedHooks() {
+
+            Thread[] hooks = new Thread[N_OF_HOOKS];
+
+            for (int i = 0; i < hooks.length; ++i){
+                Thread t = new NormalHook();
+                t.start();
+                Thread.yield();
+                try {
+                    t.join();
+                } catch (InterruptedException ie){
+                }
+                hooks[i] = t;
+            }
+
+            return hooks;
+        }
+
+        void addRemoveExecutedHooks(Thread[] hooks) {
+            for (int i = 0; i < hooks.length; ++i) {
+                boolean remShHook = true;
+                try{
+                    Runtime.getRuntime().addShutdownHook(hooks[i]);
+                } catch (IllegalArgumentException iae){
+                	remShHook = false;
+                }
+                if (remShHook){
+                    Runtime.getRuntime().removeShutdownHook(hooks[i]);
+                }
+            }
+        }
+
+        Thread[] createNormalHooks() {
+
+            Thread[] hooks = new Thread[N_OF_HOOKS];
+
+            for (int i = 0; i < hooks.length; ++i){
+                hooks[i] = new NormalHook();
+            }
+
+            return hooks;
+        }
+
+        boolean addNormalHooks(Thread[] hooks) {
+            boolean passed = true;
+            for (int i = 0; i < hooks.length; ++i) {
+                Runtime.getRuntime().addShutdownHook(hooks[i]);
+                try {
+                    Runtime.getRuntime().addShutdownHook(hooks[i]);
+                    log.add("No IllegalArgumentException in addShutdownHook is the same hook is added twice");
+                    passed = false;
+                } catch (IllegalArgumentException iae){
+                }
+            }
+            return passed;
+        }
+
+        void removeNormalHooks(Thread[] hooks){
+
+            for (int i = 0; i < hooks.length; ++i) {
+
+                Runtime.getRuntime().removeShutdownHook(hooks[i]);
+
+                // intentionslly remove the same hook, should be no surprises
+
+                Runtime.getRuntime().removeShutdownHook(hooks[i]);
+            }
+        }
+
+        boolean playWithProperties() {
+
+            boolean passed = true;
+
+            addProperty();
+
+            if (!checkProperty()) {
+                passed = false;
+            }
+
+            removeProperty();
+
+            if (!checkPropertyRemoved()) {
+                passed = false;
+            }
+
+            addProperties();
+
+            if (!checkProperties()) {
+                passed = false;
+            }
+
+            removeProperties();
+
+            if (!checkPropertiesRemoved()) {
+                passed = false;
+            }
+
+            return passed;
+        }
+
+
+
+        public void addProperty(){
+
+            for (int i = 0; i < N_OF_PROPERTIES; ++i) {
+                System.setProperty("" + i, "" + i);
+                System.setProperty("" + i, "" + i);
+            }
+        }
+
+        boolean checkProperty() {
+
+             boolean passed = true;
+
+             for (int i = 0; i < N_OF_PROPERTIES; ++i){
+
+                 if (!("" + i).equals(System.getProperty("" + i))){
+                      log.add("System.getProperty(\"" + i + "\") returns: " + System.getProperty("" + i) + 
+                              " while expected \"" + i + "\"");
+                      passed = false;
+                 }
+             }
+
+             return passed;
+        }
+
+        public void removeProperty(){
+
+            for (int i = 0; i < N_OF_PROPERTIES; ++i) {
+
+                System.clearProperty("" + i);
+            }
+        }
+
+
+        boolean checkPropertyRemoved() {
+        
+             boolean passed = true;
+
+             for (int i = 0; i < N_OF_PROPERTIES; ++i){
+
+                 if (System.getProperty("" + i) != null){
+                      log.add("System.getProperty(\"" + i + "\") returns: " + System.getProperty("" + i) + 
+                              " while expected null (no such property), property removal failed?");
+                      passed = false;
+                 }
+             }
+
+             return passed;
+
+        }
+
+
+        public void addProperties(){
+
+            Properties p = new Properties();
+
+            for (int i = 0; i < N_OF_PROPERTIES; ++i) {
+
+                p.setProperty("" + i + "_" + i, "" + i + "_" + i);
+
+            }
+
+            System.setProperties(p);
+        }
+
+
+        boolean checkProperties() {
+
+             boolean passed = true;
+
+             for (int i = 0; i < N_OF_PROPERTIES; ++i){
+
+                 if (!("" + i + "_" + i).equals(System.getProperty("" + i + "_" + i))){
+                      log.add("System.getProperty(\"" + i + "_" + i + "\") returns: " + System.getProperty("" + i + "_" + i) + 
+                              " while expected \"" + i + "_" + i + "\"");
+                      passed = false;
+                 }
+             }
+
+             return passed;
+        }
+
+
+        public void removeProperties(){
+
+                System.setProperties(null);
+
+        }
+
+
+        boolean checkPropertiesRemoved() {
+
+             boolean passed = true;
+
+             for (int i = 0; i < N_OF_PROPERTIES; ++i){
+
+                 if (System.getProperty("" + i + "_" + i) != null){
+                      log.add("System.getProperty(\"" + i + "_" + i + "\") returns: " + System.getProperty("" + i + "_" + i) + 
+                              " while expected null, properties removal failed?");
+                      passed = false;
+                 }
+             }
+
+             return passed;
+        }
+
+
+        public void parseParams(String[] params) {
+
+		if (params.length >= 1) {
+		    N_OF_PROPERTIES = Integer.parseInt(params[0]);
+		}		
+
+		if (params.length >= 2) {
+		    N_OF_HOOKS = Integer.parseInt(params[1]);
+		}		
+        }
+}
+
+
+class NormalHook extends Thread {
+    public void run() {
+        return;
+    }
+}
+
+
+class RunningThread extends Thread {
+
+    volatile boolean started = false;
+    volatile boolean ended = false;
+    volatile boolean may_wakeup = false;
+    Object obj = new Object();
+
+    public void run() {
+
+        synchronized (obj) {
+
+            while (!may_wakeup) {
+
+                try {
+
+                    started = true;
+                    obj.wait();
+
+                } catch (InterruptedException ie){
+                }
+
+            }
+        }
+
+        ended = true;
+    }
+}
+
+
+
+
+

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

Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmShtdwnHooksTest.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/AddRmShtdwnHooksTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmShtdwnHooksTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/kernel/hooks/AddRmShtdwnHooksTest.java Fri Jun  8 09:34:52 2007
@@ -0,0 +1,579 @@
+/*
+ * 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;
+import java.util.Random;
+
+ /**
+  * Goal: checking that runtime works correctly with shutdown hooks in case of different 
+  *        application completion cases, such as via System.exit(), Runtime.halt() or in
+  *       case of just normal completion.
+  * 
+  *      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. Runs 5 cases/classes, starting each case/class via 
+  *         Runtime.exec(<vm> -classpath <classes dir> <className> <number of hooks>)
+  * 
+  *         The cases / classes (<className>) are:
+  *
+  *          * AppNormalCompletion - adds hooks and exits silently (not by System.exit() 
+  *            or Runtime.halt()), it is checked that all hooks started/completed.
+  *
+  *          * AppSysExitCompletion - adds hooks and exits by System.exit(), it is checked
+  *            that all hooks started/completed.
+  *  
+  *          * AppDestroyedProcess - adds hooks and hangs in object.wait() for the main
+  *            class to destroy it via Process.destroy(), it is checked that no unexpected results.
+  *
+  *          * AppHalted - adds hooks and exits by Runtime.halt(), it is checked that no
+  *            no hooks started/completed.
+  *
+  *          * AppNormalCompletionFinishedHooks - adds hooks which are already completed/executed
+  *            threads, it is checked that hooks started/completed and no unexpected results.
+  *
+  *      3. The main class reads output of started processes, analyzes the output and exit value.
+  */
+
+public class AddRmShtdwnHooksTest extends Test {
+
+    int N_OF_HOOKS = 200;
+
+    String classpathDir = ".";
+
+    String vmPath = "";
+
+    static final String CLASSPATH_OPT = "-classpath";
+
+    static final String STARTED = " ";
+
+    static int EXIT_CODE = 33;
+
+    static int HALT_CODE = 44;
+
+    static final int NORMAL = 0;
+
+    static final int DESTROY = 1;
+
+    static final int SYS_EXIT = 2;
+
+    static final int HALT = 3;
+
+    static final int SLEEP_TIMEOUT = 200;
+
+    // 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.";
+
+
+    static final String normalCompletionClass = package_name + "AppNormalCompletion";
+    static final String sysExitCompletionClass = package_name + "AppSysExitCompletion";
+    static final String destroyedProcessClass = package_name + "AppDestroyedProcess";
+    static final String haltCompletionClass = package_name + "AppHalted";
+    static final String normalCompletionExecutedHooksClass = package_name + "AppNormalCompletionFinishedHooks";
+
+
+
+    public static void main(String[] args) {
+        System.exit(new AddRmShtdwnHooksTest().test(args));
+    }
+
+
+    public int test(String[] params) {
+
+        parseParams(params);
+
+        boolean passed = true; 
+        boolean status = false;
+
+        status = runApp(normalCompletionClass, N_OF_HOOKS, NORMAL);
+        passed = passed & status;
+        // log.add("Normally completed application (no System.exit() or halt, etc.). Test passed?: " + status + "\n");
+
+        status = runApp(sysExitCompletionClass, N_OF_HOOKS, SYS_EXIT);
+        passed = passed & status;
+        // log.add("Application exited via System.exit(). Test passed?: " + status + "\n");
+
+        //            status = runApp(destroyedProcessClass, N_OF_HOOKS, DESTROY);
+        //            passed = passed & status;
+        //            log.add("Application was destroyed. Test passed?: " + status + "\n");
+
+        status = runApp(haltCompletionClass, N_OF_HOOKS, HALT);
+        passed = passed & status;
+        // log.add("Application exited via Runtime.halt(). Test passed?: " + status + "\n");
+
+        status = runApp(normalCompletionExecutedHooksClass, N_OF_HOOKS, NORMAL);
+        passed = passed & status;
+        // log.add("Normally completed application, which registered already executed (finished)" +
+        //        " threads/hooks. Test passed?: " + status + "\n");
+
+        if (!passed) {
+            return fail("Failed");
+        }
+
+        return pass("OK");
+    }
+
+
+    boolean runApp(String className, int n_of_hooks, int mode) {
+
+        // command line is:
+        // <vmPath> -classpath <classes dir> <className> <n_of_hooks>
+
+        String[] cmd = createCmdLine(className, n_of_hooks);
+
+        // log.add("Running: " + cmd[0] + " " + cmd[1] + " " + cmd[2] + " " + cmd[3] + " " + cmd[4]);
+
+        boolean passed = true;
+
+        InputStream is = null;
+
+        try {
+
+            Process p = Runtime.getRuntime().exec(cmd);
+
+            is = p.getInputStream();
+
+            if (mode == DESTROY) {
+
+                // wait for the process's printed byte as signal 
+                // that it is ready to be destroyed:
+
+                byte b = (byte)is.read();
+
+                try {
+                    Thread.sleep(SLEEP_TIMEOUT);
+                } catch (InterruptedException ie){
+                }
+
+                p.destroy();
+
+            }
+ 
+            // Lets check that if application exited not via Runtime.halt(), then,
+            // all hooks started, each hook printed some string as a signal that the hook
+            // worked:
+ 
+            if (mode == NORMAL || mode == SYS_EXIT) {
+                
+                passed = checkAllHooksStarted(getProcessOutput(is, n_of_hooks), Hook.separator, n_of_hooks);
+
+            }
+
+            // If application exited via Runtime.halt(), then, check that no hooks started,
+            // despite of hooks were added before halt() - i.e. application printed nothing into stdout:
+
+            if (mode == HALT) {
+
+                passed = checkNoHooksStarted(is);
+
+            }
+
+            p.waitFor();
+
+            // Lets check exit codes. They should be as expected - either 0, or 1 (in case of process
+            // destroying) or EXIT_CODE or HALT_CODE.
+
+            int ev = p.exitValue();
+
+            if (mode == NORMAL && ev != 0) {
+                log.add("Process with registered hooks (created but not executed or already finished)" +
+                    " and completed normally returned status " + ev + " instead of expected 0");
+                passed = false;
+            }
+
+            if (mode == DESTROY && (ev != 0 && ev != 1)) {
+                log.add("Process with registered hooks and destroyed" +
+                    " returned status " + ev + " instead of expected 0 or 1");
+                passed = false;
+            }
+
+            if (mode == SYS_EXIT && ev != EXIT_CODE) {
+                log.add("Process with registered hooks and exited via System.exit() returned status " + 
+                    ev + " instead of expected " + EXIT_CODE);
+                passed = false;
+            }
+
+            if (mode == HALT && ev != HALT_CODE) {
+                log.add("Process with registered hooks and exited via Runtime.halt(<status>) returned " + 
+                    "status " + ev + " instead of expected " + HALT_CODE);
+                passed = false;
+            }
+        
+        } catch (Exception e){
+            e.printStackTrace();
+            log.add("Unexpected exception while exec() or postprocessing of output of " + 
+                "application registered with normal hooks");
+            passed = false;
+
+        }
+
+        return passed;
+    }
+
+
+    boolean checkNoHooksStarted(InputStream is){
+
+        ProcessOutputReader t = new ProcessOutputReader(is);
+
+        // Start thread which listens process's output:
+
+        t.start();
+
+        // Wait for the thread actually started reading process's output:
+
+        while (!t.started) {
+            Thread.yield();
+        }
+
+        // Wait either for:
+        // * the reader thread read some bytes and completed
+        // * read() returned -1 indicating EOF and reader thread completed
+        // * reader thread hung in read(), we called yield() 1000 times and 
+        //   finally interrupted the reader thread.
+
+        int i = 0;
+
+        while (!t.finished) {
+
+            Thread.yield();
+
+            if (++i == 1000) {
+                t.interrupt();
+            }
+        }
+
+        try {
+            t.join();
+        } catch (InterruptedException ie) {
+        }
+
+        // If reader thread read something from process's stdout, then, looks like 
+        // hooks started and printed something into stdout - this is not what is expected, 
+        // since halt() does not cause running hooks.
+
+        if (t.read_bytes > 0) {
+            log.add("Process did halt and looks like started hooks - something was printed into System.out");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    String getProcessOutput(InputStream is, int n_of_hooks){
+        int read_byte = 0;
+        int i = 0;
+
+        // Allocate large array to fill in with process output
+
+        byte[] b = new byte[n_of_hooks * (Hook.separator.length() + 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 "";
+        }
+
+        byte[] bb = new byte[i];
+        System.arraycopy(b, 0, bb, 0, bb.length);
+
+        // Convert bytes into String using default encoding:
+
+        return new String(bb);
+    }
+
+
+    boolean checkAllHooksStarted(String process_output, String separator, int n_of_hooks){
+
+        // log.add("Process output: " + process_output);
+
+        boolean passed = true;
+
+        String[] hook_names = process_output.split(separator);
+
+        if (hook_names.length != n_of_hooks){
+            log.add(hook_names.length + " thread's output found instead of " + n_of_hooks);
+            passed = false;
+        }
+
+        byte[] found = new byte[n_of_hooks];
+
+        for (int j = 0; j < hook_names.length; ++j){
+            int hook_number = Integer.parseInt(hook_names[j]);
+            found[hook_number]++;
+        }
+
+        for (int i = 0; i < found.length; ++i){
+            if (found[i] > 1){
+                log.add("Thread/hook " + i + " was executed " + found[i] + " times instead of 1");
+                passed = false;
+            }
+
+            if (found[i] < 1){
+                log.add("Thread/hook " + i + " was not executed - no output from the hook");
+                passed = false;
+            }
+        }
+
+        return passed;
+    }
+
+    public void parseParams(String[] params) {
+
+        if (params.length >= 1) {
+            vmPath = params[0];
+        }
+
+        if (params.length >= 2) {
+            classpathDir = params[1];
+        }
+    }
+
+
+    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;
+    }
+
+}
+
+
+    // The class adds hooks and completes normally (not via System.exit() or Runtime.halt()).
+
+class AppNormalCompletion {
+
+    public static void main(String[] args){
+
+        Thread[] hooks = createHookThreads(Integer.parseInt(args[0]));
+
+        for (int i = 0; i < hooks.length; ++ i){
+            Runtime.getRuntime().addShutdownHook(hooks[i]);
+        }
+
+    }
+
+    static Thread[] createHookThreads(int n_of_hooks_to_start) {
+
+        Thread[] t = new Thread[n_of_hooks_to_start];
+
+        for (int i = 0; i < t.length; ++i){
+            t[i] = new SimpleHook("" + i);
+        }
+
+        return t;
+    }
+}
+
+
+    // The class adds hooks which are already executed/finished threads.
+
+class AppNormalCompletionFinishedHooks {
+
+    public static void main(String[] args){
+
+        Thread[] hooks = createExecutedHookThreads(Integer.parseInt(args[0]));
+
+        for (int i = 0; i < hooks.length; ++ i){
+            Runtime.getRuntime().addShutdownHook(hooks[i]);
+        }
+
+    }
+
+    static Thread[] createExecutedHookThreads(int n_of_hooks_to_start) {
+
+        Thread[] t = new Thread[n_of_hooks_to_start];
+
+        for (int i = 0; i < t.length; ++i){
+            t[i] = new SimpleHook("" + i);
+            t[i].start();
+            try {
+                t[i].join();
+            } catch (InterruptedException ie){
+            }
+        }
+        return t;
+    }
+}
+
+
+    // The class adds hooks and exits via System.exit().
+
+class AppSysExitCompletion {
+
+    public static void main(String[] args){
+
+        AppNormalCompletion.main(args);
+
+        System.exit(AddRmShtdwnHooksTest.EXIT_CODE);
+    }
+}
+
+
+    // The class adds hooks and exits via Runtime.halt().
+
+class AppHalted {
+
+    public static void main(String[] args){
+
+        AppNormalCompletion.main(args);
+
+        Runtime.getRuntime().halt(AddRmShtdwnHooksTest.HALT_CODE);
+    }
+}
+
+
+    // The class adds hooks and hangs in Object.wait(), expecting that the process
+    // (running class) will be destroyed.
+
+class AppDestroyedProcess {
+
+    static Object obj = new Object();
+ 
+    public static void main(String[] args){
+          
+        AppNormalCompletion.main(args);
+
+        synchronized(obj){
+
+            // This print() is to indicate that the process started and is ready 
+            // to be destroyed. This is done to avoid destroying being started VM.
+
+            System.out.print(AddRmShtdwnHooksTest.STARTED);
+
+            // wait() forever waiting for being destroyed.
+
+            while(true){
+                try {
+                    obj.wait();
+                } catch (InterruptedException ie){
+                    return;
+                }
+            }
+
+        }   
+    }
+
+}
+
+
+    // This class represents all hooks. Each hook prints into stdout ":ok" as a 
+    // signal that the hook works.
+
+class SimpleHook extends Hook {
+
+    String name = "";
+
+    static Random r = new Random(1);
+
+    static Object obj = new Object();
+
+    public SimpleHook(String name){
+        this.name = name;
+    }
+
+    public void run() {
+
+        int x = r.nextInt(50);
+
+        try {
+
+            Thread.sleep(x);
+
+        } catch (InterruptedException ie){
+        }
+
+        // why synchronized? - to avoid simultaneous writing of strings by
+        // executed in parallel threads.
+
+        synchronized(SimpleHook.obj) {
+            System.out.print(name + Hook.separator);
+
+        }
+    }
+}
+
+
+class Hook extends Thread {
+
+    public static String separator = ":ok";
+
+}
+
+
+    // The class is a Thread which reads from the Process, hanging in read() until 
+    // read() returns -1 as a signal that application halted or until IOException. 
+    // Both cases signal that nothing was printed by the Process into stdout. 
+    // This is expected result, since halt() should not cause hooks running (hooks 
+    // print into stdout). 
+
+class ProcessOutputReader extends Thread {
+
+    volatile boolean started = false;
+    volatile boolean finished = false;
+    volatile int read_bytes = 0;
+
+    InputStream is;
+
+    public ProcessOutputReader(InputStream is){
+        this.is = is;
+    }
+
+
+    public void run() {
+        try {
+            started = true;
+
+            while(is.read() > 0) {
+                ++read_bytes;
+            }
+
+            finished = true;
+
+        } catch (IOException ioe) {
+            finished = true;
+            return;
+        }
+    }
+}
+
+
+
+
+

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



Mime
View raw message