test/hotspot/jtreg/vmTestbase/nsk/share/RASagent.java
author iignatyev
Mon, 30 Apr 2018 18:10:24 -0700
changeset 49934 44839fbb20db
permissions -rw-r--r--
8199643: [TESTBUG] Open source common VM testbase code Reviewed-by: vlivanov, erikj, mseledtsov, gthornbr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     1
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     4
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     8
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    14
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    18
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    21
 * questions.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    22
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    23
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    24
package nsk.share;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    25
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    26
import java.io.*;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    27
import java.lang.reflect.Method;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    28
import java.util.*;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    29
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    30
/**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    31
 * Class used as an agent for Java serviceability reliability testing (RAS).
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    32
 * It sets different RAS options and/or modes for a special agent which
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    33
 * actually performs the specified RAS testing.<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    34
 * The agent recognizes arguments, started with ''<code>-ras.</code>''. They
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    35
 * may be as follows:<p>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    36
 * <li><code>-ras.help</code> - print usage message and exit
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    37
 * <li><code>-ras.verbose</code> - verbose mode
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    38
 * <li><code>-ras.invoke_run</code> - invoke the method <i>run(String[],PrintStream)</i>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    39
 * of the test instead of <i>main(String[])</i> which is invoked by default.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    40
 * <li><code>-ras.hotswap=&lt;stress_level&gt;</code> - enable JVMTI hotswap of
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    41
 * the currently running test classes. Here are the possible HotSwap stress
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    42
 * levels:<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    43
 * 0 - HotSwap off<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    44
 * 2 - HotSwap tested class in every JVMTI method entry event of running test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    45
 * (default mode)<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    46
 * 20 - HotSwap tested class in every JVMTI method entry event of every class<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    47
 * 3 - HotSwap tested class in every JVMTI single step event of running test<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    48
 * 4 - HotSwap tested class in every JVMTI exception event of running test<br>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    49
 * 40 - HotSwap tested class in every JVMTI exception event of every class<p>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    50
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    51
public class RASagent {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    52
    static final int HOTSWAP_OFF = 0;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    53
    static final int HOTSWAP_EVERY_METHOD_ENTRY = 2;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    54
    static final int HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS = 20;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    55
    static final int HOTSWAP_EVERY_SINGLE_STEP = 3;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    56
    static final int HOTSWAP_EVERY_EXCEPTION = 4;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    57
    static final int HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS = 40;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    58
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    59
    // path to the directory with class files of the invoked test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    60
    static String clfBasePath = null;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    61
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    62
    private static boolean verbose = false;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    63
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    64
    private static PrintStream out;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    65
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    66
    native static int setHotSwapMode(boolean vrb, int stress_lev,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    67
        String shortName);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    68
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    69
    public static void main(String argv[]) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    70
        System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    71
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    72
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    73
    public static int run(String argv[], PrintStream out) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    74
        return new RASagent().runThis(argv, out);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    75
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    76
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    77
    private int runThis(String argv[], PrintStream out) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    78
        int skipArgs = 1; // number of arguments which must be skipped
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    79
                          // for the invoked test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    80
        boolean invokeRun = false; // invoke the method "main" by default
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    81
        int hotSwapMode = HOTSWAP_EVERY_METHOD_ENTRY; // HotSwap default stress level
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    82
        int res;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    83
        String hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    84
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    85
        RASagent.out = out;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    86
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    87
        if (argv.length != 0) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    88
            // parse arguments for the RASagent and then skip them
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    89
            while(argv[skipArgs-1].startsWith("-ras.")) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    90
                if (argv[skipArgs-1].equals("-ras.verbose")) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    91
                    verbose = true;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    92
                } else if (argv[skipArgs-1].equals("-ras.help")) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    93
                    printHelp();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    94
                    return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    95
                } else if (argv[skipArgs-1].equals("-ras.invoke_run")) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    96
                    invokeRun = true;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    97
                } else if (argv[skipArgs-1].startsWith("-ras.hotswap=")) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    98
                    try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    99
                        hotSwapMode = Integer.parseInt(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   100
                           argv[skipArgs-1].substring(argv[skipArgs-1].lastIndexOf("=")+1));
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   101
                    } catch (NumberFormatException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   102
                        e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   103
                        out.println("\nERROR: RASagent: specified HotSwap mode \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   104
                            + hotSwapMode + "\" is not an integer");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   105
                        printHelp();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   106
                        return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   107
                    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   108
                    switch(hotSwapMode) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   109
                        case HOTSWAP_EVERY_METHOD_ENTRY:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   110
                            hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   111
                            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   112
                        case HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   113
                            hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   114
                            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   115
                        case HOTSWAP_EVERY_SINGLE_STEP:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   116
                            hotSwapModeName = "HOTSWAP_EVERY_SINGLE_STEP";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   117
                            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   118
                        case HOTSWAP_EVERY_EXCEPTION:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   119
                            hotSwapModeName = "HOTSWAP_EVERY_EXCEPTION";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   120
                            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   121
                        case HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   122
                            hotSwapModeName = "HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   123
                            break;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   124
                        default:
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   125
                            out.println("\nERROR: RASagent: specified HotSwap mode \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   126
                                + hotSwapMode + "\" is unrecognized");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   127
                            printHelp();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   128
                            return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   129
                    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   130
                }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   131
                skipArgs++;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   132
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   133
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   134
            String shortTestName = getTestNameAndPath(argv[skipArgs-1]);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   135
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   136
            display("\n#### RASagent: setting hotswap mode \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   137
                + hotSwapModeName + "\" for class \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   138
                + shortTestName + "\" ...");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   139
            if ((res = setHotSwapMode(verbose, hotSwapMode, shortTestName)) != 0) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   140
                out.println("\nERROR: RASagent: unable to set HotSwap stress level for \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   141
                    + shortTestName + "\", exiting");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   142
                return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   143
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   144
            display("\n#### RASagent: ... setting hotswap mode done");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   145
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   146
            try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   147
                Class testCls = Class.forName(argv[skipArgs-1]);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   148
                display("\n#### RASagent: main class \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   149
                    + testCls.toString() + "\" loaded");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   150
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   151
                // copy arguments for the invoked test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   152
                String args[] = new String[argv.length-skipArgs];
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   153
                System.arraycopy(argv, skipArgs, args, 0, args.length);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   154
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   155
                // invoke the test
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   156
                if (invokeRun)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   157
                    return invokeRunMethod(testCls, args);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   158
                else
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   159
                    return invokeMainMethod(testCls, args);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   160
            } catch(ClassNotFoundException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   161
                // just pass: the invoked test is already a RAS specific one
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   162
                out.println("\nWARNING: the test was not really run due to the following error:"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   163
                    + "\n\tunable to get the Class object for \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   164
                    + argv[skipArgs-1] + "\"\n\tcaught: " + e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   165
                return Consts.TEST_PASSED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   166
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   167
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   168
        } else {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   169
            out.println("\nERROR: RASagent: required test name is absent in parameters list");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   170
            return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   171
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   172
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   173
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   174
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   175
     * Verify that test's class file exists with a path given as a parameter
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   176
     * and, if so, store that path in the static field "clfBasePath".
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   177
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   178
    private boolean pathValid(String pathToCheck, String testName) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   179
        String fullPath = pathToCheck + File.separator
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   180
            + testName.replace('.', File.separatorChar) + ".class";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   181
        File classFile = null;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   182
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   183
        display("\n#### RASagent: verifying class path\n<RASagent>\t"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   184
            + pathToCheck + " ...");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   185
        try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   186
            classFile = new File(fullPath);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   187
        } catch (NullPointerException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   188
            e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   189
            out.println("\nERROR: RASagent: verification of class file "
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   190
                + fullPath + " failed: caught " + e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   191
            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   192
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   193
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   194
        if (classFile.exists()) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   195
            clfBasePath = pathToCheck;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   196
            display("<RASagent>\tthe class file exists:\n<RASagent>\t\t"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   197
                + fullPath + "\n<RASagent>\tclass file base directory found:\n"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   198
                + "<RASagent>\t\t" + clfBasePath
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   199
                + "\n#### RASagent: ... class path verification done\n");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   200
            return true;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   201
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   202
        else {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   203
            display("<RASagent>\tno class file at location :\n\t\t"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   204
                + fullPath
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   205
                + "\n#### RASagent: ... class path verification done\n");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   206
            return false;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   207
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   208
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   209
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   210
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   211
     * Get short name of an invoked test (i.e. without package name) and
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   212
     * store path to the directory with the test's class files.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   213
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   214
    private String getTestNameAndPath(String testName) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   215
        String shortTestName = testName;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   216
        String packageName = "";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   217
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   218
        // if '.' occurs, it means that current test is inside a package
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   219
        if (testName.lastIndexOf(".") != -1) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   220
            shortTestName = testName.substring(testName.lastIndexOf(".")+1);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   221
            packageName = testName.substring(0, testName.lastIndexOf("."));
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   222
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   223
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   224
        StringTokenizer clPathes = new StringTokenizer(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   225
            System.getProperty("java.class.path"), File.pathSeparator);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   226
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   227
        while(clPathes.hasMoreTokens()) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   228
            String clPath = clPathes.nextToken();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   229
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   230
            // trying to load a class file defining the current test from
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   231
            // this entry of "java.class.path": the class file may locate
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   232
            // at the test's work directory or if it's already compiled,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   233
            // at any directory in classpath
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   234
            if (pathValid(clPath, testName))
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   235
                return shortTestName;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   236
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   237
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   238
        // directory with the test's class files was not found.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   239
        // Actually, it means that the invoked test has own Java
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   240
        // options such as, for example, "-verify"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   241
        out.println("\nWARNING: the test was not really run due to the following reason:"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   242
            + "\n\tthe invoked test has the own Java option: "
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   243
            + testName);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   244
        System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_PASSED);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   245
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   246
        return null; // fake return for too smart javac
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   247
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   248
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   249
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   250
     * Invoke the method <i>main(String[])</i> of the test.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   251
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   252
    private int invokeMainMethod(Class testCls, String args[]) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   253
        Class[] methType = { String[].class };
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   254
        Object[] methArgs = { args };
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   255
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   256
        return invokeMethod(testCls, "main", methType, methArgs);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   257
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   258
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   259
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   260
     * Invoke the method <i>run(String[], PrintStream)</i> of the test.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   261
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   262
    private int invokeRunMethod(Class testCls, String args[]) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   263
        Class[] methType = { String[].class, PrintStream.class };
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   264
        Object[] methArgs = { args, out };
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   265
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   266
        return invokeMethod(testCls, "run", methType, methArgs);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   267
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   268
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   269
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   270
     * Low level invocation of the test.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   271
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   272
    private int invokeMethod(Class<?> testCls, String methodName,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   273
            Class methType[], Object methArgs[]) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   274
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   275
        try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   276
            Method testMeth = testCls.getMethod(methodName, methType);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   277
            display("\n#### RASagent: invoking method \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   278
                + testMeth.toString() + "\" ...");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   279
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   280
            Object result = testMeth.invoke(null, methArgs);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   281
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   282
            display("\n#### RASagent: ... invocation of \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   283
                + testMeth.toString() + "\" done");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   284
            if (result instanceof Integer) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   285
                Integer retCode = (Integer) result;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   286
                return retCode.intValue();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   287
            }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   288
        } catch(NoSuchMethodException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   289
            e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   290
            out.println("\nFAILURE: RASagent: unable to get method \""
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   291
                + methodName + "\" in class "
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   292
                + testCls + "\n\tcaught " + e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   293
            return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   294
        } catch(Exception e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   295
            e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   296
            out.println("\nFAILURE: RASagent: caught during invokation of the test class "
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   297
                + testCls + " " + e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   298
            return Consts.TEST_FAILED;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   299
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   300
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   301
        return -1;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   302
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   303
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   304
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   305
     * Load class bytes for HotSwap.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   306
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   307
    static byte[] loadFromClassFile(String signature) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   308
        String testPath = clfBasePath + File.separator + signature.substring(
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   309
                1, signature.length()-1).replace('/', File.separatorChar) + ".class";
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   310
        File classFile = null;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   311
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   312
        display("\n#### RASagent: looking for class file\n<RASagent>\t"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   313
            + testPath + " ...");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   314
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   315
        try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   316
            classFile = new File(testPath);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   317
        } catch (NullPointerException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   318
            out.println("\nFAILURE: RASagent: path name to the redefining class file is null");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   319
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   320
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   321
        display("\n#### RASagent: loading " + classFile.length()
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   322
            + " bytes from class file "+ testPath + " ...");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   323
        byte[] buf = new byte[(int) classFile.length()];
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   324
        try {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   325
            InputStream in = new FileInputStream(classFile);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   326
            in.read(buf);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   327
            in.close();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   328
        } catch(FileNotFoundException e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   329
            e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   330
            out.println("\nFAILURE: RASagent: loadFromClassFile: file " +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   331
                classFile.getName() + " not found");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   332
            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   333
        } catch (Exception e) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   334
            e.printStackTrace();
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   335
            out.println("\nFAILURE: RASagent: unable to load bytes from the file:\n");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   336
            out.println("\t" + testPath + ": caught " + e);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   337
            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   338
        }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   339
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   340
        display("\n#### RASagent: ... " + classFile.length() + " bytes loaded");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   341
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   342
        return buf;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   343
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   344
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   345
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   346
     * This method is used in verbose mode. It prints paramter string only
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   347
     * in case of verbose mode.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   348
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   349
    private static void display(String msg) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   350
        if (verbose)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   351
            out.println(msg);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   352
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   353
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   354
    /**
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   355
     * This method prints out RASagent usage message.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   356
     */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   357
    private static void printHelp() {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   358
        out.println("\nRASagent usage: RASagent [option, ...] test" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   359
            "\n\t-ras.help                 print this message and exit" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   360
            "\n\t-ras.verbose              verbose mode (off by default)" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   361
            "\n\t-ras.hotswap=mode         enable HotSwap of the running test classes" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   362
            "\n\t\twhere mode is:" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   363
            "\n\t\t\t" + HOTSWAP_EVERY_METHOD_ENTRY
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   364
                + " - hotswap tested class in its every method entry event" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   365
            "\n\t\t\t" + HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   366
                + " - hotswap tested class in every method entry event for every class" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   367
            "\n\t\t\t" + HOTSWAP_EVERY_SINGLE_STEP
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   368
                + " - hotswap tested class in its every single step event" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   369
            "\n\t\t\t" + HOTSWAP_EVERY_EXCEPTION
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   370
                + " - hotswap tested class in its every exception event" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   371
            "\n\t\t\t" + HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   372
                + " - hotswap tested class in every exception event for every class\n" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   373
            "\n\t-ras.invoke_run           invoke the method run() of the test" +
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   374
            "\n\t\tinstead of main() by default");
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   375
    }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
   376
}