test/jdk/sun/tools/jps/TestJpsSanity.java
author iklam
Wed, 13 Nov 2019 19:55:11 -0800
changeset 59072 b987ea528c21
parent 51840 dc15e45122b2
permissions -rw-r--r--
8234133: VM build broken due to memory/archiveUtils.inline.hpp Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     1
/*
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     4
 *
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     7
 * published by the Free Software Foundation.
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     8
 *
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    13
 * accompanied this code).
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    14
 *
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    18
 *
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    21
 * questions.
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    22
 */
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    23
51840
dc15e45122b2 8210894: remove jdk/testlibrary/Asserts
iignatyev
parents: 51675
diff changeset
    24
import jdk.test.lib.Asserts;
51675
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 48543
diff changeset
    25
import jdk.test.lib.process.OutputAnalyzer;
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    26
import jdk.test.lib.apps.LingeredApp;
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    27
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    28
/*
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    29
 * @test
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    30
 * @summary This test verifies jps usage and checks that appropriate error message is shown
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    31
 *          when running jps with illegal arguments.
51840
dc15e45122b2 8210894: remove jdk/testlibrary/Asserts
iignatyev
parents: 51675
diff changeset
    32
 * @library /test/lib
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 25987
diff changeset
    33
 * @modules jdk.jartool/sun.tools.jar
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 25987
diff changeset
    34
 *          java.management
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    35
 *          java.base/jdk.internal.misc
51840
dc15e45122b2 8210894: remove jdk/testlibrary/Asserts
iignatyev
parents: 51675
diff changeset
    36
 * @build jdk.test.lib.apps.* JpsHelper
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    37
 * @run driver TestJpsSanity
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    38
 */
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    39
public class TestJpsSanity {
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    40
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    41
    public static void main(String[] args) throws Throwable {
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    42
        testJpsUsage();
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    43
        testJpsVersion();
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    44
        testJpsUnknownHost();
38956
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    45
        testJpsShort();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    46
        testJpsLong();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    47
        testJpsShortPkg();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    48
        testJpsLongPkg();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    49
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    50
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    51
    private static void testJpsShort() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    52
        OutputAnalyzer output = JpsHelper.jps();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    53
        output.shouldMatch("^[0-9]+ Jps$");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    54
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    55
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    56
    private static void testJpsLong() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    57
        OutputAnalyzer output = JpsHelper.jps("-l");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    58
        output.shouldMatch("^[0-9]+ jdk\\.jcmd/sun\\.tools\\.jps\\.Jps$");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    59
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    60
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    61
    private static void testJpsShortPkg() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    62
        LingeredApp app = null;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    63
        try {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    64
            app = LingeredApp.startApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    65
            OutputAnalyzer output = JpsHelper.jps();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    66
            output.shouldMatch("^[0-9]+ LingeredApp$");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    67
        } finally {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    68
            LingeredApp.stopApp(app);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    69
        }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    70
    }
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    71
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    72
    private static void testJpsLongPkg() throws Exception {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    73
        LingeredApp app = null;
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    74
        try {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    75
            app = LingeredApp.startApp();
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    76
            OutputAnalyzer output = JpsHelper.jps("-l");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    77
            output.shouldMatch("^[0-9]+ jdk\\.test\\.lib\\.apps\\.LingeredApp$");
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    78
        } finally {
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    79
            LingeredApp.stopApp(app);
cf2c4bfba78a 8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents: 34715
diff changeset
    80
        }
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    81
    }
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    82
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    83
    private static void testJpsUsage() throws Exception {
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    84
        OutputAnalyzer output = JpsHelper.jps("-?");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    85
        JpsHelper.verifyOutputAgainstFile(output);
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    86
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
    87
        output = JpsHelper.jps("-h");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
    88
        JpsHelper.verifyOutputAgainstFile(output);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
    89
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
    90
        output = JpsHelper.jps("--help");
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    91
        JpsHelper.verifyOutputAgainstFile(output);
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    92
    }
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    93
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    94
    private static void testJpsVersion() throws Exception {
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    95
        OutputAnalyzer output = JpsHelper.jps("-version");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    96
        Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    97
        Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    98
        output.shouldContain("illegal argument: -version");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
    99
    }
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   100
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   101
    private static void testJpsUnknownHost() throws Exception {
42101
e75889484926 8165500: TestJpsJar shouldn't jar all test.classpath directories
dsamersoff
parents: 40686
diff changeset
   102
        String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C.invalid";
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   103
        OutputAnalyzer output = JpsHelper.jps(invalidHostName);
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   104
        Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   105
        Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");
34715
efac989a60dd 8145417: JInfoSanityTest failed with Error attaching to remote server: java.rmi.ConnectException: Connection refused
jbachorik
parents: 30376
diff changeset
   106
        output.shouldMatch(".*(RMI Registry not available at|Unknown host\\:) " + invalidHostName + ".*");
25987
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   107
    }
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   108
76e62811f63b 8054278: Refactor jps utility tests
ykantser
parents:
diff changeset
   109
}