jdk/test/tools/launcher/Arrrghs.java
author ksrini
Fri, 20 Nov 2009 11:01:32 -0800
changeset 4340 ec6ba551fa78
parent 1343 ecc86134ee4c
child 5506 202f599c92aa
permissions -rw-r--r--
6367077: Purge LD_LIBRARY_PATH usage from the launcher 6899834: (launcher) remove the solaris libjvm.so symlink Summary: Fixes other related issues as well. Reviewed-by: darcy, ohair, xlu, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    24
/**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    25
 * @test
1343
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
    26
 * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
    27
 * @summary Argument parsing validation.
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 1343
diff changeset
    28
 * @compile -XDignore.symbol.file Arrrghs.java TestHelper.java
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    29
 * @run main Arrrghs
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    30
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    31
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    32
import java.io.BufferedReader;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    33
import java.io.File;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    34
import java.io.FileNotFoundException;
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    35
import java.io.IOException;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    36
import java.io.InputStream;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    37
import java.io.InputStreamReader;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    38
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    40
public class Arrrghs {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    41
    private Arrrghs(){}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    43
     * This class provides various tests for arguments processing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * A group of tests to ensure that arguments are passed correctly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * a child java process upon a re-exec, this typically happens when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * a version other than the one being executed is requested by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * History: these set of tests  were part of Arrrghs.sh. The MKS shell
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    49
     * implementations were notoriously buggy. Implementing these tests purely
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * in Java is not only portable but also robust.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // The version string to force a re-exec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    final static String VersionStr = "-version:1.1+";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // The Cookie or the pattern we match in the debug output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    final static String Cookie = "ReExec Args: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * SIGH, On Windows all strings are quoted, we need to unwrap it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static String removeExtraQuotes(String in) {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    64
        if (TestHelper.isWindows) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            // Trim the string and remove the enclosed quotes if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            in = in.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            if (in.startsWith("\"") && in.endsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                return in.substring(1, in.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * This method detects the cookie in the output stream of the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    77
    private static boolean detectCookie(InputStream istream,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    78
            String expectedArguments) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        BufferedReader rd = new BufferedReader(new InputStreamReader(istream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        while (in != null) {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    84
            if (TestHelper.debug) System.out.println(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (in.startsWith(Cookie)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                String detectedArgument = removeExtraQuotes(in.substring(Cookie.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                if (expectedArguments.equals(detectedArgument)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    retval = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                } else {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    90
                    System.out.println("Error: Expected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    91
                            expectedArguments + "'");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    92
                    System.out.println(" Detected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    93
                            detectedArgument + "'");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                // Return the value asap if not in debug mode.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    96
                if (!TestHelper.debug) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    rd.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    istream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   107
    private static boolean doTest0(ProcessBuilder pb, String expectedArguments) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        try {
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
   110
            pb.redirectErrorStream(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Process p = pb.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            retval = detectCookie(p.getInputStream(), expectedArguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            p.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            p.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * This method return true  if the expected and detected arguments are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Quoting could cause dissimilar testArguments and expected arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   126
    static int doTest(String testArguments, String expectedPattern) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   127
        ProcessBuilder pb = new ProcessBuilder(TestHelper.javaCmd,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   128
                VersionStr, testArguments);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Map<String, String> env = pb.environment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        env.put("_JAVA_LAUNCHER_DEBUG", "true");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   132
        return doTest0(pb, testArguments) ? 0 : 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * A convenience method for identical test pattern and expected arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   138
    static int doTest(String testPattern) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   139
        return doTest(testPattern, testPattern);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   140
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   141
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   142
    static void quoteParsingTests() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   143
        /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   144
         * Tests for 6214916
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   145
         * These tests require that a JVM (any JVM) be installed in the system registry.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   146
         * If none is installed, skip this test.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   147
         */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   148
        TestHelper.TestResult tr =
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   149
                TestHelper.doExec(TestHelper.javaCmd, VersionStr, "-version");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   150
        if (!tr.isOK()) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   151
            System.err.println("Warning:Argument Passing Tests were skipped, " +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   152
                    "no java found in system registry.");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   153
            return;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   154
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   155
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   156
        // Basic test
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   157
        TestHelper.testExitValue += doTest("-a -b -c -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   158
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   159
        // Basic test with many spaces
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   160
        TestHelper.testExitValue += doTest("-a    -b      -c       -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   161
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   162
        // Quoted whitespace does matter ?
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   163
        TestHelper.testExitValue += doTest("-a \"\"-b      -c\"\" -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   164
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   165
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   166
        // Escaped quotes outside of quotes as literals
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   167
        TestHelper.testExitValue += doTest("-a \\\"-b -c\\\" -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   168
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   169
        // Check for escaped quotes inside of quotes as literal
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   170
        TestHelper.testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   171
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   172
        // A quote preceeded by an odd number of slashes is a literal quote
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   173
        TestHelper.testExitValue += doTest("-a -b\\\\\\\" -c -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   174
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   175
        // A quote preceeded by an even number of slashes is a literal quote
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   176
        // see 6214916.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   177
        TestHelper.testExitValue += doTest("-a -b\\\\\\\\\" -c -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   178
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   179
        // Make sure that whitespace doesn't interfere with the removal of the
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   180
        // appropriate tokens. (space-tab-space preceeds -jre-restict-search).
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   181
        TestHelper.testExitValue += doTest("-a -b  \t -jre-restrict-search -c -d","-a -b -c -d");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   182
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   183
        // Make sure that the mJRE tokens being stripped, aren't stripped if
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   184
        // they happen to appear as arguments to the main class.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   185
        TestHelper.testExitValue += doTest("foo -version:1.1+");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   186
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   187
        System.out.println("Completed arguments quoting tests with " +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   188
                TestHelper.testExitValue + " errors");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   189
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   190
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   191
    /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   192
     * These tests are usually run on non-existent targets to check error results
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   193
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   194
    static void runBasicErrorMessageTests() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   195
        // Tests for 5030233
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   196
        TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd, "-cp");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   197
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   198
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   199
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   200
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   201
        tr = TestHelper.doExec(TestHelper.javaCmd, "-classpath");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   202
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   203
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   204
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   205
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   206
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   207
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   208
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   209
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   210
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   211
        tr = TestHelper.doExec(TestHelper.javacCmd, "-cp");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   212
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   213
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   214
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   215
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   216
        // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   217
        tr = TestHelper.doExec(TestHelper.javaCmd, "-X");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   218
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   219
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   220
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   221
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   222
        tr = TestHelper.doExec(TestHelper.javaCmd, "-help");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   223
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   224
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   225
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   226
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   227
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   228
    /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   229
     * A set of tests which tests various dispositions of the main method.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   230
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   231
    static void runMainMethodTests() throws FileNotFoundException {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   232
        TestHelper.TestResult tr = null;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   233
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   234
        // a missing class
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   235
        TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"),
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   236
                (String[])null);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   237
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
1343
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   238
        tr.contains("Error: Could not find main class MIA");
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   239
        tr.contains("java.lang.NoClassDefFoundError: MIA");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   240
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   241
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   242
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   243
        tr.contains("Error: Could not find main class MIA");
1343
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   244
        tr.contains("java.lang.NoClassDefFoundError: MIA");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   245
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   246
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   247
        // incorrect method access
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   248
        TestHelper.createJar(new File("some.jar"), new File("Foo"),
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   249
                "private static void main(String[] args){}");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   250
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   251
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   252
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   253
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   254
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   255
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   256
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   257
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   258
        // incorrect return type
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   259
        TestHelper.createJar(new File("some.jar"), new File("Foo"),
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   260
                "public static int main(String[] args){return 1;}");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   261
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   262
        tr.contains("Error: Main method must return a value of type void in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   263
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   264
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   265
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   266
        tr.contains("Error: Main method must return a value of type void in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   267
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   268
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   269
        // incorrect parameter type
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   270
        TestHelper.createJar(new File("some.jar"), new File("Foo"),
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   271
                "public static void main(Object[] args){}");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   272
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   273
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   274
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   275
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   276
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   277
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   278
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   279
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   280
        // incorrect method type - non-static
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   281
         TestHelper.createJar(new File("some.jar"), new File("Foo"),
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   282
                "public void main(String[] args){}");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   283
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   284
        tr.contains("Error: Main method is not static in class Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   285
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   286
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   287
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   288
        tr.contains("Error: Main method is not static in class Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   289
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   290
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   291
        // amongst a potpourri of kindred main methods, is the right one chosen ?
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   292
        TestHelper.createJar(new File("some.jar"), new File("Foo"),
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   293
        "void main(Object[] args){}",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   294
        "int  main(Float[] args){return 1;}",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   295
        "private void main() {}",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   296
        "private static void main(int x) {}",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   297
        "public int main(int argc, String[] argv) {return 1;}",
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   298
        "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   299
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   300
        tr.contains("THE_CHOSEN_ONE");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   301
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   302
        // use classpath to check
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   303
        tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   304
        tr.contains("THE_CHOSEN_ONE");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   305
        System.out.println(tr);
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   306
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   307
        // test for extraneous whitespace in the Main-Class attribute
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   308
        TestHelper.createJar(" Foo ", new File("some.jar"), new File("Foo"),
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   309
                "public static void main(String... args){}");
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   310
        tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   311
        tr.checkPositive();
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   312
        System.out.println(tr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param args the command line arguments
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   317
     * @throws java.io.FileNotFoundException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   319
    public static void main(String[] args) throws FileNotFoundException {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   320
        if (TestHelper.debug) System.out.println("Starting Arrrghs tests");
1343
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   321
            quoteParsingTests();
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   322
            runBasicErrorMessageTests();
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   323
            runMainMethodTests();
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   324
            if (TestHelper.testExitValue > 0) {
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   325
                System.out.println("Total of " + TestHelper.testExitValue + " failed");
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   326
                System.exit(1);
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   327
            } else {
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   328
                System.out.println("All tests pass");
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
   329
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }