8294993: LingeredApp test update
Reviewed-by: cjplummer, amenkov
This commit is contained in:
parent
f37a6055c4
commit
9051dded84
@ -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;
|
||||
@ -60,7 +62,7 @@ import jdk.test.lib.util.CoreUtils;
|
||||
*
|
||||
* 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
|
||||
@ -70,7 +72,7 @@ import jdk.test.lib.util.CoreUtils;
|
||||
* a = new SmartTestApp("MyLock.lck");
|
||||
* a.createLock();
|
||||
* a.runAppExactJvmOpts(Utils.getTestJavaOpts());
|
||||
* a.waitAppReady();
|
||||
* a.waitAppReadyOrCrashed();
|
||||
* // do something
|
||||
* a.deleteLock();
|
||||
* a.waitAppTerminate();
|
||||
@ -263,23 +265,12 @@ public class LingeredApp {
|
||||
* @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");
|
||||
}
|
||||
|
||||
// Live process should touch lock file every second
|
||||
long lm = lastModified(lockFileName);
|
||||
if (lm > lockCreationTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Make sure process didn't already exit
|
||||
// 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.
|
||||
@ -288,6 +279,16 @@ public class LingeredApp {
|
||||
}
|
||||
}
|
||||
|
||||
// Live process should touch lock file every second
|
||||
long lm = lastModified(lockFileName);
|
||||
if (lm > lockCreationTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -299,8 +300,8 @@ public class LingeredApp {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,15 +442,45 @@ public class LingeredApp {
|
||||
* @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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,8 +113,11 @@ public class CoreUtils {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user