author | xuelei |
Fri, 14 Sep 2018 20:30:28 -0700 | |
changeset 51755 | 6c394ed56b07 |
parent 50525 | 767cdb97f103 |
child 51949 | 2a1e47af3c6b |
permissions | -rw-r--r-- |
48154
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
1 |
/* |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
4 |
* |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
8 |
* |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
13 |
* accompanied this code). |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
14 |
* |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
18 |
* |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
21 |
* questions. |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
22 |
*/ |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
23 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
24 |
/* @test TestAllocateHeapAtError.java |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
25 |
* @key gc |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
26 |
* @summary Test to check correct handling of non-existent directory passed to AllocateHeapAt option |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
48154
diff
changeset
|
27 |
* @requires vm.gc != "Z" |
48154
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
28 |
* @library /test/lib |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
29 |
* @modules java.base/jdk.internal.misc |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
30 |
*/ |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
31 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
32 |
import java.io.File; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
33 |
import jdk.test.lib.JDKToolFinder; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
34 |
import jdk.test.lib.process.ProcessTools; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
35 |
import jdk.test.lib.process.OutputAnalyzer; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
37 |
import java.util.Collections; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
38 |
import java.util.UUID; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
39 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
40 |
public class TestAllocateHeapAtError { |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
41 |
public static void main(String args[]) throws Exception { |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
42 |
ArrayList<String> vmOpts = new ArrayList(); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
43 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
44 |
String testVmOptsStr = System.getProperty("test.java.opts"); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
45 |
if (!testVmOptsStr.isEmpty()) { |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
46 |
String[] testVmOpts = testVmOptsStr.split(" "); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
47 |
Collections.addAll(vmOpts, testVmOpts); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
48 |
} |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
49 |
String test_dir = System.getProperty("test.dir", "."); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
50 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
51 |
File f = null; |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
52 |
do { |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
53 |
f = new File(test_dir, UUID.randomUUID().toString()); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
54 |
} while(f.exists()); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
55 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
56 |
Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + f.getName(), |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
57 |
"-Xlog:gc+heap=info", |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
58 |
"-Xmx32m", |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
59 |
"-Xms32m", |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
60 |
"-version"}); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
61 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
62 |
System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java")); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
63 |
for (int i = 0; i < vmOpts.size(); i += 1) { |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
64 |
System.out.print(" " + vmOpts.get(i)); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
65 |
} |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
66 |
System.out.println(); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
67 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
68 |
ProcessBuilder pb = |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
69 |
ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()])); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
70 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
71 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
72 |
System.out.println("Output:\n" + output.getOutput()); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
73 |
|
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
74 |
output.shouldContain("Could not create file for Heap"); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
75 |
output.shouldContain("Error occurred during initialization of VM"); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
76 |
output.shouldNotHaveExitValue(0); |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
77 |
} |
dea4d68f1340
8190980: Develop test cases and collect test pass rate
kkharbas
parents:
diff
changeset
|
78 |
} |