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

The following examples show how to use jdk.test.lib.Platform#isWindows() . 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: AttachWithStalePidFile.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 {

    // this test is only valid on non-Windows platforms
    if(Platform.isWindows()) {
      System.out.println("This test is only valid on non-Windows platforms.");
      return;
    }

    // Since there might be stale pid-files owned by different
    // users on the system we may need to retry the test in case we
    // are unable to remove the existing file.
    int retries = 5;
    while(!runTest() && --retries > 0);

    if(retries == 0) {
      throw new RuntimeException("Test failed after 5 retries. " +
        "Remove any /tmp/.java_pid* files and retry.");
    }
  }
 
Example 4
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 5
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 6
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 7
Source File: CtwTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void compile(String[] args) throws Exception {
    // concat CTW_COMMAND and args w/o 0th element
    String[] cmd = Arrays.copyOf(CTW_COMMAND, CTW_COMMAND.length + args.length - 1);
    System.arraycopy(args, 1, cmd, CTW_COMMAND.length, args.length - 1);
    if (Platform.isWindows()) {
        // '*' has to be escaped on windows
        for (int i = 0; i < cmd.length; ++i) {
            cmd[i] = cmd[i].replace("*", "\"*\"");
        }
    }
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd);
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    dump(output, "compile");
    output.shouldHaveExitValue(0);
}
 
Example 8
Source File: CiReplayBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private String[] getTestJavaCommandlineWithPrefix(String prefix, String... args) {
    try {
        String cmd = ProcessTools.getCommandLine(ProcessTools.createJavaProcessBuilder(true, args));
        return new String[]{"sh", "-c", prefix
                + (Platform.isWindows() ? cmd.replace('\\', '/').replace(";", "\\;") : cmd)};
    } catch(Throwable t) {
        throw new Error("Can't create process builder: " + t, t);
    }
}
 
Example 9
Source File: CiReplayBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private String getCoreFileLocation(String crashOutputString) {
    Asserts.assertTrue(crashOutputString.contains(LOCATIONS_STRING),
            "Output doesn't contain the location of core file, see crash.out");
    String stringWithLocation = Arrays.stream(crashOutputString.split("\\r?\\n"))
            .filter(str -> str.contains(LOCATIONS_STRING))
            .findFirst()
            .get();
    stringWithLocation = stringWithLocation.substring(stringWithLocation
            .indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length());
    String coreWithPid;
    if (stringWithLocation.contains("or ") && !Platform.isWindows()) {
        Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation);
        if (!m.find()) {
            throw new Error("Couldn't find path to core inside location string");
        }
        coreWithPid = m.group(1);
    } else {
        coreWithPid = stringWithLocation.trim();
    }
    if (new File(coreWithPid).exists()) {
        return coreWithPid;
    }
    String justCore = Paths.get("core").toString();
    if (new File(justCore).exists()) {
        return justCore;
    }
    Path coreWithPidPath = Paths.get(coreWithPid);
    String justFile = coreWithPidPath.getFileName().toString();
    if (new File(justFile).exists()) {
        return justFile;
    }
    Path parent = coreWithPidPath.getParent();
    if (parent != null) {
        String coreWithoutPid = parent.resolve("core").toString();
        if (new File(coreWithoutPid).exists()) {
            return coreWithoutPid;
        }
    }
    return null;
}
 
Example 10
Source File: CiReplayBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void remove(String item) {
    File toDelete = new File(item);
    toDelete.delete();
    if (Platform.isWindows()) {
        Utils.waitForCondition(() -> !toDelete.exists());
    }
}
 
Example 11
Source File: CreateCoredumpOnCrash.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 {
    runTest("-XX:-CreateCoredumpOnCrash").shouldContain("CreateCoredumpOnCrash turned off, no core file dumped");

    if (Platform.isWindows()) {
        // The old CreateMinidumpOnCrash option should still work
        runTest("-XX:-CreateMinidumpOnCrash").shouldContain("CreateCoredumpOnCrash turned off, no core file dumped");
    } else {
        runTest("-XX:+CreateCoredumpOnCrash").shouldNotContain("CreateCoredumpOnCrash turned off, no core file dumped");
    }

}
 
Example 12
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 13
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 14
Source File: LoadAgentDcmdTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * return path to library inside jdk tree
 */
public static String jdkLibPath() {
    if (Platform.isWindows()) {
        return "bin";
    }
    return "lib";
}
 
Example 15
Source File: TestShutdownEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isApplicable() {
    if (Platform.isWindows()) {
        return false;
    }
    if (signalName.equals("HUP") && Platform.isSolaris()) {
        return false;
    }
    return true;
}
 
Example 16
Source File: JFRSecurityTestSuite.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void setProtectedLocation() {
    if (Platform.isWindows()) {
        protectedLocationPath = System.getenv("%WINDIR%");
        if (protectedLocationPath == null) {
            // fallback
            protectedLocationPath = "c:\\windows";
        }
    } else {
        protectedLocationPath = "/etc";
    }
}
 
Example 17
Source File: TestShutdownEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isApplicable() {
    if (Platform.isWindows()) {
        return false;
    }
    if (signalName.equals("HUP") && Platform.isSolaris()) {
        return false;
    }
    return true;
}
 
Example 18
Source File: SecondaryErrorTest.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 {

    // Do not execute for windows, nor for non-debug builds
    if (Platform.isWindows()) {
      return;
    }

    if (!Platform.isDebugBuild()) {
      return;
    }

    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-Xmx100M",
        "-XX:-CreateCoredumpOnCrash",
        "-XX:ErrorHandlerTest=15",
        "-XX:TestCrashInErrorHandler=14",
        "-version");

    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());

    // we should have crashed with a SIGFPE
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
    output_detail.shouldMatch("# +SIGFPE.*");

    // extract hs-err file
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
    if (hs_err_file == null) {
      throw new RuntimeException("Did not find hs-err file in output.\n");
    }

    // scan hs-err file: File should contain the "[error occurred during error reporting..]"
    // markers which show that the secondary error handling kicked in and handled the
    // error successfully. As an added test, we check that the last line contains "END.",
    // which is an end marker written in the last step and proves that hs-err file was
    // completely written.
    File f = new File(hs_err_file);
    if (!f.exists()) {
      throw new RuntimeException("hs-err file missing at "
          + f.getAbsolutePath() + ".\n");
    }

    System.out.println("Found hs_err file. Scanning...");

    FileInputStream fis = new FileInputStream(f);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String line = null;

    Pattern [] pattern = new Pattern[] {
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 1\\).*\\]"),
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 2\\).*\\]"),
    };
    int currentPattern = 0;

    String lastLine = null;
    while ((line = br.readLine()) != null) {
      if (currentPattern < pattern.length) {
        if (pattern[currentPattern].matcher(line).matches()) {
          System.out.println("Found: " + line + ".");
          currentPattern ++;
        }
      }
      lastLine = line;
    }
    br.close();

    if (currentPattern < pattern.length) {
      throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
    }

    if (!lastLine.equals("END.")) {
      throw new RuntimeException("hs-err file incomplete (missing END marker.)");
    } else {
      System.out.println("End marker found.");
    }

    System.out.println("OK.");

  }
 
Example 19
Source File: CheckForProperDetailStackTrace.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 {
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
        "-XX:+UnlockDiagnosticVMOptions",
        "-XX:NativeMemoryTracking=detail",
        "-XX:+PrintNMTStatistics",
        "-version");
    OutputAnalyzer output = new OutputAnalyzer(pb.start());

    output.shouldHaveExitValue(0);

    // We should never see either of these frames because they are supposed to be skipped. */
    output.shouldNotContain("NativeCallStack::NativeCallStack");
    output.shouldNotContain("os::get_native_stack");

    // AllocateHeap shouldn't be in the output because it is supposed to always be inlined.
    // We check for that here, but allow it for Aix, Solaris and Windows slowdebug builds
    // because the compiler ends up not inlining AllocateHeap.
    Boolean okToHaveAllocateHeap =
        Platform.isSlowDebugBuild() &&
        (Platform.isAix() || Platform.isSolaris() || Platform.isWindows());
    if (!okToHaveAllocateHeap) {
        output.shouldNotContain("AllocateHeap");
    }

    // See if we have any stack trace symbols in the output
    boolean hasSymbols =
        output.getStdout().contains(expectedSymbol) || output.getStderr().contains(expectedSymbol);
    if (!hasSymbols) {
        // It's ok for ARM not to have symbols, because it does not support NMT detail
        // when targeting thumb2. It's also ok for Windows not to have symbols, because
        // they are only available if the symbols file is included with the build.
        if (Platform.isWindows() || Platform.isARM()) {
            return; // we are done
        }
        output.reportDiagnosticSummary();
        throw new RuntimeException("Expected symbol missing missing from output: " + expectedSymbol);
    }

    /* Make sure the expected NMT detail stack trace is found. */
    String expectedStackTrace =
        (okToHaveAllocateHeap ? stackTraceAllocateHeap : stackTraceDefault);
    if (!stackTraceMatches(expectedStackTrace, output)) {
        output.reportDiagnosticSummary();
        throw new RuntimeException("Expected stack trace missing missing from output: " + expectedStackTrace);
    }
}
 
Example 20
Source File: ProcessUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return true if the ProcessHandle is a Windows i586 conhost.exe process.
 *
 * @param p the processHandle of the Process
 * @return Return true if the ProcessHandle is for a Windows i586 conhost.exe process
 */
static boolean isWindowsConsole(ProcessHandle p) {
    return Platform.isWindows() && p.info().command().orElse("").endsWith("C:\\Windows\\System32\\conhost.exe");
}