|
1 /* |
|
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package nsk.share.jdi.sde; |
|
24 |
|
25 import java.lang.reflect.Method; |
|
26 import nsk.share.TestBug; |
|
27 import nsk.share.jdi.*; |
|
28 |
|
29 public class SDEDebuggee extends AbstractJDIDebuggee { |
|
30 public static String mainThreadName = "SDEDebuggee_mainThread"; |
|
31 |
|
32 // command:class_name |
|
33 public static String COMMAND_EXECUTE_TEST_METHODS = "executeTestMethods"; |
|
34 |
|
35 public static void main(String args[]) { |
|
36 new SDEDebuggee().doTest(args); |
|
37 } |
|
38 |
|
39 protected String[] doInit(String[] args) { |
|
40 args = super.doInit(args); |
|
41 |
|
42 if (classpath == null) |
|
43 throw new TestBug("Debuggee requires '-testClassPath' parameter"); |
|
44 |
|
45 Thread.currentThread().setName(mainThreadName); |
|
46 |
|
47 return args; |
|
48 } |
|
49 |
|
50 public boolean parseCommand(String command) { |
|
51 if (super.parseCommand(command)) |
|
52 return true; |
|
53 |
|
54 if (command.startsWith(COMMAND_EXECUTE_TEST_METHODS)) { |
|
55 // extract class name |
|
56 String split[] = command.split(":"); |
|
57 |
|
58 if ((split.length != 2) || (split[1].length() == 0)) |
|
59 throw new TestBug(""); |
|
60 |
|
61 executeTestMethods(split[1]); |
|
62 breakpointMethod(); |
|
63 |
|
64 return true; |
|
65 } |
|
66 |
|
67 return false; |
|
68 } |
|
69 |
|
70 // create instance of given class and execute all methods which names start |
|
71 // with 'sde_testMethod' |
|
72 private void executeTestMethods(String className) { |
|
73 TestClassLoader classLoader = new TestClassLoader(); |
|
74 classLoader.setClassPath(classpath); |
|
75 |
|
76 try { |
|
77 Class<?> klass = classLoader.loadClass(className); |
|
78 Object testObject = klass.newInstance(); |
|
79 |
|
80 for (Method method : klass.getDeclaredMethods()) { |
|
81 if (method.getName().startsWith("sde_testMethod")) |
|
82 method.invoke(testObject, new Object[] {}); |
|
83 } |
|
84 } catch (Exception e) { |
|
85 setSuccess(false); |
|
86 log.complain("Unexpected exception: " + e); |
|
87 e.printStackTrace(log.getOutStream()); |
|
88 |
|
89 throw new TestBug("Unexpected exception: " + e); |
|
90 } |
|
91 } |
|
92 |
|
93 } |