Path: blob/master/test/jdk/sun/tools/jinfo/BasicJInfoTest.java
41149 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.Arrays;2425import jdk.test.lib.JDKToolLauncher;26import jdk.test.lib.Utils;27import jdk.test.lib.process.OutputAnalyzer;28import jdk.test.lib.process.ProcessTools;2930/*31* @test32* @summary Unit test for jinfo utility33* @library /test/lib34* @run main BasicJInfoTest35*/36public class BasicJInfoTest {3738private static ProcessBuilder processBuilder = new ProcessBuilder();3940public static void main(String[] args) throws Exception {41testJinfoNoArgs();42testJinfoFlags();43testJinfoProps();44testJinfoFlagInvalid();45}4647private static void testJinfoNoArgs() throws Exception {48OutputAnalyzer output = jinfo();49output.shouldContain("-XX");50output.shouldContain("test.jdk=");51output.shouldHaveExitValue(0);52}5354private static void testJinfoFlagInvalid() throws Exception {55OutputAnalyzer output = jinfo("-flag");56output.shouldHaveExitValue(1);57}5859private static void testJinfoFlags() throws Exception {60OutputAnalyzer output = jinfo("-flags");61output.shouldContain("-XX");62output.shouldHaveExitValue(0);63}6465private static void testJinfoProps() throws Exception {66OutputAnalyzer output = jinfo("-props");67output.shouldContain("test.jdk=");68output.shouldHaveExitValue(0);69}7071private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {72JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");73launcher.addVMArgs(Utils.getTestJavaOpts());74if (toolArgs != null) {75for (String toolArg : toolArgs) {76launcher.addToolArg(toolArg);77}78}79launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));8081processBuilder.command(launcher.getCommand());82System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));83OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);84System.out.println(output.getOutput());8586return output;87}8889}909192