41182
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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 |
|
|
24 |
import java.io.IOException;
|
|
25 |
import java.io.File;
|
|
26 |
import java.io.FileOutputStream;
|
|
27 |
import java.io.PrintStream;
|
|
28 |
import jdk.test.lib.process.OutputAnalyzer;
|
|
29 |
|
|
30 |
|
|
31 |
// This class contains common test utilities for CDS testing
|
|
32 |
public class CDSTestUtils {
|
|
33 |
|
|
34 |
// check result of 'dump' operation
|
|
35 |
public static void checkDump(OutputAnalyzer output, String... extraMatches)
|
|
36 |
throws Exception {
|
|
37 |
|
|
38 |
output.shouldContain("Loading classes to share");
|
|
39 |
output.shouldHaveExitValue(0);
|
|
40 |
|
|
41 |
for (String match : extraMatches) {
|
|
42 |
output.shouldContain(match);
|
|
43 |
}
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
// check the output for indication that mapping of the archive failed
|
|
48 |
public static boolean isUnableToMap(OutputAnalyzer output) {
|
|
49 |
String outStr = output.getOutput();
|
|
50 |
if ((output.getExitValue() == 1) && (
|
|
51 |
outStr.contains("Unable to reserve shared space at required address") ||
|
|
52 |
outStr.contains("Unable to map ReadOnly shared space at required address") ||
|
|
53 |
outStr.contains("Unable to map ReadWrite shared space at required address") ||
|
|
54 |
outStr.contains("Unable to map MiscData shared space at required address") ||
|
|
55 |
outStr.contains("Unable to map MiscCode shared space at required address") ||
|
|
56 |
outStr.contains("Unable to map shared string space at required address") ||
|
|
57 |
outStr.contains("Could not allocate metaspace at a compatible address") ||
|
|
58 |
outStr.contains("Unable to allocate shared string space: range is not within java heap") ))
|
|
59 |
{
|
|
60 |
return true;
|
|
61 |
}
|
|
62 |
|
|
63 |
return false;
|
|
64 |
}
|
|
65 |
|
|
66 |
// check result of 'exec' operation, that is when JVM is run using the archive
|
|
67 |
public static void checkExec(OutputAnalyzer output, String... extraMatches) throws Exception {
|
|
68 |
if (isUnableToMap(output)) {
|
|
69 |
System.out.println("Unable to map shared archive: test did not complete; assumed PASS");
|
|
70 |
return;
|
|
71 |
}
|
|
72 |
output.shouldContain("sharing");
|
|
73 |
output.shouldHaveExitValue(0);
|
|
74 |
|
|
75 |
for (String match : extraMatches) {
|
|
76 |
output.shouldContain(match);
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
// get the file object for the test artifact
|
|
82 |
private static File getTestArtifactFile(String prefix, String name) {
|
|
83 |
File dir = new File(System.getProperty("test.classes", "."));
|
|
84 |
return new File(dir, prefix + name);
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
// create file containing the specified class list
|
|
89 |
public static File makeClassList(String testCaseName, String classes[])
|
|
90 |
throws Exception {
|
|
91 |
|
|
92 |
File classList = getTestArtifactFile(testCaseName, "test.classlist");
|
|
93 |
FileOutputStream fos = new FileOutputStream(classList);
|
|
94 |
PrintStream ps = new PrintStream(fos);
|
|
95 |
|
|
96 |
addToClassList(ps, classes);
|
|
97 |
|
|
98 |
ps.close();
|
|
99 |
fos.close();
|
|
100 |
|
|
101 |
return classList;
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
private static void addToClassList(PrintStream ps, String classes[])
|
|
106 |
throws IOException
|
|
107 |
{
|
|
108 |
if (classes != null) {
|
|
109 |
for (String s : classes) {
|
|
110 |
ps.println(s);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
}
|