Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8215568: Refactor SA clhsdb tests to use ClhsdbLauncher #381

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -79,7 +79,7 @@ public static void main(String[] args) throws Exception {
// words[0] and words[1] represent the start and end addresses
String cmd = "scanoops " + words[0] + " " + words[1];
expStrMap = new HashMap<>();
expStrMap.put(cmd, List.of("[Ljava/lang/String"));
expStrMap.put(cmd, List.of("\\[Ljava/lang/String"));
test.run(theApp.getPid(), List.of(cmd), expStrMap, null);
} catch (SkippedException e) {
throw e;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -179,7 +179,7 @@ public static void main(String[] args) throws Exception {
"_nofast_getfield",
"_nofast_putfield",
"Constant Pool of",
"public static void main(java.lang.String[])",
"public static void main\\(java.lang.String\\[\\]\\)",
"Bytecode",
"invokevirtual",
"checkcast",
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,7 @@ public static void main(String[] args) throws Exception {
"_nofast_getfield",
"_nofast_putfield",
"Constant Pool of",
"public static void main(java.lang.String[])",
"public static void main\\(java.lang.String\\[\\]\\)",
"Bytecode",
"invokevirtual",
"checkcast",
@@ -27,7 +27,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;

/**
@@ -69,7 +69,7 @@ public static void main(String[] args) throws Exception {
"instance of Oop for java/lang/Class");
tokensMap.put("Method*=", "Type is Method");
tokensMap.put("(a java.lang.ref.ReferenceQueue$Lock)",
"instance of Oop for java/lang/ref/ReferenceQueue$Lock");
"instance of Oop for java/lang/ref/ReferenceQueue\\$Lock");

String[] lines = jstackOutput.split("\\R");

@@ -77,14 +77,15 @@ public static void main(String[] args) throws Exception {

Map<String, List<String>> expStrMap = new HashMap<>();
expStrMap.put(cmdStr, List.of(
"public static void main(java.lang.String[])",
"public static void main\\(java\\.lang\\.String\\[\\]\\)",
"Holder Class",
"public class jdk.test.lib.apps.LingeredApp @",
"public class jdk\\.test\\.lib\\.apps\\.LingeredApp @",
"Bytecode",
"line bci bytecode",
"Exception Table",
"start bci end bci handler bci catch type",
"Constant Pool of [public class jdk.test.lib.apps.LingeredApp @"));
"Constant Pool of \\[public class jdk\\.test\\.lib\\.apps\\.LingeredApp @"));

test.run(theApp.getPid(), cmds, expStrMap, null);
} catch (SkippedException e) {
@@ -26,7 +26,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;

/**
* @test
@@ -56,11 +55,11 @@ private static void testJstack(boolean withXcomp) throws Exception {
Map<String, List<String>> expStrMap = new HashMap<>();
expStrMap.put("jstack -v", List.of(
"No deadlocks found",
"Common-Cleaner",
"Common\\-Cleaner",
"Signal Dispatcher",
"java.lang.ref.Finalizer$FinalizerThread.run",
"java.lang.ref.Finalizer\\$FinalizerThread.run",
"java.lang.ref.Reference",
"Method*",
"Method\\*",
"LingeredApp.main"));

test.run(theApp.getPid(), cmds, expStrMap, null);
@@ -137,7 +137,7 @@ private String runCmd(List<String> commands,
List<String> expectedStr = expectedStrMap.get(cmd);
if (expectedStr != null) {
for (String exp : expectedStr) {
out.shouldContain(exp);
out.shouldMatch(exp);
}
}
}
@@ -146,7 +146,7 @@ private String runCmd(List<String> commands,
List<String> unExpectedStr = unExpectedStrMap.get(cmd);
if (unExpectedStr != null) {
for (String unExp : unExpectedStr) {
out.shouldNotContain(unExp);
out.shouldNotMatch(unExp);
}
}
}
@@ -26,7 +26,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;

/**
* @test
@@ -55,11 +55,11 @@ public static void main(String[] args) throws Exception {
expStrMap.put("printall", List.of(
"aload_0",
"Constant Pool of",
"public static void main(java.lang.String[])",
"public static void main\\(java.lang.String\\[\\]\\)",
"Bytecode",
"[enum] class Song [signature Ljava/lang/Enum<LSong;>;]",
"Method java.lang.Object clone()",
"public static Song[] values()",
"\\[enum\\] class Song \\[signature Ljava/lang/Enum\\<LSong;\\>;\\]",
"Method java.lang.Object clone\\(\\)",
"public static Song\\[\\] values\\(\\)",
"invokevirtual",
"checkcast",
"Field Song HAVANA",
@@ -26,7 +26,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;

/**
* @test
@@ -70,7 +69,7 @@ public static void main(String[] args) throws Exception {
expStrMap.put("printstatics Threads", List.of(
"Static fields of Threads",
"_number_of_threads", "_number_of_non_daemon_threads",
"JavaThread* Threads"));
"JavaThread\\* Threads"));
expStrMap.put("printstatics Universe", List.of(
"Static fields of Universe",
"uintptr_t Universe::_verify_oop_mask",
@@ -26,7 +26,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;

/**
* @test
@@ -85,7 +85,7 @@ private static void testWithGcType(String gc) throws Exception {

expStrMap.put(cmd, List.of
("java/lang/Object", "java/lang/Class", "java/lang/Thread",
"java/lang/String", "[B", "[I"));
"java/lang/String", "\\[B", "\\[I"));

// Test the 'type' option also
// scanoops <start addr> <end addr> java/lang/String
@@ -57,16 +57,16 @@ public static void main(String[] args) throws Exception {
Map<String, List<String>> expStrMap = new HashMap<>();
expStrMap.put("source clhsdb_cmd_file", List.of(
"No deadlocks found",
"Common-Cleaner",
"Common\\-Cleaner",
"Signal Dispatcher",
"java.lang.ref.Finalizer$FinalizerThread.run",
"java.lang.ref.Finalizer\\$FinalizerThread.run",
"java.lang.ref.Reference",
"Method*",
"Method\\*",
"LingeredApp.main",
"Available commands:",
"attach pid | exec core",
"intConstant [ name [ value ] ]",
"type [ type [ name super isOop isInteger isUnsigned size ] ]"));
"attach pid \\| exec core",
"intConstant \\[ name \\[ value \\] \\]",
"type \\[ type \\[ name super isOop isInteger isUnsigned size \\] \\]"));

Map<String, List<String>> unExpStrMap = new HashMap<>();
unExpStrMap.put("source clhsdb_cmd_file", List.of(
@@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception {

Map<String, List<String>> expStrMap = new HashMap<>();
// Check for the presence of the usage string
expStrMap.put("thread", List.of( "Usage: thread { -a | id }"));
expStrMap.put("thread", List.of( "Usage: thread \\{ \\-a \\| id \\}"));
expStrMap.put("thread -a", List.of(
"State: BLOCKED",
"Stack in use by Java",
@@ -68,7 +68,7 @@ public static void main(String[] args) throws Exception {
Map<String, List<String>> unExpStrMap = new HashMap<>();
unExpStrMap.put(
"thread -a",
List.of("Couldn't find thread -a"));
List.of("Couldn't find thread \\-a"));

String consolidatedOutput = test.run(
theApp.getPid(),
@@ -26,7 +26,6 @@
import java.util.Map;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;

/**
* @test
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -22,19 +22,12 @@
*/

import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.io.File;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.OutputStream;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Utils;
import jdk.test.lib.Asserts;
import java.util.Map;
import java.util.HashMap;
import jtreg.SkippedException;

/**
* @test
@@ -45,117 +38,39 @@

public class TestClhsdbJstackLock {

private static final String JSTACK_OUT_FILE = "jstack_out.txt";

private static void verifyJStackOutput() throws Exception {

Exception unexpected = null;
File jstackFile = new File(JSTACK_OUT_FILE);
Asserts.assertTrue(jstackFile.exists() && jstackFile.isFile(),
"File with jstack output not created: " +
jstackFile.getAbsolutePath());
try {
Scanner scanner = new Scanner(jstackFile);

boolean classLockOwnerFound = false;
boolean classLockWaiterFound = false;
boolean objectLockOwnerFound = false;
boolean primitiveLockOwnerFound = false;

while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);

if (line.contains("missing reason for ")) {
unexpected = new RuntimeException("Unexpected msg: missing reason for ");
break;
}
if (line.matches("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$")) {
classLockOwnerFound = true;
}
if (line.matches("^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$")) {
classLockWaiterFound = true;
}
if (line.matches("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$")) {
objectLockOwnerFound = true;
}
if (line.matches("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$")) {
primitiveLockOwnerFound = true;
}
}

if (!classLockOwnerFound || !classLockWaiterFound ||
!objectLockOwnerFound || !primitiveLockOwnerFound) {
unexpected = new RuntimeException(
"classLockOwnerFound = " + classLockOwnerFound +
", classLockWaiterFound = " + classLockWaiterFound +
", objectLockOwnerFound = " + objectLockOwnerFound +
", primitiveLockOwnerFound = " + primitiveLockOwnerFound);
}
if (unexpected != null) {
throw unexpected;
}
} catch (Exception ex) {
throw new RuntimeException("Test ERROR " + ex, ex);
} finally {
jstackFile.delete();
}
}

private static void startClhsdbForLock(long lingeredAppPid) throws Exception {

Process p;
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addToolArg("clhsdb");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(lingeredAppPid));

ProcessBuilder pb = new ProcessBuilder();
pb.command(launcher.getCommand());
System.out.println(pb.command().stream().collect(Collectors.joining(" ")));

try {
p = pb.start();
} catch (Exception attachE) {
throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
}

// Issue the 'jstack' input at the clhsdb prompt.
OutputStream input = p.getOutputStream();
String str = "jstack > " + JSTACK_OUT_FILE + "\nquit\n";
try {
input.write(str.getBytes());
input.flush();
} catch (IOException ioe) {
throw new Error("Problem issuing the jstack command: " + str, ioe);
}

OutputAnalyzer output = new OutputAnalyzer(p);

try {
p.waitFor();
} catch (InterruptedException ie) {
p.destroyForcibly();
throw new Error("Problem awaiting the child process: " + ie, ie);
}

output.shouldHaveExitValue(0);
}

public static void main (String... args) throws Exception {

LingeredApp app = null;

System.out.println("Starting TestClhsdbJstackLock test");
LingeredAppWithLock app = null;
try {
ClhsdbLauncher test = new ClhsdbLauncher();
List<String> vmArgs = new ArrayList<String>(Utils.getVmOptions());

app = new LingeredAppWithLock();
LingeredApp.startApp(vmArgs, app);
System.out.println ("Started LingeredApp with pid " + app.getPid());
startClhsdbForLock(app.getPid());
verifyJStackOutput();

System.out.println ("Started LingeredAppWithLock with pid " + app.getPid());

List<String> cmds = List.of("jstack");

Map<String, List<String>> expStrMap = new HashMap<>();
Map<String, List<String>> unExpStrMap = new HashMap<>();
expStrMap.put("jstack", List.of(
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$",
"^\\s+- waiting to lock <0x[0-9a-f]+> \\(a java\\.lang\\.Class for LingeredAppWithLock\\)$",
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$",
"^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$"));
unExpStrMap.put("jstack", List.of(
"missing reason for "));
test.run(app.getPid(), cmds, expStrMap, unExpStrMap);
} catch (SkippedException se) {
throw se;
} catch (Exception ex) {
throw new RuntimeException("Test ERROR " + ex, ex);
} finally {
LingeredApp.stopApp(app);
}

System.out.println("Test PASSED");
}
}