14275
|
1 /*
|
|
2 * Copyright (c) 2014, 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 /*
|
|
25 * @test CdsWriteError
|
|
26 * @summary Test how VM handles situation when it is impossible to write the
|
|
27 * CDS archive. VM is expected to exit gracefully and display the
|
|
28 * correct reason for the error.
|
|
29 * @library /testlibrary
|
|
30 * @run main CdsWriteError
|
|
31 */
|
|
32
|
|
33 import com.oracle.java.testlibrary.*;
|
|
34 import java.io.File;
|
|
35
|
|
36 public class CdsWriteError {
|
|
37 public static void main(String[] args) throws Exception {
|
|
38
|
|
39 if (Platform.isWindows()) {
|
|
40 System.out.println("This test is ignored on Windows. This test " +
|
|
41 "manipulates folder writable attribute, which is known to be " +
|
|
42 "often ignored by Windows");
|
|
43
|
|
44 return;
|
|
45 }
|
|
46
|
|
47 String folderName = "tmp";
|
|
48 String fileName = folderName + File.separator + "empty.jsa";
|
|
49
|
|
50 // create an empty archive file and make it read only
|
|
51 File folder = new File(folderName);
|
|
52 if (!folder.mkdir())
|
|
53 throw new RuntimeException("Error when creating a tmp folder");
|
|
54
|
|
55 File cdsFile = new File(fileName);
|
|
56 if (!cdsFile.createNewFile())
|
|
57 throw new RuntimeException("Error when creating an empty CDS file");
|
|
58 if (!cdsFile.setWritable(false))
|
|
59 throw new RuntimeException("Error: could not set writable attribute on cds file");
|
|
60 if (!folder.setWritable(false))
|
|
61 throw new RuntimeException("Error: could not set writable attribute on the cds folder");
|
|
62
|
|
63 try {
|
|
64 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
|
65 "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + fileName, "-Xshare:dump");
|
|
66
|
|
67 OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
|
68 output.shouldContain("Unable to create shared archive file");
|
|
69 output.shouldHaveExitValue(1);
|
|
70 } finally {
|
|
71 // doing this, just in case, to make sure that files can be deleted by the harness
|
|
72 // on any subsequent run
|
|
73 folder.setWritable(true);
|
|
74 cdsFile.setWritable(true);
|
|
75 }
|
|
76 }
|
|
77 }
|
|
78
|