author | iignatyev |
Fri, 07 Sep 2018 14:01:52 -0700 | |
changeset 51675 | b487c1e914d0 |
parent 51541 | 69ee8894f5fa |
child 52731 | 157c1130b46e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51541
69ee8894f5fa
8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
31454
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
24 |
import java.io.File; |
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
25 |
import java.io.IOException; |
2 | 26 |
import java.net.ServerSocket; |
27 |
import java.net.Socket; |
|
31454
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
28 |
import java.util.List; |
2 | 29 |
import java.util.Properties; |
31454
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
30 |
|
51541
69ee8894f5fa
8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents:
47216
diff
changeset
|
31 |
import jdk.test.lib.thread.ProcessThread; |
51675 | 32 |
import jdk.test.lib.process.OutputAnalyzer; |
33 |
import jdk.test.lib.process.ProcessTools; |
|
31454
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
34 |
|
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
35 |
import com.sun.tools.attach.AgentInitializationException; |
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
36 |
import com.sun.tools.attach.AgentLoadException; |
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
37 |
import com.sun.tools.attach.VirtualMachine; |
4dba1183dc2f
8085813: The targeted processes in sun/tools tests should be launched with -XX:+UsePerfData flag in order to work on embedded platforms
ykantser
parents:
30820
diff
changeset
|
38 |
import com.sun.tools.attach.VirtualMachineDescriptor; |
2 | 39 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
40 |
/* |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
41 |
* @test |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
42 |
* @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757 |
32018
91c91b3d50a0
8132094: Mark intermittently failuring core-svc tests
ykantser
parents:
31909
diff
changeset
|
43 |
* @key intermittent |
44425
ae33f100001d
8177374: fix module dependency declaration in jdk_svc tests
iignatyev
parents:
32018
diff
changeset
|
44 |
* @summary Basic unit tests for the VM attach mechanism. This test will perform |
ae33f100001d
8177374: fix module dependency declaration in jdk_svc tests
iignatyev
parents:
32018
diff
changeset
|
45 |
* a number of basic attach tests. |
ae33f100001d
8177374: fix module dependency declaration in jdk_svc tests
iignatyev
parents:
32018
diff
changeset
|
46 |
* |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
47 |
* @library /lib/testlibrary |
51541
69ee8894f5fa
8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents:
47216
diff
changeset
|
48 |
* @library /test/lib |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
28760
diff
changeset
|
49 |
* @modules java.instrument |
44425
ae33f100001d
8177374: fix module dependency declaration in jdk_svc tests
iignatyev
parents:
32018
diff
changeset
|
50 |
* jdk.attach |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
28760
diff
changeset
|
51 |
* jdk.jartool/sun.tools.jar |
44425
ae33f100001d
8177374: fix module dependency declaration in jdk_svc tests
iignatyev
parents:
32018
diff
changeset
|
52 |
* |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
53 |
* @run build jdk.testlibrary.* Agent BadAgent RedefineAgent Application RedefineDummy RunnerUtil |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
54 |
* @run main BasicTests |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
55 |
*/ |
2 | 56 |
public class BasicTests { |
57 |
||
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
58 |
/* |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
59 |
* The actual test is in the nested class TestMain. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
60 |
* The responsibility of this class is to: |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
61 |
* 1. Build all needed jars. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
62 |
* 2. Start the Application class in a separate process. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
63 |
* 3. Find the pid and shutdown port of the running Application. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
64 |
* 4. Launches the tests in nested class TestMain that will attach to the Application. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
65 |
* 5. Shut down the Application. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
66 |
*/ |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
67 |
public static void main(String args[]) throws Throwable { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
68 |
ProcessThread processThread = null; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
69 |
try { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
70 |
buildJars(); |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
71 |
processThread = RunnerUtil.startApplication(); |
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
72 |
runTests(processThread.getPid()); |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
73 |
} catch (Throwable t) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
74 |
System.out.println("TestBasic got unexpected exception: " + t); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
75 |
t.printStackTrace(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
76 |
throw t; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
77 |
} finally { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
78 |
// Make sure the Application process is stopped. |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
79 |
RunnerUtil.stopApplication(processThread); |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
80 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
81 |
} |
2 | 82 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
83 |
/** |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
84 |
* Runs the actual tests in nested class TestMain. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
85 |
* The reason for running the tests in a separate process |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
86 |
* is that we need to modify the class path. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
87 |
*/ |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
88 |
private static void runTests(long pid) throws Throwable { |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
89 |
final String sep = File.separator; |
2 | 90 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
91 |
// Need to add jdk/lib/tools.jar to classpath. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
92 |
String classpath = |
28760
b83d51c77b31
8067945: SVC jdk/test/* should be cleaned from JRE layout dependency
ykantser
parents:
25182
diff
changeset
|
93 |
System.getProperty("test.class.path", ""); |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
94 |
String testClassDir = System.getProperty("test.classes", "") + sep; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
95 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
96 |
// Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
97 |
String[] args = { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
98 |
"-classpath", |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
99 |
classpath, |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
100 |
"BasicTests$TestMain", |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24366
diff
changeset
|
101 |
Long.toString(pid), |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
102 |
testClassDir + "Agent.jar", |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
103 |
testClassDir + "BadAgent.jar", |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
104 |
testClassDir + "RedefineAgent.jar" }; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
105 |
OutputAnalyzer output = ProcessTools.executeTestJvm(args); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
106 |
output.shouldHaveExitValue(0); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
107 |
} |
2 | 108 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
109 |
/** |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
110 |
* Will build all jars needed by the tests. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
111 |
*/ |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
112 |
private static void buildJars() throws Throwable { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
113 |
String[] jars = {"Agent", "BadAgent", "RedefineAgent", "Application" }; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
114 |
for (String jar : jars) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
115 |
buildJar(jar); |
2 | 116 |
} |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
117 |
} |
2 | 118 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
119 |
/** |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
120 |
* Will build a jar with the given name. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
121 |
* Class file and manifest must already exist. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
122 |
* @param jarName Name of the jar. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
123 |
*/ |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
124 |
private static void buildJar(String jarName) throws Throwable { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
125 |
String testClasses = System.getProperty("test.classes", "?"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
126 |
String testSrc = System.getProperty("test.src", "?"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
127 |
String jar = String.format("%s/%s.jar", testClasses, jarName); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
128 |
String manifest = String.format("%s/%s.mf", testSrc, jarName.toLowerCase()); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
129 |
String clazz = String.format("%s.class", jarName); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
130 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
131 |
// Arguments to the jar command has this format: |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
132 |
// "-cfm TESTCLASSES/Agent.jar TESTSRC/agent.mf -C TESTCLASSES Agent.class" |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
133 |
RunnerUtil.createJar("-cfm", jar, manifest, "-C", testClasses, clazz); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
134 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
135 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
136 |
/** |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
137 |
* This is the actual test. It will attach to the running Application |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
138 |
* and perform a number of basic attach tests. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
139 |
*/ |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
140 |
public static class TestMain { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
141 |
public static void main(String args[]) throws Exception { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
142 |
String pid = args[0]; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
143 |
String agent = args[1]; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
144 |
String badagent = args[2]; |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
145 |
String redefineagent = args[3]; |
2 | 146 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
147 |
System.out.println(" - Attaching to application ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
148 |
VirtualMachine vm = VirtualMachine.attach(pid); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
149 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
150 |
// Test 1 - read the system properties from the target VM and |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
151 |
// check that property is set |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
152 |
System.out.println(" - Test: system properties in target VM"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
153 |
Properties props = vm.getSystemProperties(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
154 |
String value = props.getProperty("attach.test"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
155 |
if (value == null || !value.equals("true")) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
156 |
throw new RuntimeException("attach.test property not set"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
157 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
158 |
System.out.println(" - attach.test property set as expected"); |
2 | 159 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
160 |
// Test 1a - read the agent properties from the target VM. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
161 |
// By default, the agent property contains "sun.java.command", |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
162 |
// "sun.jvm.flags", and "sun.jvm.args". |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
163 |
// Just sanity check - make sure not empty. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
164 |
System.out.println(" - Test: agent properties in target VM"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
165 |
props = vm.getAgentProperties(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
166 |
if (props == null || props.size() == 0) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
167 |
throw new RuntimeException("Agent properties is empty"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
168 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
169 |
System.out.println(" - agent properties non-empty as expected"); |
2 | 170 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
171 |
// Test 2 - attempt to load an agent that does not exist |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
172 |
System.out.println(" - Test: Load an agent that does not exist"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
173 |
try { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
174 |
vm.loadAgent("SilverBullet.jar"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
175 |
} catch (AgentLoadException x) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
176 |
System.out.println(" - AgentLoadException thrown as expected!"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
177 |
} |
2 | 178 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
179 |
// Test 3 - load an "bad" agent (agentmain throws an exception) |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
180 |
System.out.println(" - Test: Load a bad agent"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
181 |
System.out.println("INFO: This test will cause error messages " |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
182 |
+ "to appear in the application log about SilverBullet.jar " |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
183 |
+ "not being found and an agent failing to start."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
184 |
try { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
185 |
vm.loadAgent(badagent); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
186 |
throw new RuntimeException( |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
187 |
"AgentInitializationException not thrown as expected!"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
188 |
} catch (AgentInitializationException x) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
189 |
System.out.println( |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
190 |
" - AgentInitializationException thrown as expected!"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
191 |
} |
2 | 192 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
193 |
// Test 4 - detach from the VM and attempt a load (should throw IOE) |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
194 |
System.out.println(" - Test: Detach from VM"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
195 |
System.out.println("INFO: This test will cause error messages " |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
196 |
+ "to appear in the application log about a BadAgent including " |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
197 |
+ "a RuntimeException and an InvocationTargetException."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
198 |
vm.detach(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
199 |
try { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
200 |
vm.loadAgent(agent); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
201 |
throw new RuntimeException("loadAgent did not throw an exception!!"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
202 |
} catch (IOException ioe) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
203 |
System.out.println(" - IOException as expected"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
204 |
} |
2 | 205 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
206 |
// Test 5 - functional "end-to-end" test. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
207 |
// Create a listener socket. Load Agent.jar into the target VM passing |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
208 |
// it the port number of our listener. When agent loads it should connect |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
209 |
// back to the tool. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
210 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
211 |
System.out.println(" - Re-attaching to application ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
212 |
vm = VirtualMachine.attach(pid); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
213 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
214 |
System.out.println(" - Test: End-to-end connection with agent"); |
2 | 215 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
216 |
ServerSocket ss = new ServerSocket(0); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
217 |
int port = ss.getLocalPort(); |
2 | 218 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
219 |
System.out.println(" - Loading Agent.jar into target VM ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
220 |
vm.loadAgent(agent, Integer.toString(port)); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
221 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
222 |
System.out.println(" - Waiting for agent to connect back to tool ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
223 |
Socket s = ss.accept(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
224 |
System.out.println(" - Connected to agent."); |
2 | 225 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
226 |
// Test 5b - functional "end-to-end" test. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
227 |
// Now with an agent that does redefine. |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
228 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
229 |
System.out.println(" - Re-attaching to application ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
230 |
vm = VirtualMachine.attach(pid); |
2 | 231 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
232 |
System.out.println(" - Test: End-to-end connection with RedefineAgent"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
233 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
234 |
ServerSocket ss2 = new ServerSocket(0); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
235 |
int port2 = ss2.getLocalPort(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
236 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
237 |
System.out.println(" - Loading RedefineAgent.jar into target VM ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
238 |
vm.loadAgent(redefineagent, Integer.toString(port2)); |
2 | 239 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
240 |
System.out.println(" - Waiting for RedefineAgent to connect back to tool ..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
241 |
Socket s2 = ss2.accept(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
242 |
System.out.println(" - Connected to RedefineAgent."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
243 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
244 |
// Test 6 - list method should list the target VM |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
245 |
System.out.println(" - Test: VirtualMachine.list"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
246 |
List<VirtualMachineDescriptor> l = VirtualMachine.list(); |
24268
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
247 |
boolean found = false; |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
248 |
for (VirtualMachineDescriptor vmd: l) { |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
249 |
if (vmd.id().equals(pid)) { |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
250 |
found = true; |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
251 |
break; |
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
252 |
} |
24268
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
253 |
} |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
254 |
if (found) { |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
255 |
System.out.println(" - " + pid + " found."); |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
256 |
} else { |
43fb1c9e594c
8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
sla
parents:
24120
diff
changeset
|
257 |
throw new RuntimeException(pid + " not found in VM list"); |
2 | 258 |
} |
259 |
||
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
260 |
// test 7 - basic hashCode/equals tests |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
261 |
System.out.println(" - Test: hashCode/equals"); |
2 | 262 |
|
21968
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
263 |
VirtualMachine vm1 = VirtualMachine.attach(pid); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
264 |
VirtualMachine vm2 = VirtualMachine.attach(pid); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
265 |
if (!vm1.equals(vm2)) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
266 |
throw new RuntimeException("virtual machines are not equal"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
267 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
268 |
if (vm.hashCode() != vm.hashCode()) { |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
269 |
throw new RuntimeException("virtual machine hashCodes not equal"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
270 |
} |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
271 |
System.out.println(" - hashCode/equals okay"); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
272 |
|
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
273 |
// --- |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
274 |
System.out.println(" - Cleaning up..."); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
275 |
s.close(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
276 |
ss.close(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
277 |
s2.close(); |
619035df6988
6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents:
9259
diff
changeset
|
278 |
ss2.close(); |
2 | 279 |
} |
280 |
} |
|
281 |
} |