Java Code Examples for jdk.test.lib.Platform#isOSX()

The following examples show how to use jdk.test.lib.Platform#isOSX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestNativeLibrariesEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static List<String> getExpectedLibs() throws Throwable {
    String libTemplate = null;
    if (Platform.isSolaris()) {
        libTemplate = "lib%s.so";
    } else if (Platform.isWindows()) {
        libTemplate = "%s.dll";
    } else if (Platform.isOSX()) {
        libTemplate = "lib%s.dylib";
    } else if (Platform.isLinux()) {
        libTemplate = "lib%s.so";
    }
    if (libTemplate == null) {
        throw new Exception("Unsupported OS");
    }

    List<String> libs = new ArrayList<String>();
    String[] names = { "jvm", "java", "zip" };
    for (String name : names) {
        libs.add(String.format(libTemplate, name));
    }
    return libs;
}
 
Example 2
Source File: TestNativeLibrariesEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static List<String> getExpectedLibs() throws Throwable {
    String libTemplate = null;
    if (Platform.isSolaris()) {
        libTemplate = "lib%s.so";
    } else if (Platform.isWindows()) {
        libTemplate = "%s.dll";
    } else if (Platform.isOSX()) {
        libTemplate = "lib%s.dylib";
    } else if (Platform.isLinux()) {
        libTemplate = "lib%s.so";
    }
    if (libTemplate == null) {
        throw new Exception("Unsupported OS");
    }

    List<String> libs = new ArrayList<String>();
    String[] names = { "jvm", "java", "zip" };
    for (String name : names) {
        libs.add(String.format(libTemplate, name));
    }
    return libs;
}
 
Example 3
Source File: DynLibsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void run(CommandExecutor executor) {
    OutputAnalyzer output = executor.execute("VM.dynlibs");

    String osDependentBaseString = null;
    if (Platform.isAix()) {
        osDependentBaseString = "lib%s.so";
    } else if (Platform.isLinux()) {
        osDependentBaseString = "lib%s.so";
    } else if (Platform.isOSX()) {
        osDependentBaseString = "lib%s.dylib";
    } else if (Platform.isSolaris()) {
        osDependentBaseString = "lib%s.so";
    } else if (Platform.isWindows()) {
        osDependentBaseString = "%s.dll";
    }

    if (osDependentBaseString == null) {
        Assert.fail("Unsupported OS");
    }

    output.shouldContain(String.format(osDependentBaseString, "jvm"));
    output.shouldContain(String.format(osDependentBaseString, "java"));
    output.shouldContain(String.format(osDependentBaseString, "management"));
}
 
Example 4
Source File: ReserveMemory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
  if (args.length > 0) {
    WhiteBox.getWhiteBox().readReservedMemory();

    throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!");
  }

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xbootclasspath/a:.",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:-TransmitErrorReport",
        "-XX:-CreateCoredumpOnCrash",
        "-Xmx32m",
        "ReserveMemory",
        "test");

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  if (Platform.isWindows()) {
    output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
  } else if (Platform.isOSX()) {
    output.shouldContain("SIGBUS");
  } else {
    output.shouldContain("SIGSEGV");
  }
}
 
Example 5
Source File: ProcessUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the native command to list the active processes.
 */
static void logTaskList() {
    String[] windowsArglist = {"tasklist.exe", "/v"};
    String[] unixArglist = {"ps", "-ef"};

    String[] argList = null;
    if (Platform.isWindows()) {
        argList = windowsArglist;
    } else if (Platform.isLinux() || Platform.isOSX()) {
        argList = unixArglist;
    } else {
        return;
    }

    ProcessBuilder pb = new ProcessBuilder(argList);
    pb.inheritIO();
    try {
        Process proc = pb.start();
        proc.waitFor();
    } catch (IOException | InterruptedException ex) {
        ex.printStackTrace();
    }
}
 
Example 6
Source File: LoadAgentDcmdTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build name of shared object according to platform rules
 */
public static String sharedObjectName(String name) {
    if (Platform.isWindows()) {
        return name + ".dll";
    }
    if (Platform.isOSX()) {
        return "lib" + name + ".dylib";
    }
    return "lib" + name + ".so";
}
 
Example 7
Source File: ReadFromNoaccessArea.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
  if (!Platform.is64bit()) {
    System.out.println("ReadFromNoaccessArea tests is useful only on 64bit architecture. Passing silently.");
    return;
  }

  ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-Xbootclasspath/a:.",
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:+WhiteBoxAPI",
        "-XX:+UseCompressedOops",
        "-XX:HeapBaseMinAddress=33G",
        "-XX:-CreateCoredumpOnCrash",
        "-Xmx32m",
        DummyClassWithMainTryingToReadFromNoaccessArea.class.getName());

  OutputAnalyzer output = new OutputAnalyzer(pb.start());
  System.out.println("******* Printing stdout for analysis in case of failure *******");
  System.out.println(output.getStdout());
  System.out.println("******* Printing stderr for analysis in case of failure *******");
  System.out.println(output.getStderr());
  System.out.println("***************************************************************");
  if (output.getStdout() != null && output.getStdout().contains("WB_ReadFromNoaccessArea method is useless")) {
    // Test conditions broken. There is no protected page in ReservedHeapSpace in these circumstances. Silently passing test.
    return;
  }
  if (Platform.isWindows()) {
    output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
  } else if (Platform.isOSX()) {
    output.shouldContain("SIGBUS");
  } else {
    output.shouldContain("SIGSEGV");
  }
}
 
Example 8
Source File: ReservedStackTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@jdk.internal.vm.annotation.ReservedStackAccess
public void run() {
    counter = 0;
    decounter = deframe;
    test.initialize();
    recursiveCall();
    System.out.println("Framework got StackOverflowError at frame = " + counter);
    System.out.println("Test started execution at frame = " + (counter - deframe));
    String result = test.getResult();
    // The feature is not fully implemented on all platforms,
    // corruptions are still possible.
    boolean supportedPlatform =
        Platform.isAix() ||
        (Platform.isLinux() &&
          (Platform.isPPC() || Platform.isS390x() || Platform.isX64() ||
           Platform.isX86() || Platform.isAArch64())) ||
        Platform.isOSX() ||
        Platform.isSolaris();
    if (supportedPlatform && !result.contains("PASSED")) {
        System.out.println(result);
        throw new Error(result);
    } else {
        // Either the test passed or this platform is not supported.
        // On not supported platforms, we only expect the VM to
        // not crash during the test. This is especially important
        // on Windows where the detection of SOE in annotated
        // sections is implemented but the reserved zone mechanism
        // to avoid the corruption cannot be implemented yet
        // because of JDK-8067946
        System.out.println("PASSED");
    }
}
 
Example 9
Source File: BasicLauncherTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void launchJStack() throws IOException {

        if (Platform.isOSX()) {
            // Coredump stackwalking is not implemented for Darwin
            System.out.println("This test is not expected to work on OS X. Skipping");
            return;
        }

        System.out.println("Starting LingeredApp");
        try {
            theApp = LingeredApp.startApp(Arrays.asList("-Xmx256m"));

            System.out.println("Starting jstack against " + theApp.getPid());
            JDKToolLauncher launcher = createSALauncher();

            launcher.addToolArg("jstack");
            launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));

            ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
            OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);;
            output.shouldContain("No deadlocks found");
            output.shouldNotContain("illegal bci");
            output.shouldNotContain("AssertionFailure");
            output.shouldHaveExitValue(0);

        } catch (Exception ex) {
            throw new RuntimeException("Test ERROR " + ex, ex);
        } finally {
            LingeredApp.stopApp(theApp);
        }
    }
 
Example 10
Source File: DeadlockDetectionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println("Starting DeadlockDetectionTest");

    if (!Platform.shouldSAAttach()) {
        // Silently skip the test if we don't have enough permissions to attach
        // Not all conditions checked by function is relevant to SA but it's worth
        // to check
        System.err.println("Error! Insufficient permissions to attach.");
        return;
    }

    if (Platform.isOSX()) {
        // Coredump stackwalking is not implemented for Darwin
        System.out.println("This test is not expected to work on OS X. Skipping");
        return;
    }


    if (!LingeredApp.isLastModifiedWorking()) {
        // Exact behaviour of the test depends on operating system and the test nature,
        // so just print the warning and continue
        System.err.println("Warning! Last modified time doesn't work.");
    }

    try {
        List<String> vmArgs = new ArrayList<String>();
        vmArgs.add("-XX:+UsePerfData");
        vmArgs.addAll(Utils.getVmOptions());

        theApp = new LingeredAppWithDeadlock();
        LingeredApp.startApp(vmArgs, theApp);
        OutputAnalyzer output = jstack("--pid", Long.toString(theApp.getPid()));
        System.out.println(output.getOutput());

        if (output.getExitValue() == 3) {
            System.out.println("Test can't run for some reason. Skipping");
        }
        else {
            output.shouldHaveExitValue(0);
            output.shouldContain("Found a total of 1 deadlock.");
        }

    } finally {
        LingeredApp.stopApp(theApp);
    }
}
 
Example 11
Source File: CiReplayBase.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean generateReplay(boolean needCoreDump, String... vmopts) {
    OutputAnalyzer crashOut;
    String crashOutputString;
    try {
        List<String> options = new ArrayList<>();
        options.addAll(Arrays.asList(REPLAY_GENERATION_OPTIONS));
        options.addAll(Arrays.asList(vmopts));
        options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH);
        options.add(VERSION_OPTION);
        if (needCoreDump) {
            crashOut = ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix(
                    RUN_SHELL_NO_LIMIT, options.toArray(new String[0])));
        } else {
            crashOut = ProcessTools.executeProcess(ProcessTools.createJavaProcessBuilder(true,
                    options.toArray(new String[0])));
        }
        crashOutputString = crashOut.getOutput();
        Asserts.assertNotEquals(crashOut.getExitValue(), 0, "Crash JVM exits gracefully");
        Files.write(Paths.get("crash.out"), crashOutputString.getBytes(),
                StandardOpenOption.CREATE, StandardOpenOption.WRITE,
                StandardOpenOption.TRUNCATE_EXISTING);
    } catch (Throwable t) {
        throw new Error("Can't create replay: " + t, t);
    }
    if (needCoreDump) {
        String coreFileLocation = getCoreFileLocation(crashOutputString);
        if (coreFileLocation == null) {
            if (Platform.isOSX()) {
                File coresDir = new File("/cores");
                if (!coresDir.isDirectory() || !coresDir.canWrite()) {
                    return false;
                }
            }
            throw new Error("Couldn't find core file location in: '" + crashOutputString + "'");
        }
        try {
            Asserts.assertGT(new File(coreFileLocation).length(), 0L, "Unexpected core size");
            Files.move(Paths.get(coreFileLocation), Paths.get(TEST_CORE_FILE_NAME));
        } catch (IOException ioe) {
            throw new Error("Can't move core file: " + ioe, ioe);
        }
    }
    removeFromCurrentDirectoryStartingWith(HS_ERR_NAME);
    return true;
}