Skip to content
Permalink
Browse files
8238268: Many SA tests are not running on OSX because they do not att…
…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.
@@ -58,7 +58,6 @@ requires.properties= \
vm.cpu.features \
vm.debug \
vm.hasSA \
vm.hasSAandCanAttach \
vm.hasJFR \
vm.rtm.cpu \
vm.rtm.compiler \
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
@@ -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;
@@ -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);
@@ -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
@@ -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(" ")));

@@ -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";

@@ -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
*/
@@ -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 {

@@ -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(" ")));

@@ -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;

@@ -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) {
@@ -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
*/
@@ -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);

@@ -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",
@@ -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.
@@ -45,11 +43,9 @@
public class ClhsdbLauncher {

private Process toolProcess;
private boolean needPrivileges;

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

/**
@@ -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();
}
@@ -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);
}
@@ -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
@@ -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");
@@ -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());
@@ -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()) {
@@ -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);
}
@@ -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 {
@@ -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);

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.