Path: blob/master/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/TestJcmdOutput.java
41153 views
/*1* Copyright (c) 2015, 2021, 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*/2223/*24* @test25* @summary Verify jcmd error message for out-of-range value and for26* value which is not allowed by constraint. Also check that27* jcmd does not print an error message to the target process output.28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* jdk.management32* @run driver TestJcmdOutput33*/3435import jdk.test.lib.Asserts;36import jdk.test.lib.management.DynamicVMOption;37import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.dcmd.PidJcmdExecutor;4041public class TestJcmdOutput {4243/* Message printed by jcmd for value which is out-of-range */44static final String JCMD_OUT_OF_RANGE_MESSAGE = "error: must have value in range";45/* Message printed by jcmd for value which is not allowed by constraint */46static final String JCMD_CONSTRAINT_MESSAGE = "value violates its flag's constraint";4748public static void main(String[] args) throws Exception {49OutputAnalyzer output;5051System.out.println("Verify jcmd error message and that jcmd does not write errors to the target process output");52output = new OutputAnalyzer((ProcessTools.createJavaProcessBuilder(53"-Dtest.jdk=" + System.getProperty("test.jdk"),54"-XX:MinHeapFreeRatio=20", "-XX:MaxHeapFreeRatio=80", runJcmd.class.getName())).start());5556output.shouldHaveExitValue(0);57/* Verify that jcmd not print error message to the target process output */58output.shouldNotContain(JCMD_OUT_OF_RANGE_MESSAGE);59output.shouldNotContain(JCMD_CONSTRAINT_MESSAGE);60}6162public static class runJcmd {6364public static void main(String[] args) throws Exception {65int minHeapFreeRatio = Integer.valueOf((new DynamicVMOption("MinHeapFreeRatio")).getValue());66int maxHeapFreeRatio = Integer.valueOf((new DynamicVMOption("MaxHeapFreeRatio")).getValue());67PidJcmdExecutor executor = new PidJcmdExecutor();6869Asserts.assertGT(minHeapFreeRatio, 0, "MinHeapFreeRatio must be greater than 0");70Asserts.assertLT(maxHeapFreeRatio, 100, "MaxHeapFreeRatio must be less than 100");7172/* Check out-of-range values */73executor.execute("VM.set_flag MinHeapFreeRatio -1", true).shouldContain(JCMD_OUT_OF_RANGE_MESSAGE);74executor.execute("VM.set_flag MaxHeapFreeRatio 101", true).shouldContain(JCMD_OUT_OF_RANGE_MESSAGE);7576/* Check values which not allowed by constraint */77executor.execute(78String.format("VM.set_flag MinHeapFreeRatio %d", maxHeapFreeRatio + 1), true)79.shouldContain(JCMD_CONSTRAINT_MESSAGE);80executor.execute(81String.format("VM.set_flag MaxHeapFreeRatio %d", minHeapFreeRatio - 1), true)82.shouldContain(JCMD_CONSTRAINT_MESSAGE);83}84}85}868788