Path: blob/master/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
41149 views
/*1* Copyright (c) 2017, 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 jdk.test.lib.apps.LingeredApp;24import jdk.test.lib.JDKToolLauncher;25import jdk.test.lib.process.OutputAnalyzer;26import jdk.test.lib.SA.SATestUtils;27import jdk.test.lib.Utils;2829/**30* @test31* @requires vm.hasSA32* @library /test/lib33* @run main JhsdbThreadInfoTest34*/35public class JhsdbThreadInfoTest {3637public static void main(String[] args) throws Exception {38SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.39LingeredApp app = null;4041try {42app = LingeredApp.startApp();43System.out.println("Started LingeredApp with pid " + app.getPid());4445JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");46jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion"));4748jhsdbLauncher.addToolArg("jstack");49jhsdbLauncher.addToolArg("--pid");50jhsdbLauncher.addToolArg(Long.toString(app.getPid()));5152ProcessBuilder pb = SATestUtils.createProcessBuilder(jhsdbLauncher);53Process jhsdb = pb.start();5455OutputAnalyzer out = new OutputAnalyzer(jhsdb);5657jhsdb.waitFor();5859System.out.println(out.getStdout());60System.err.println(out.getStderr());6162out.shouldMatch("\".+\" #\\d+ daemon prio=\\d+ tid=0x[0-9a-f]+ nid=0x[0-9a-f]+ .+ \\[0x[0-9a-f]+]");63out.shouldMatch("\"main\" #\\d+ prio=\\d+ tid=0x[0-9a-f]+ nid=0x[0-9a-f]+ .+ \\[0x[0-9a-f]+]");64out.shouldMatch(" java.lang.Thread.State: .+");65out.shouldMatch(" JavaThread state: _thread_.+");6667out.shouldNotContain(" prio=0 ");68out.shouldNotContain(" java.lang.Thread.State: UNKNOWN");6970out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();7172System.out.println("Test Completed");73} catch (Exception ex) {74throw new RuntimeException("Test ERROR " + ex, ex);75} finally {76LingeredApp.stopApp(app);77}78}79}808182