test/runtime/SharedArchiveFile/ArchiveDoesNotExist.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -31,11 +31,12 @@
* @modules java.base/jdk.internal.misc
* java.management
* @run main ArchiveDoesNotExist
*/
-import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import java.io.File;
public class ArchiveDoesNotExist {
public static void main(String[] args) throws Exception {
@@ -43,29 +44,24 @@
File cdsFile = new File(fileName);
if (cdsFile.exists())
throw new RuntimeException("Test error: cds file already exists");
- // Sharing: on
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
- "-XX:+UnlockDiagnosticVMOptions",
- "-XX:SharedArchiveFile=./" + fileName,
- "-Xshare:on",
- "-version");
-
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
- output.shouldContain("Specified shared archive not found");
- output.shouldHaveExitValue(1);
-
- // Sharing: auto
- pb = ProcessTools.createJavaProcessBuilder(
- "-XX:+UnlockDiagnosticVMOptions",
- "-XX:SharedArchiveFile=./" + fileName,
- "-Xshare:auto",
- "-version");
-
- output = new OutputAnalyzer(pb.start());
- output.shouldMatch("(java|openjdk) version");
- output.shouldNotContain("sharing");
- output.shouldHaveExitValue(0);
+ CDSOptions opts = (new CDSOptions()).setArchiveName(fileName);
+
+ // -Xshare=on
+ OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
+ if (!CDSTestUtils.isUnableToMap(out)) {
+ out.shouldContain("Specified shared archive not found")
+ .shouldHaveExitValue(1);
+ }
+
+ // -Xshare=auto
+ opts.setXShareMode("auto");
+ out = CDSTestUtils.runWithArchive(opts);
+ if (!CDSTestUtils.isUnableToMap(out)) {
+ out.shouldMatch("(java|openjdk) version")
+ .shouldNotContain("sharing")
+ .shouldHaveExitValue(0);
+ }
}
}