Skip to content

Commit

Permalink
8294993: LingeredApp test update
Browse files Browse the repository at this point in the history
Reviewed-by: cjplummer, amenkov
  • Loading branch information
kevinjwalls committed Oct 25, 2022
1 parent f37a605 commit 9051dde
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
69 changes: 50 additions & 19 deletions test/lib/jdk/test/lib/apps/LingeredApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package jdk.test.lib.apps;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand Down Expand Up @@ -60,7 +62,7 @@
*
* for use custom LingeredApp (class SmartTestApp extends LingeredApp):
*
* SmartTestApp = new SmartTestApp();
* SmartTestApp a = new SmartTestApp();
* LingeredApp.startApp(a, cmd);
* // do something
* a.stopApp(); // LingeredApp.stopApp(a) can be used as well
Expand All @@ -70,7 +72,7 @@
* a = new SmartTestApp("MyLock.lck");
* a.createLock();
* a.runAppExactJvmOpts(Utils.getTestJavaOpts());
* a.waitAppReady();
* a.waitAppReadyOrCrashed();
* // do something
* a.deleteLock();
* a.waitAppTerminate();
Expand Down Expand Up @@ -263,14 +265,18 @@ public void waitAppTerminate() {
* @param timeout timeout in seconds
* @throws java.io.IOException
*/
public void waitAppReady(long timeout) throws IOException {
public void waitAppReadyOrCrashed(long timeout) throws IOException {
// adjust timeout for timeout_factor and convert to ms
timeout = Utils.adjustTimeout(timeout) * 1000;
long here = epoch();
while (true) {
long epoch = epoch();
if (epoch - here > timeout) {
throw new IOException("App waiting timeout");
// Check for crash or lock modification now, and immediately after sleeping for spinDelay each loop.
if (!appProcess.isAlive()) {
if (forceCrash) {
return; // This is expected. Just return.
} else {
throw new IOException("App exited unexpectedly with " + appProcess.exitValue());
}
}

// Live process should touch lock file every second
Expand All @@ -279,15 +285,10 @@ public void waitAppReady(long timeout) throws IOException {
break;
}

// Make sure process didn't already exit
if (!appProcess.isAlive()) {
if (forceCrash) {
return; // This is expected. Just return.
} else {
throw new IOException("App exited unexpectedly with " + appProcess.exitValue());
}
long timeTaken = epoch() - here;
if (timeTaken > timeout) {
throw new IOException("Timeout: app not started or crashed in " + timeTaken + "ms");
}

try {
Thread.sleep(spinDelay);
} catch (InterruptedException ex) {
Expand All @@ -299,8 +300,8 @@ public void waitAppReady(long timeout) throws IOException {
/**
* Waits for the application to start with the default timeout.
*/
public void waitAppReady() throws IOException {
waitAppReady(forceCrash ? appCoreWaitTime : appWaitTime);
public void waitAppReadyOrCrashed() throws IOException {
waitAppReadyOrCrashed(forceCrash ? appCoreWaitTime : appWaitTime);
}

/**
Expand Down Expand Up @@ -441,15 +442,45 @@ public void stopApp() throws IOException {
* @throws IOException
*/
public static void startAppExactJvmOpts(LingeredApp theApp, String... jvmOpts) throws IOException {
long t1 = System.currentTimeMillis();
theApp.createLock();
try {
theApp.runAppExactJvmOpts(jvmOpts);
theApp.waitAppReady();
theApp.waitAppReadyOrCrashed();
} catch (Exception ex) {
System.out.println("LingeredApp failed to start: " + ex);
theApp.finishApp();
boolean alive = theApp.getProcess() != null && theApp.getProcess().isAlive();
System.out.println("LingeredApp failed to start or failed to crash. isAlive=" + alive + ": " + ex);
// stopApp in case it is still alive, may be able to get output:
if (alive) {
theApp.stopApp();
}
alive = theApp.getProcess() != null && theApp.getProcess().isAlive();
if (!alive) {
theApp.finishApp(); // Calls getOutput(), fails if still alive
}
theApp.deleteLock();
throw ex;
} finally {
long t2 = System.currentTimeMillis();
System.out.println("LingeredApp startup took " + (t2 - t1) + "ms");
checkForDumps();
}
}

/**
* Show any dump files of interest in the current directory.
*/
public static void checkForDumps() {
System.out.println("Check for hs_err_pid/core/mdmp files:");
int count = 0;
FilenameFilter filter = (dir, file) -> (file.startsWith("hs_err_pid") || file.startsWith("core") || file.endsWith("mdmp"));
for (File f : new File(".").listFiles(filter)) {
long fileSize = f.length();
System.out.println(f + " " + (fileSize / 1024 / 1024) + "mb (" + fileSize + " bytes)");
count++;
}
if (count == 0) {
System.out.println("None.");
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/lib/jdk/test/lib/util/CoreUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
Asserts.assertGT(coreFileSize, 0L, "Unexpected core size");

// Make sure the core file is moved into the cwd if not already there.
// Core/minidump usually created in current directory (Linux and Windows).
Path corePath = Paths.get(coreFileLocation);
if (corePath.getParent() != null) {
File parent = new File(coreFileLocation).getParentFile();
File cwdParent = new File(".").getAbsoluteFile().getParentFile();
if (parent != null && !parent.equals(cwdParent)) {
Path coreFileName = corePath.getFileName();
System.out.println("Moving core file to cwd: " + coreFileName);
long startTime = System.currentTimeMillis();
Expand Down

1 comment on commit 9051dde

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.