< prev index next > test/hotspot/jtreg/runtime/8176717/TestInheritFD.java
8205054: Could not find "lsof" on test machine
Reviewed-by: goetz, dholmes
8205054: Could not find "lsof" on test machine
Reviewed-by: goetz
8205054: Could not find "lsof" on test machine
Reviewed-by:
-import static java.io.File.createTempFile;
-import static java.lang.Long.parseLong;
-import static java.lang.System.getProperty;
-import static java.nio.file.Files.readAllBytes;
-import static java.util.Arrays.stream;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.toList;
-import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Collection;
-import java.util.stream.Stream;
-
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+import static java.io.File.createTempFile;
+import static java.lang.Long.parseLong;
+import static java.lang.System.getProperty;
+import static java.nio.file.Files.readAllBytes;
+import static java.util.Arrays.stream;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.stream.Stream;
+
/*
* @test TestInheritFD
* @bug 8176717 8176809
* @summary a new process should not inherit open file descriptors
* @library /test/lib
// first VM
public static void main(String[] args) throws Exception {
String logPath = createTempFile("logging", LOG_SUFFIX).getName();
File commFile = createTempFile("communication", ".txt");
+ if (isWindows() == false && lsofCommand().isPresent() == false) {
+ System.out.println("Could not find lsof like command");
+ System.out.println("Exit test case as successful though it could not verify anything");
+ return;
+ }
+
ProcessBuilder pb = createJavaProcessBuilder(
"-Xlog:gc:\"" + logPath + "\"",
"-Dtest.jdk=" + getProperty("test.jdk"),
VMStartedWithLogging.class.getName(),
logPath);
args[0],
"" + ProcessHandle.current().pid());
pb.inheritIO(); // in future, redirect information from third VM to first VM
pb.start();
- if (getProperty("os.name").toLowerCase().contains("win") == false) {
+ if (!isWindows()) {
System.out.println("(Second VM) Open file descriptors:\n" + outputContainingFilenames().stream().collect(joining("\n")));
}
}
}
try {
File logFile = new File(args[0]);
long parentPid = parseLong(args[1]);
fakeLeakyJVM(false); // for debugging of test case
- if (getProperty("os.name").toLowerCase().contains("win")) {
+ if (isWindows()) {
windows(logFile, parentPid);
} else {
Collection<String> output = outputContainingFilenames();
System.out.println("(Third VM) Open file descriptors:\n" + output.stream().collect(joining("\n")));
System.out.println(findOpenLogFile(output) ? LEAKS_FD : RETAINS_FD);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
- static Collection<String> outputContainingFilenames() {
- long pid = ProcessHandle.current().pid();
- String[] command = stream(new String[][]{
+ static boolean isWindows() {
+ return getProperty("os.name").toLowerCase().contains("win");
+ }
+
+ static Optional<String[]> lsofCommand() {
+ return stream(new String[][]{
{"/usr/bin/lsof", "-p"},
{"/usr/sbin/lsof", "-p"},
{"/bin/lsof", "-p"},
{"/sbin/lsof", "-p"},
{"/usr/local/bin/lsof", "-p"},
{"/usr/bin/pfiles", "-F"}}) // Solaris
.filter(args -> new File(args[0]).exists())
- .findFirst()
- .orElseThrow(() -> new RuntimeException("could not find lsof-like command"));
+ .findFirst();
+ }
+
+ static Collection<String> outputContainingFilenames() {
+ long pid = ProcessHandle.current().pid();
+ String[] command = lsofCommand().orElseThrow(() -> new RuntimeException("lsof like command not found"));
System.out.println("using command: " + command[0] + " " + command[1]);
return run(command[0], command[1], "" + pid).collect(toList());
}
static boolean findOpenLogFile(Collection<String> fileNames) {
< prev index next >