test/hotspot/jtreg/serviceability/dcmd/vm/EventsTest.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import jdk.test.lib.dcmd.CommandExecutor;
       
    25 import jdk.test.lib.dcmd.JMXExecutor;
       
    26 import jdk.test.lib.process.OutputAnalyzer;
       
    27 import org.testng.annotations.Test;
       
    28 
       
    29 /*
       
    30  * @test
       
    31  * @summary Test of diagnostic command VM.events
       
    32  * @library /test/lib
       
    33  * @modules java.base/jdk.internal.misc
       
    34  *          java.compiler
       
    35  *          java.management
       
    36  *          jdk.internal.jvmstat/sun.jvmstat.monitor
       
    37  * @run testng  EventsTest
       
    38  */
       
    39 public class EventsTest {
       
    40 
       
    41     static String buildHeaderPattern(String logname) {
       
    42         return "^" + logname + ".*\\(\\d+ events\\):";
       
    43     }
       
    44 
       
    45     public void run_all(CommandExecutor executor) {
       
    46         OutputAnalyzer output = executor.execute("VM.events");
       
    47         // This tests for the output to contain the event log header line (e.g. "Classes unloaded (0 events):").
       
    48         // Those are always printed even if the corresponding event log is empty.
       
    49         output.stdoutShouldMatch(buildHeaderPattern("Events"));
       
    50         output.stdoutShouldMatch(buildHeaderPattern("Compilation"));
       
    51         output.stdoutShouldMatch(buildHeaderPattern("GC Heap History"));
       
    52         output.stdoutShouldMatch(buildHeaderPattern("Deoptimization"));
       
    53         output.stdoutShouldMatch(buildHeaderPattern("Classes unloaded"));
       
    54     }
       
    55 
       
    56     public void run_selected(CommandExecutor executor) {
       
    57         OutputAnalyzer output = executor.execute("VM.events log=deopt");
       
    58         // We only expect one log to be printed here.
       
    59         output.stdoutShouldMatch(buildHeaderPattern("Deoptimization"));
       
    60 
       
    61         output.stdoutShouldNotMatch(buildHeaderPattern("Events"));
       
    62         output.stdoutShouldNotMatch(buildHeaderPattern("Compilation"));
       
    63         output.stdoutShouldNotMatch(buildHeaderPattern("GC Heap History"));
       
    64         output.stdoutShouldNotMatch(buildHeaderPattern("Classes unloaded"));
       
    65     }
       
    66 
       
    67     @Test
       
    68     public void jmx() {
       
    69         run_all(new JMXExecutor());
       
    70         run_selected(new JMXExecutor());
       
    71     }
       
    72 }