test/runtime/NMT/JcmdWithNMTDisabled.java

Thu, 27 Mar 2014 22:36:08 +0100

author
ctornqvi
date
Thu, 27 Mar 2014 22:36:08 +0100
changeset 8183
dce765c2ff7d
parent 7110
6640f982c1be
permissions
-rw-r--r--

8007890: [TESTBUG] JcmdWithNMTDisabled.java fails when invoked with NMT explicitly turned on
Summary: Wrapped the test in another layer process creation to avoid NMT being turned on.
Reviewed-by: coleenp, dcubed

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @key nmt jcmd
aoqi@0 27 * @summary Verify that jcmd correctly reports that NMT is not enabled
aoqi@0 28 * @library /testlibrary
ctornqvi@8183 29 * @run main JcmdWithNMTDisabled 1
aoqi@0 30 */
aoqi@0 31
aoqi@0 32 import com.oracle.java.testlibrary.*;
aoqi@0 33
aoqi@0 34 public class JcmdWithNMTDisabled {
aoqi@0 35 static ProcessBuilder pb = new ProcessBuilder();
aoqi@0 36 static String pid;
aoqi@0 37
aoqi@0 38 public static void main(String args[]) throws Exception {
ctornqvi@8183 39
ctornqvi@8183 40 // This test explicitly needs to be run with the exact command lines below, not passing on
ctornqvi@8183 41 // arguments from the parent VM is a conscious choice to avoid NMT being turned on.
ctornqvi@8183 42 if (args.length > 0) {
ctornqvi@8183 43 ProcessBuilder pb;
ctornqvi@8183 44 OutputAnalyzer output;
ctornqvi@8183 45 String testjdkPath = System.getProperty("test.jdk");
ctornqvi@8183 46
ctornqvi@8183 47 // First run without enabling NMT
ctornqvi@8183 48 pb = ProcessTools.createJavaProcessBuilder("-Dtest.jdk=" + testjdkPath, "JcmdWithNMTDisabled");
ctornqvi@8183 49 output = new OutputAnalyzer(pb.start());
ctornqvi@8183 50 output.shouldHaveExitValue(0);
ctornqvi@8183 51
ctornqvi@8183 52 // Then run with explicitly disabling NMT, should not be any difference
ctornqvi@8183 53 pb = ProcessTools.createJavaProcessBuilder("-Dtest.jdk=" + testjdkPath, "-XX:NativeMemoryTracking=off", "JcmdWithNMTDisabled");
ctornqvi@8183 54 output = new OutputAnalyzer(pb.start());
ctornqvi@8183 55 output.shouldHaveExitValue(0);
ctornqvi@8183 56
ctornqvi@8183 57 return;
ctornqvi@8183 58 }
ctornqvi@8183 59
aoqi@0 60 // Grab my own PID
aoqi@0 61 pid = Integer.toString(ProcessTools.getProcessId());
aoqi@0 62
aoqi@0 63 jcmdCommand("summary");
aoqi@0 64 jcmdCommand("detail");
aoqi@0 65 jcmdCommand("baseline");
aoqi@0 66 jcmdCommand("summary.diff");
aoqi@0 67 jcmdCommand("detail.diff");
aoqi@0 68 jcmdCommand("scale=GB");
aoqi@0 69 jcmdCommand("shutdown");
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 // Helper method for invoking different jcmd calls, all should fail with the same message saying NMT is not enabled
aoqi@0 73 public static void jcmdCommand(String command) throws Exception {
aoqi@0 74
aoqi@0 75 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", command});
aoqi@0 76 OutputAnalyzer output = new OutputAnalyzer(pb.start());
aoqi@0 77
aoqi@0 78 // Verify that jcmd reports that NMT is not enabled
aoqi@0 79 output.shouldContain("Native memory tracking is not enabled");
aoqi@0 80 }
aoqi@0 81 }

mercurial