jdk/test/java/lang/instrument/FakeTestDriver.java
author chegar
Tue, 09 Aug 2011 16:39:04 +0100
changeset 10150 dee4cb73adc3
parent 5506 202f599c92aa
permissions -rw-r--r--
7073295: TEST_BUG: test/java/lang/instrument/ManifestTest.sh causing havoc (win) Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. 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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  Cheesy class to run all of our test cases in a hard-coded fashion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  Will be replaced by Sun's iterator that uses the source decorations to figure out what to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import  java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class FakeTestDriver  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private String[] fTestList = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        "javafake.lang.instrument.AddTransformerTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        "javafake.lang.instrument.AppendToBootstrapClassPathTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        "javafake.lang.instrument.AppendToClassPathTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        "javafake.lang.instrument.GetAllLoadedClassesTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        "javafake.lang.instrument.GetInitiatedClassesTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        "javafake.lang.instrument.GetObjectSizeTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        "javafake.lang.instrument.NoTransformerAddedTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        "javafake.lang.instrument.NullTransformerAddTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        "javafake.lang.instrument.RedefineClassesTests",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        "javafake.lang.instrument.RemoveAbsentTransformerTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        "javafake.lang.instrument.RemoveTransformerTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        "javafake.lang.instrument.SingleTransformerTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        "javafake.lang.instrument.TransformerManagementThreadAddTests",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        "javafake.lang.instrument.TransformerManagementThreadRemoveTests",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "javafake.lang.instrument.TransformMethodTest",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        (new FakeTestDriver()).runSuppliedTests(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
    private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    FakeTestDriver() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    runAllTests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        runSuppliedTests(fTestList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    runSuppliedTests(String[] classnames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        for (int x = 0; x < classnames.length; x++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            loadAndRunOneTest(classnames[x]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    loadAndRunOneTest(String classname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        log("trying to run: " + classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Class testclass = loadOneTest(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if ( testclass != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            boolean result = runOneTest(testclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if ( result ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                log(classname + " SUCCEEDED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                log(classname + " FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            log(classname + " could not be loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    loadOneTest(String classname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        Class result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            result = Class.forName(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            t.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    runOneTest(Class testclass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Method mainMethod = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            String[]    forType = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            mainMethod = testclass.getMethod("main",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                    new Class[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                                        forType.getClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                                     });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            log(testclass.getName() + " is malformed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            t.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            mainMethod.invoke(null, new Object[] {new String[] {testclass.getName()}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            t.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    log(String m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        System.out.println(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}