Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/compiler/CompilerDirectivesDCMDTest.java
41153 views
/*1* Copyright (c) 2015, 2016, 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* @test CompilerDirectivesDCMDTest25* @bug 813716726* @library /test/lib27* @modules java.base/jdk.internal.misc28* java.compiler29* java.management30* @run testng/othervm CompilerDirectivesDCMDTest31* @summary Test of diagnostic command32*/3334import jdk.test.lib.process.OutputAnalyzer;35import jdk.test.lib.dcmd.CommandExecutor;36import jdk.test.lib.dcmd.JMXExecutor;37import jdk.test.lib.Platform;38import org.testng.annotations.Test;39import org.testng.Assert;4041import java.io.BufferedReader;42import java.io.File;43import java.io.StringReader;4445public class CompilerDirectivesDCMDTest {4647public static String filename;4849public void run(CommandExecutor executor) {5051if (Platform.isServer() && !Platform.isEmulatedClient()) {52filename = System.getProperty("test.src", ".") + File.separator + "control2.txt";53} else {54filename = System.getProperty("test.src", ".") + File.separator + "control1.txt";55}56testPrintCommand(executor);57testAddAndRemoveCommand(executor);58}5960public static void testPrintCommand(CommandExecutor executor) {6162// Get output from dcmd (diagnostic command)63OutputAnalyzer output = executor.execute("Compiler.directives_print");64int count = find(output, "Directive:");65if (count < 1) {66Assert.fail("Expected at least one directive - found " + count);67}68}6970public static void testAddAndRemoveCommand(CommandExecutor executor) {71OutputAnalyzer output;72int count = 0;7374// Start with clearing stack - expect only default directive left75output = executor.execute("Compiler.directives_clear");76output = executor.execute("Compiler.directives_print");77count = find(output, "Directive:");78if (count != 1) {79Assert.fail("Expected one directives - found " + count);80}8182// Test that we can not remove the default directive83output = executor.execute("Compiler.directives_remove");84output = executor.execute("Compiler.directives_print");85count = find(output, "Directive:");86if (count != 1) {87Assert.fail("Expected one directives - found " + count);88}8990// Test adding some directives from file91output = executor.execute("Compiler.directives_add " + filename);92output = executor.execute("Compiler.directives_print");93count = find(output, "Directive:");94if (count != 3) {95Assert.fail("Expected three directives - found " + count);96}9798// Test remove one directive99output = executor.execute("Compiler.directives_remove");100output = executor.execute("Compiler.directives_print");101count = find(output, "Directive:");102if (count != 2) {103Assert.fail("Expected two directives - found " + count);104}105106// Test adding directives again107output = executor.execute("Compiler.directives_add " + filename);108output = executor.execute("Compiler.directives_print");109count = find(output, "Directive:");110if (count != 4) {111Assert.fail("Expected four directives - found " + count);112}113114// Test clearing115output = executor.execute("Compiler.directives_clear");116output = executor.execute("Compiler.directives_print");117count = find(output, "Directive:");118if (count != 1) {119Assert.fail("Expected one directives - found " + count);120}121122// Test clear when already cleared123output = executor.execute("Compiler.directives_clear");124output = executor.execute("Compiler.directives_print");125count = find(output, "Directive:");126if (count != 1) {127Assert.fail("Expected one directives - found " + count);128}129130// Test remove one directive when empty131output = executor.execute("Compiler.directives_remove");132output = executor.execute("Compiler.directives_print");133count = find(output, "Directive:");134if (count != 1) {135Assert.fail("Expected one directive - found " + count);136}137}138139public static int find(OutputAnalyzer output, String find) {140int count = 0;141142for (String line : output.asLines()) {143if (line.startsWith(find)) {144count++;145}146}147return count;148}149150@Test151public void jmx() {152run(new JMXExecutor());153}154}155156157