22 */ |
22 */ |
23 |
23 |
24 import java.io.IOException; |
24 import java.io.IOException; |
25 import java.io.File; |
25 import java.io.File; |
26 import java.nio.file.Files; |
26 import java.nio.file.Files; |
27 import java.nio.file.Path; |
|
28 import java.util.Arrays; |
27 import java.util.Arrays; |
29 import java.util.regex.Pattern; |
28 import java.util.regex.Pattern; |
30 import java.util.regex.Matcher; |
29 import java.util.regex.Matcher; |
|
30 |
31 import jdk.testlibrary.OutputAnalyzer; |
31 import jdk.testlibrary.OutputAnalyzer; |
32 import jdk.testlibrary.JDKToolLauncher; |
|
33 import jdk.testlibrary.ProcessTools; |
32 import jdk.testlibrary.ProcessTools; |
34 import jdk.testlibrary.Utils; |
33 import jdk.testlibrary.Utils; |
35 import jdk.testlibrary.ProcessThread; |
34 import jdk.testlibrary.ProcessThread; |
36 |
35 |
37 /* |
36 /* |
38 * Utility functions for test runners. |
37 * Utility functions for test runners. |
39 * (Test runner = class that launch a test) |
38 * (Test runner = class that launch a test) |
40 */ |
39 */ |
41 public class RunnerUtil { |
40 public class RunnerUtil { |
|
41 |
42 /** |
42 /** |
43 * The Application process must be run concurrently with our tests since |
43 * The Application process must be run concurrently with our tests since |
44 * the tests will attach to the Application. |
44 * the tests will attach to the Application. |
45 * We will run the Application process in a separate thread. |
45 * We will run the Application process in a separate thread. |
46 * |
46 * |
47 * The Application must be started with flag "-Xshare:off" for the Retransform |
47 * The Application must be started with flag "-Xshare:off" for the Retransform |
48 * test in TestBasics to pass on all platforms. |
48 * test in TestBasics to pass on all platforms. |
49 * |
49 * |
50 * The Application will write its pid and shutdownPort in the given outFile. |
50 * The Application will write its pid and shutdownPort in the given outFile. |
51 */ |
51 */ |
52 public static ProcessThread startApplication(String outFile) throws Throwable { |
52 public static ProcessThread startApplication(String outFile, String... additionalOpts) throws Throwable { |
53 String classpath = System.getProperty("test.class.path", "."); |
53 String classpath = System.getProperty("test.class.path", "."); |
54 String[] args = Utils.addTestJavaOpts( |
54 String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application", outFile }); |
55 "-Dattach.test=true", "-classpath", classpath, "Application", outFile); |
55 String[] args = Utils.addTestJavaOpts(myArgs); |
56 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); |
56 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); |
57 ProcessThread pt = new ProcessThread("runApplication", pb); |
57 ProcessThread pt = new ProcessThread("runApplication", pb); |
58 pt.start(); |
58 pt.start(); |
59 return pt; |
59 return pt; |
60 } |
60 } |
|
61 |
|
62 public static String[] concat(String[] a, String[] b) { |
|
63 if (a == null) { |
|
64 return b; |
|
65 } |
|
66 if (b == null) { |
|
67 return a; |
|
68 } |
|
69 int aLen = a.length; |
|
70 int bLen = b.length; |
|
71 String[] c = new String[aLen + bLen]; |
|
72 System.arraycopy(a, 0, c, 0, aLen); |
|
73 System.arraycopy(b, 0, c, aLen, bLen); |
|
74 return c; |
|
75 } |
61 |
76 |
62 /** |
77 /** |
63 * Will stop the running Application. |
78 * Will stop the running Application. |
64 * First tries to shutdown nicely by connecting to the shut down port. |
79 * First tries to shutdown nicely by connecting to the shut down port. |
65 * If that fails, the process will be killed hard with stopProcess(). |
80 * If that fails, the process will be killed hard with stopProcess(). |