Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getUnixPID() for jdk11+ and stop waiting for tests after 10 min #11199

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions test/functional/cmdline_options_tester/src/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -73,6 +74,7 @@ class Test {

static String archName = System.getProperty("os.arch");
static boolean isRiscv = archName.toLowerCase().contains("riscv");
static boolean isJava8 = System.getProperty("java.specification.version").equals("1.8");

/**
* Create a new test case with the given id.
Expand Down Expand Up @@ -224,7 +226,10 @@ public boolean run(long defaultTimeout) {
TestSuite.printErrorMessage("stderr timed out");
}

proc.waitFor();
// Wait an additional 10 min after the regular timeout for the process to finish.
// It should finish because the ProcessKiller terminates it, but if it doesn't
// then don't wait forever.
proc.waitFor(_timeout + (10 * 60 * 1000), TimeUnit.MILLISECONDS);

testTimer.stop();
timer = testTimer.getTimeSpent();
Expand Down Expand Up @@ -411,14 +416,24 @@ public void dumpVerboseOutput(boolean result) {
}

public static int getUnixPID(Process process) throws Exception {
Class<?> cl = process.getClass();
if (!cl.getName().equals("java.lang.UNIXProcess") || isRiscv) {
if (isRiscv) {
return 0;
}
Field field = cl.getDeclaredField("pid");
field.setAccessible(true);
Object pidObject = field.get(process);
return ((Integer) pidObject).intValue();
if (isJava8) {
Class<?> cl = process.getClass();
if (!cl.getName().equals("java.lang.UNIXProcess")) {
return 0;
}
Field field = cl.getDeclaredField("pid");
field.setAccessible(true);
Object pidObject = field.get(process);
return ((Integer) pidObject).intValue();
} else {
// if not Java 8 then it must be Java 11 or later
Method pidMethod = Process.class.getMethod("pid");
Long pid = (Long)pidMethod.invoke(process);
return pid.intValue();
}
}

private final class StreamMatcher extends Thread {
Expand Down