Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8238268

Many SA tests are not running on OSX because they do not attempt to use sudo when available



    • b15
    • os_x



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


          Issue Links



                cjplummer Chris Plummer
                cjplummer Chris Plummer
                0 Vote for this issue
                5 Start watching this issue