author | goetz |
Mon, 14 Jan 2019 00:00:00 +0100 | |
changeset 53273 | bbc79e0ec9ee |
parent 51987 | c4010f88ea68 |
permissions | -rw-r--r-- |
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
1 |
/* |
53273
bbc79e0ec9ee
8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents:
51987
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
4 |
* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
8 |
* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
13 |
* accompanied this code). |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
14 |
* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
18 |
* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
21 |
* questions. |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
22 |
*/ |
2 | 23 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
24 |
/* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
25 |
* @test |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
26 |
* @bug 6225664 6220618 |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
27 |
* @summary Test for when private transport library outside jdk |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
28 |
* @comment converted from test/jdk/com/sun/jdi/PrivateTransportTest.sh |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
29 |
* |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
30 |
* @library /test/lib |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
31 |
* @run compile -g HelloWorld.java |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
32 |
* @build PrivateTransportTest |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
33 |
* @run main/othervm PrivateTransportTest |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
34 |
*/ |
2 | 35 |
|
53273
bbc79e0ec9ee
8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents:
51987
diff
changeset
|
36 |
import jdk.test.lib.Platform; |
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
37 |
import jdk.test.lib.Utils; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
38 |
import jdk.test.lib.process.ProcessTools; |
2 | 39 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
40 |
import java.io.IOException; |
53273
bbc79e0ec9ee
8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents:
51987
diff
changeset
|
41 |
import java.io.File; |
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
42 |
import java.nio.file.Files; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
43 |
import java.nio.file.Path; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
44 |
import java.nio.file.Paths; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
45 |
import java.util.Map; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
46 |
import java.util.Optional; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
47 |
import java.util.stream.Stream; |
2 | 48 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
49 |
public class PrivateTransportTest { |
2 | 50 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
51 |
public static void main(String argv[]) throws Throwable { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
52 |
new PrivateTransportTest() |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
53 |
.test(); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
54 |
} |
2 | 55 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
56 |
private final Path transportLib; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
57 |
private final String pathEnvVar; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
58 |
private final String pathSep; |
2 | 59 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
60 |
private static boolean isTransportLib(Path path) { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
61 |
String fileName = path.getFileName().toString().toLowerCase(); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
62 |
return fileName.equals("dt_socket.dll") |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
63 |
|| fileName.equals("libdt_socket.so") |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
64 |
|| fileName.equals("libdt_socket.dylib"); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
65 |
} |
2 | 66 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
67 |
private PrivateTransportTest() throws IOException { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
68 |
Path jdkRoot = Paths.get(Utils.TEST_JDK); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
69 |
try (Stream<Path> files = Files.find(jdkRoot, 5, (path, attr) -> isTransportLib(path.getFileName()))) { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
70 |
Optional<Path> foundLib = files.findAny(); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
71 |
if (!foundLib.isPresent()) { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
72 |
throw new RuntimeException("cannot find dt_socket lib"); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
73 |
} |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
74 |
transportLib = foundLib.get(); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
75 |
} |
53273
bbc79e0ec9ee
8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents:
51987
diff
changeset
|
76 |
pathEnvVar = Platform.sharedLibraryPathVariableName(); |
bbc79e0ec9ee
8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents:
51987
diff
changeset
|
77 |
pathSep = File.pathSeparator; |
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
78 |
} |
2 | 79 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
80 |
private void test() throws Throwable { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
81 |
// copy existing dt_socket lib to <CLASSES>/private_dt_socket |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
82 |
String libName = transportLib.getFileName().toString().replace("dt_socket", "private_dt_socket"); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
83 |
Files.copy(transportLib, Paths.get(Utils.TEST_CLASSES).resolve(libName)); |
2 | 84 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
85 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
86 |
"-agentlib:jdwp=transport=private_dt_socket,server=y,suspend=n", |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
87 |
"-classpath", Utils.TEST_CLASSES, |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
88 |
"HelloWorld"); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
89 |
Map<String, String> env = pb.environment(); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
90 |
String pathValue = env.get(pathEnvVar); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
91 |
if (pathValue == null) { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
92 |
pathValue = Utils.TEST_CLASSES; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
93 |
} else { |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
94 |
pathValue = pathValue + pathSep + Utils.TEST_CLASSES; |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
95 |
} |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
96 |
env.put(pathEnvVar, pathValue); |
2 | 97 |
|
51987
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
98 |
ProcessTools.executeCommand(pb) |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
99 |
.shouldHaveExitValue(0); |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
100 |
} |
c4010f88ea68
8203928: [Test] Convert non-JDB scaffolding serviceability shell script tests to java
amenkov
parents:
47216
diff
changeset
|
101 |
} |