test/hotspot/jtreg/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java
author shade
Thu, 30 Nov 2017 17:13:33 +0100
branchepsilon-gc-branch
changeset 55934 912c55e702d6
parent 47216 71c04702a3d5
child 48469 7312ae4465d6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     1
/*
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     4
 *
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     8
 *
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    13
 * accompanied this code).
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    14
 *
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    18
 *
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    21
 * questions.
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    22
 */
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    23
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 46417
diff changeset
    24
/**
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    25
 * @test
46779
d80ca591ae48 8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents: 46417
diff changeset
    26
 * @requires vm.cds
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    27
 * @bug 8066670
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    28
 * @summary Testing -XX:+PrintSharedArchiveAndExit option
46417
1593c061e6af 8179243: [TESTBUG] CDS tests should be excluded from running with -UseCompressedOops
mseledtsov
parents: 46389
diff changeset
    29
 * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    30
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36508
diff changeset
    31
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28017
diff changeset
    32
 *          java.management
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    33
 */
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    34
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    35
import jdk.test.lib.cds.CDSOptions;
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    36
import jdk.test.lib.cds.CDSTestUtils;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    38
import jdk.test.lib.process.OutputAnalyzer;
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    39
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    40
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    41
public class PrintSharedArchiveAndExit {
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    42
    public static void main(String[] args) throws Exception {
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    43
        String archiveName = "PrintSharedArchiveAndExit.jsa";
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    44
        CDSOptions opts = (new CDSOptions()).setArchiveName(archiveName);
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    45
        OutputAnalyzer out = CDSTestUtils.createArchive(opts);
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    46
        CDSTestUtils.checkDump(out);
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    47
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    48
        // (1) With a valid archive
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    49
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    50
                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    51
                "-XX:+PrintSharedArchiveAndExit", "-version");
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    52
        out = CDSTestUtils.executeAndLog(pb, "print-shared-archive-and-version");
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    53
        if (!CDSTestUtils.isUnableToMap(out)) {
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    54
            out.shouldContain("archive is valid")
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    55
                .shouldNotContain("java version")     // Should not print JVM version
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    56
                .shouldHaveExitValue(0);              // Should report success in error code.
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    57
        }
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    58
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    59
        pb = ProcessTools.createJavaProcessBuilder(
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    60
                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    61
                "-XX:+PrintSharedArchiveAndExit");
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    62
        out = CDSTestUtils.executeAndLog(pb, "print-shared-archive");
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    63
        if (!CDSTestUtils.isUnableToMap(out)) {
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    64
            out.shouldContain("archive is valid")
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    65
                .shouldNotContain("Usage:")           // Should not print JVM help message
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    66
                .shouldHaveExitValue(0);               // Should report success in error code.
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 40631
diff changeset
    67
        }
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    68
    }
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents:
diff changeset
    69
}