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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 15
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b15
    • OS:
      os_x

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cjplummer Chris Plummer
              Reporter:
              cjplummer Chris Plummer
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: