Path: blob/master/test/jdk/java/lang/instrument/FakeTestDriver.java
41149 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* Copyright 2003 Wily Technology, Inc.26*/2728/**29* Cheesy class to run all of our test cases in a hard-coded fashion.30* Will be replaced by Sun's iterator that uses the source decorations to figure out what to do.31*/3233import java.lang.reflect.*;3435public class FakeTestDriver {3637private String[] fTestList = {38"javafake.lang.instrument.AddTransformerTest",39"javafake.lang.instrument.AppendToBootstrapClassPathTest",40"javafake.lang.instrument.AppendToClassPathTest",41"javafake.lang.instrument.GetAllLoadedClassesTest",42"javafake.lang.instrument.GetInitiatedClassesTest",43"javafake.lang.instrument.GetObjectSizeTest",44"javafake.lang.instrument.NoTransformerAddedTest",45"javafake.lang.instrument.NullTransformerAddTest",46"javafake.lang.instrument.RedefineClassesTests",47"javafake.lang.instrument.RemoveAbsentTransformerTest",48"javafake.lang.instrument.RemoveTransformerTest",49"javafake.lang.instrument.SingleTransformerTest",50"javafake.lang.instrument.TransformerManagementThreadAddTests",51"javafake.lang.instrument.TransformerManagementThreadRemoveTests",52"javafake.lang.instrument.TransformMethodTest",53};5455public static void56main(String[] args) {57(new FakeTestDriver()).runSuppliedTests(args);58}5960private61FakeTestDriver() {62}6364private void65runAllTests() {66runSuppliedTests(fTestList);67}6869private void70runSuppliedTests(String[] classnames) {71for (int x = 0; x < classnames.length; x++ ) {72loadAndRunOneTest(classnames[x]);73}74}7576private void77loadAndRunOneTest(String classname) {78log("trying to run: " + classname);7980Class testclass = loadOneTest(classname);8182if ( testclass != null ) {83boolean result = runOneTest(testclass);84if ( result ) {85log(classname + " SUCCEEDED");86}87else {88log(classname + " FAILED");89}90}91else {92log(classname + " could not be loaded");93}94}9596private Class97loadOneTest(String classname) {98Class result = null;99100try {101result = Class.forName(classname);102}103catch (Throwable t) {104t.printStackTrace();105result = null;106}107return result;108}109110private boolean111runOneTest(Class testclass) {112Method mainMethod = null;113114try {115String[] forType = new String[0];116mainMethod = testclass.getMethod("main",117new Class[] {118forType.getClass()119});120}121catch (Throwable t) {122log(testclass.getName() + " is malformed");123t.printStackTrace();124return false;125}126127try {128mainMethod.invoke(null, new Object[] {new String[] {testclass.getName()}});129return true;130}131catch (Throwable t) {132t.printStackTrace();133return false;134}135}136137private void138log(String m) {139System.out.println(m);140}141}142143144