Skip to content

Commit

Permalink
8238268: Many SA tests are not running on OSX because they do not att…
Browse files Browse the repository at this point in the history
…empt to use sudo when available

8238196: tests that use SA Attach should not be allowed to run against signed binaries on Mac OS X 10.14.5 and later

Reviewed-by: goetz
Backport-of: a147636
  • Loading branch information
RealCLanger committed Aug 2, 2022
1 parent 8871303 commit e80c7e1
Show file tree
Hide file tree
Showing 40 changed files with 373 additions and 271 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/TEST.ROOT
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ requires.properties= \
vm.cpu.features \
vm.debug \
vm.hasSA \
vm.hasSAandCanAttach \
vm.hasJFR \
vm.rtm.cpu \
vm.rtm.compiler \
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/compiler/ciReplay/TestSAClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
Expand All @@ -26,7 +26,7 @@
* @bug 8011675
* @library / /test/lib
* @summary testing of ciReplay with using generated by SA replay.txt
* @requires vm.hasSAandCanAttach & vm.flightRecorder != true & vm.compMode != "Xint" & vm.debug == true & vm.flavor == "client"
* @requires vm.hasSA & vm.flightRecorder != true & vm.compMode != "Xint" & vm.debug == true & vm.flavor == "client"
* @modules java.base/jdk.internal.misc
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/compiler/ciReplay/TestSAServer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
Expand All @@ -26,7 +26,7 @@
* @bug 8011675
* @library / /test/lib
* @summary testing of ciReplay with using generated by SA replay.txt
* @requires vm.hasSAandCanAttach & vm.flightRecorder != true & vm.compMode != "Xint" & vm.debug == true & vm.flavor == "server"
* @requires vm.hasSA & vm.flightRecorder != true & vm.compMode != "Xint" & vm.debug == true & vm.flavor == "server"
* @modules java.base/jdk.internal.misc
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
Expand Down Expand Up @@ -27,7 +27,7 @@
* @test CompressedClassSpaceSizeInJmapHeap
* @bug 8004924
* @summary Checks that jmap -heap contains the flag CompressedClassSpaceSize
* @requires vm.hasSAandCanAttach
* @requires vm.hasSA
* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true
* @library /test/lib
* @modules java.base/jdk.internal.misc
Expand All @@ -39,6 +39,7 @@
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
import java.nio.file.*;
import java.io.File;
import java.nio.charset.Charset;
Expand All @@ -47,6 +48,8 @@
public class CompressedClassSpaceSizeInJmapHeap {
// Note that on some platforms it may require root privileges to run this test.
public static void main(String[] args) throws Exception {
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.

if (!Platform.is64bit()) {
// Compressed Class Space is only available on 64-bit JVMs
return;
Expand All @@ -59,7 +62,7 @@ public static void main(String[] args) throws Exception {
.addToolArg("--heap")
.addToolArg("--pid")
.addToolArg(pid);
ProcessBuilder pb = new ProcessBuilder(jmap.getCommand());
ProcessBuilder pb = SATestUtils.createProcessBuilder(jmap);

File out = new File("CompressedClassSpaceSizeInJmapHeap.stdout.txt");
pb.redirectOutput(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@
import sun.jvm.hotspot.debugger.*;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
import jdk.test.lib.Asserts;

/**
* @test
* @library /test/lib
* @bug 8171084
* @requires vm.hasSAandCanAttach & (vm.bits == "64" & os.maxMemory > 8g)
* @requires vm.hasSA & (vm.bits == "64" & os.maxMemory > 8g)
* @requires vm.gc != "Shenandoah"
* @modules java.base/jdk.internal.misc
* jdk.hotspot.agent/sun.jvm.hotspot
Expand All @@ -71,8 +72,7 @@ private static void attachAndDump(String heapDumpFileName,
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(lingeredAppPid));

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

Expand All @@ -87,6 +87,7 @@ private static void attachAndDump(String heapDumpFileName,
}

public static void main (String... args) throws Exception {
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.

String heapDumpFileName = "LargeArrayHeapDump.bin";

Expand Down
7 changes: 4 additions & 3 deletions test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @test
* @bug 8204308
* @summary Test the jhsdb jmap -clstats command with CDS enabled
* @requires vm.hasSAandCanAttach & vm.cds
* @requires vm.hasSA & vm.cds
* @library /test/lib
* @run main/othervm/timeout=2400 CDSJMapClstats
*/
Expand All @@ -39,6 +39,7 @@
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.SA.SATestUtils;

public class CDSJMapClstats {

Expand All @@ -50,8 +51,7 @@ private static void runClstats(long lingeredAppPid) throws Exception {
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(lingeredAppPid));

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

Expand All @@ -64,6 +64,7 @@ private static void runClstats(long lingeredAppPid) throws Exception {

public static void main(String[] args) throws Exception {
System.out.println("Starting CDSJMapClstats test");
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
String sharedArchiveName = "ArchiveForCDSJMapClstats.jsa";
LingeredApp theApp = null;

Expand Down
40 changes: 18 additions & 22 deletions test/hotspot/jtreg/serviceability/sa/ClhsdbFindPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,32 @@ private static void testFindPC(boolean withXcomp) throws Exception {
// the 'jstack -v' command
cmds = new ArrayList<String>();

// Output could be null if the test was skipped due to
// attach permission issues.
if (output != null) {
String cmdStr = null;
String[] parts = output.split("LingeredAppWithTrivialMain.main");
String[] tokens = parts[1].split(" ");
for (String token : tokens) {
if (token.contains("pc")) {
String[] address = token.split("=");
// address[1] represents the address of the Method
cmdStr = "findpc " + address[1].replace(",","");
cmds.add(cmdStr);
break;
}
String cmdStr = null;
String[] parts = output.split("LingeredAppWithTrivialMain.main");
String[] tokens = parts[1].split(" ");
for (String token : tokens) {
if (token.contains("pc")) {
String[] address = token.split("=");
// address[1] represents the address of the Method
cmdStr = "findpc " + address[1].replace(",","");
cmds.add(cmdStr);
break;
}
}

Map<String, List<String>> expStrMap = new HashMap<>();
if (withXcomp) {
expStrMap.put(cmdStr, List.of(
Map<String, List<String>> expStrMap = new HashMap<>();
if (withXcomp) {
expStrMap.put(cmdStr, List.of(
"In code in NMethod for LingeredAppWithTrivialMain.main",
"content:",
"oops:",
"frame size:"));
} else {
expStrMap.put(cmdStr, List.of(
} else {
expStrMap.put(cmdStr, List.of(
"In interpreter codelet"));
}

test.run(theApp.getPid(), cmds, expStrMap, null);
}

test.run(theApp.getPid(), cmds, expStrMap, null);
} catch (SkippedException se) {
throw se;
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import java.util.stream.Collectors;

import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.process.OutputAnalyzer;

/**
* @test
* @bug 8196969
* @requires vm.hasSAandCanAttach
* @requires vm.hasSA
* @library /test/lib
* @run main/othervm ClhsdbJstackXcompStress
*/
Expand All @@ -62,8 +63,7 @@ private static void runJstackInLoop(LingeredApp app) throws Exception {
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));

ProcessBuilder pb = new ProcessBuilder();
pb.command(launcher.getCommand());
ProcessBuilder pb = SATestUtils.createProcessBuilder(launcher);
Process jhsdb = pb.start();
OutputAnalyzer out = new OutputAnalyzer(jhsdb);

Expand All @@ -87,6 +87,7 @@ private static void runJstackInLoop(LingeredApp app) throws Exception {
}

public static void main(String... args) throws Exception {
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
LingeredApp app = null;
try {
List<String> vmArgs = List.of("-Xcomp",
Expand Down
23 changes: 2 additions & 21 deletions test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jtreg.SkippedException;


/**
* This is a framework to run 'jhsdb clhsdb' commands.
Expand All @@ -45,11 +43,9 @@
public class ClhsdbLauncher {

private Process toolProcess;
private boolean needPrivileges;

public ClhsdbLauncher() {
toolProcess = null;
needPrivileges = false;
}

/**
Expand All @@ -66,11 +62,7 @@ private void attach(long lingeredAppPid)
System.out.println("Starting clhsdb against " + lingeredAppPid);
}

List<String> cmdStringList = Arrays.asList(launcher.getCommand());
if (needPrivileges) {
cmdStringList = SATestUtils.addPrivileges(cmdStringList);
}
ProcessBuilder processBuilder = new ProcessBuilder(cmdStringList);
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
toolProcess = processBuilder.start();
}
Expand Down Expand Up @@ -180,18 +172,7 @@ public String run(long lingeredAppPid,
Map<String, List<String>> unExpectedStrMap)
throws Exception {

if (!Platform.shouldSAAttach()) {
if (Platform.isOSX() && SATestUtils.canAddPrivileges()) {
needPrivileges = true;
}
else {
// Skip the test if we don't have enough permissions to attach
// and cannot add privileges.
throw new SkippedException(
"SA attach not expected to work. Insufficient privileges.");
}
}

SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
attach(lingeredAppPid);
return runCmd(commands, expectedStrMap, unExpectedStrMap);
}
Expand Down
12 changes: 5 additions & 7 deletions test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
/**
* @test
* @summary Test deadlock detection
* @requires vm.hasSAandCanAttach
* @requires os.family != "mac"
* @requires vm.hasSA
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.management
Expand All @@ -38,18 +37,17 @@

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

import jdk.test.lib.Utils;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;

import jtreg.SkippedException;

public class DeadlockDetectionTest {

private static LingeredAppWithDeadlock theApp = null;
private static ProcessBuilder processBuilder = new ProcessBuilder();

private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
Expand All @@ -60,7 +58,7 @@ private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
}
}

processBuilder.command(launcher.getCommand());
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
System.out.println(processBuilder.command().stream().collect(Collectors.joining(" ")));
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
Expand All @@ -69,6 +67,7 @@ private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
}

public static void main(String[] args) throws Exception {
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
System.out.println("Starting DeadlockDetectionTest");

if (!LingeredApp.isLastModifiedWorking()) {
Expand All @@ -93,7 +92,6 @@ public static void main(String[] args) throws Exception {
output.shouldHaveExitValue(0);
output.shouldContain("Found a total of 1 deadlock.");
}

} finally {
LingeredApp.stopApp(theApp);
}
Expand Down
8 changes: 4 additions & 4 deletions test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;

/**
* @test
* @requires vm.hasSAandCanAttach
* @requires vm.hasSA
* @library /test/lib
* @run main JhsdbThreadInfoTest
*/
public class JhsdbThreadInfoTest {

public static void main(String[] args) throws Exception {

SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
LingeredApp app = null;

try {
Expand All @@ -54,8 +55,7 @@ public static void main(String[] args) throws Exception {
jhsdbLauncher.addToolArg("--pid");
jhsdbLauncher.addToolArg(Long.toString(app.getPid()));

ProcessBuilder pb = new ProcessBuilder();
pb.command(jhsdbLauncher.getCommand());
ProcessBuilder pb = SATestUtils.createProcessBuilder(jhsdbLauncher);
Process jhsdb = pb.start();

OutputAnalyzer out = new OutputAnalyzer(jhsdb);
Expand Down

1 comment on commit e80c7e1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.