JDK-8238268 : Many SA tests are not running on OSX because they do not attempt to use sudo when available
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 15
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2020-01-31
  • Updated: 2020-05-29
  • Resolved: 2020-03-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b15Fixed
Related Reports
Blocks :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
There are ~20 or so serviceability/sa tests that use "@require vm.hasSAandCanAttach", and another 10 outside of serviceability/sa. On OSX vm.hasSAandCanAttach is only true if the tests are being run as root, so if not run as root these tests are skipped. 

Another option when not running as root is for the test to attempt to use sudo. We actually already support this in the tests that use ClhsdbLauncher. Instead of using "@require vm.hasSAandCanAttach", they do the equivalent of the vm.hasSAandCanAttach check from within the test by checking Platform.shouldSAAttach(). If it returns true, then the test can run. If it returns false and we are on OSX, then the tests query SATestUtils.canAddPrivileges(), which is basically a test to see if sudo will work. If it does work, then we also allow the test to run, and make sure the test runs the clhsdb command under sudo. All of this is handled by the following code ClhsdbLauncher:

        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.");
           }

And then for execution of clhsdb

        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
        launcher.addToolArg("clhsdb");
        if (lingeredAppPid != -1) {
            launcher.addToolArg("--pid=" + Long.toString(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);
        toolProcess = processBuilder.start();

We should modify non-ClhsdbLauncher tests to do the same as ClhsdbLauncher and use sudo if not running as root. We can move the SATestUtils.canAddPrivileges() check into vm.hasSAandCanAttach, and then have the test always use sudo if not running as root.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/d6ae5212211f User: cjplummer Date: 2020-03-18 01:06:28 +0000
18-03-2020

6 of the tests that @require vm.hasSAandCanAttach also @require 'os.family != "mac"'. It's unclear why. We should double check to see if they will work on OSX once sudo is used. Also, there are two other tests that use 'os.family != "xxx"' but do not use vm.hasSAandCanAttach. They are ClhsdbPstack and ClhsdbPmap. Neither pstack nor pmap are supported on OSX. However, I think it would be better if these tests remained enabled and properly detected the failure. For ClhsdbPstack, there is "Not available on Darwin" in the output which the test could detect. For ClhsdbPmap, the output is empty. I think Pmap should be fixed to also produce some sort of error output when run on OSX. As of right now if you are in clhsdb you execute "pmap", you simply get no output, which is not really useful to users. JDK-8237250 has been filed to clean this up.
31-01-2020

Besides the ~20 tests in hotspot/serviceability/sa, there are also 10 others that use "@require vm.hasSAandCanAttach" and therefore are never run on OSX. They include: jdk/sun/tools/jhsdb/* - 5 tests jdk/sun/tools/jstack/DeadlockDetectionTest.java gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java compiler/ciReplay/TestSAServer.java compiler/ciReplay/TestSAClient.java resourcehogs/serviceability/sa/TestHeapDumpForLargeArray.java
31-01-2020