Skip to content
6 changes: 1 addition & 5 deletions test/jdk/jdk/crac/CPUFeatures/SimpleCPUFeaturesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

import jdk.test.lib.crac.*;
import jdk.test.lib.process.OutputAnalyzer;

/*
* @test id=NAMED
Expand Down Expand Up @@ -104,15 +103,12 @@ private enum ErrorMsg {
@Override
public void test() throws Exception {
CracBuilder builder = new CracBuilder()
.captureOutput(true)
.vmOption("-XX:CPUFeatures=" + cpuFeatures)
.vmOption("-XX:+ShowCPUFeatures");
if (glibcTunables != null && !"--".equals(glibcTunables)) {
builder.env("GLIBC_TUNABLES", glibcTunables);
}
CracProcess process = builder.startPlain();
process.waitFor();
OutputAnalyzer oa = process.outputAnalyzer();
final var oa = builder.doPlainToAnalyze();
if (error == null) {
oa.shouldHaveExitValue(0)
.stdoutShouldContain(SUCCESS);
Expand Down
21 changes: 9 additions & 12 deletions test/jdk/jdk/crac/CheckpointRestorePathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@

import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.concurrent.Callable;

import static jdk.test.lib.Asserts.assertEquals;
import static jdk.test.lib.Asserts.assertTrue;

/**
Expand Down Expand Up @@ -78,15 +75,15 @@ void testNone() throws Exception {
}

void checkNotConfigured(CracBuilder builder) throws Exception {
builder.captureOutput(true)
.startCheckpoint().outputAnalyzer()
builder
.doCheckpointToAnalyze()
.shouldHaveExitValue(1)
.stderrShouldContain("C/R is not configured");
}

void testDeep() throws Exception {
new CracBuilder().engine(CracEngine.SIMULATE).imageDir(DEEPLY_NESTED_CR).captureOutput(true)
.startCheckpoint().outputAnalyzer()
new CracBuilder().engine(CracEngine.SIMULATE).imageDir(DEEPLY_NESTED_CR)
.doCheckpointToAnalyze()
.shouldHaveExitValue(1)
// unified logging going to standard output rather than stderr by default
.stdoutShouldContain("Cannot create CRaCCheckpointTo=" + DEEPLY_NESTED_CR);
Expand All @@ -95,15 +92,15 @@ void testDeep() throws Exception {
void testRestoreEmpty() throws Exception {
// Empty CRaCRestoreFrom should result in default java usage output
// as if the VM option was missing (we won't test that case)
new CracBuilder().engine(CracEngine.PAUSE).imageDir("").captureOutput(true)
.startRestore().outputAnalyzer()
new CracBuilder().engine(CracEngine.PAUSE).imageDir("")
.doRestoreToAnalyze()
.shouldHaveExitValue(1)
.stderrShouldContain("Usage: java");
}

void testRestoreNoDir() throws Exception {
new CracBuilder().engine(CracEngine.PAUSE).imageDir(NON_EXISTENT_CR).captureOutput(true)
.startRestore().outputAnalyzer()
new CracBuilder().engine(CracEngine.PAUSE).imageDir(NON_EXISTENT_CR)
.doRestoreToAnalyze()
.shouldHaveExitValue(1)
.stdoutShouldContain("Cannot open CRaCRestoreFrom=" + NON_EXISTENT_CR)
.stdoutShouldContain("Failed to restore from " + NON_EXISTENT_CR);
Expand All @@ -127,7 +124,7 @@ void testRestoreNoImage(boolean skipCpuFeatures, String errMessage) throws Excep
if (skipCpuFeatures) {
builder.vmOption("-XX:+UnlockExperimentalVMOptions").vmOption("-XX:CheckCPUFeatures=skip");
}
builder.captureOutput(true).startRestore().outputAnalyzer()
builder.doRestoreToAnalyze()
.shouldHaveExitValue(1)
.stderrShouldContain(errMessage);
}
Expand Down
5 changes: 2 additions & 3 deletions test/jdk/jdk/crac/ContainerOOMETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void test() throws Exception {
DockerTestUtils.checkCanUseResourceLimits();
final String imageName = Common.imageName("oome-test");
CracContainerBuilder builder = new CracContainerBuilder()
.captureOutput(true)
.inDockerImage(imageName)
.dockerOptions("-m", "256M")
.runContainerDirectly(true)
Expand All @@ -60,10 +59,10 @@ public void test() throws Exception {
.vmOption("-Xmx4G")
.vmOption("-XX:CRaCMaxHeapSizeBeforeCheckpoint=128M");
try {
builder.startCheckpoint().outputAnalyzer()
builder.doCheckpointToAnalyze()
.shouldHaveExitValue(137) // checkpoint
.stderrShouldContain(AFTER_OOME);
builder.clearDockerOptions().clearVmOptions().captureOutput(false);
builder.clearDockerOptions().clearVmOptions();
builder.doRestore();
} finally {
builder.ensureContainerKilled();
Expand Down
17 changes: 6 additions & 11 deletions test/jdk/jdk/crac/ContainerPidAdjustmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import jdk.test.lib.containers.docker.Common;
import jdk.test.lib.crac.CracContainerBuilder;
import jdk.test.lib.crac.CracEngine;
import jdk.test.lib.crac.CracProcess;
import jdk.test.lib.crac.CracTest;
import jdk.test.lib.crac.CracTestArg;
import jdk.test.lib.process.OutputAnalyzer;

import static jdk.test.lib.Asserts.assertEquals;
import static jdk.test.lib.Asserts.assertLessThan;

/*
Expand Down Expand Up @@ -93,9 +91,6 @@ public void test() throws Exception {
if (needSetMinPid) {
builder.vmOption("-XX:CRaCMinPid=" + createLastPidValue(lastPid));
}
if (0 > expectedLastPid) {
builder.captureOutput(true);
}
if (null != lastPidSetup) {
// Set up the initial last pid,
// create a non-privileged user,
Expand All @@ -113,14 +108,14 @@ public void test() throws Exception {
}

if (0 < expectedLastPid) {
builder.startCheckpoint().waitForSuccess();
// Cannot use doCheckpoint because for CRIU it expects the process to be killed on checkpoint
try (var p = builder.startCheckpoint()) {
p.waitForSuccess();
}
} else {
final int expectedExitValue = (int)java.lang.Math.abs(expectedLastPid);
CracProcess process = builder.startCheckpoint();
final int exitValue = process.waitFor();
assertEquals(expectedExitValue, exitValue, "Process returned unexpected exit code: " + exitValue);
OutputAnalyzer oa = process.outputAnalyzer();
oa.shouldNotContain(CURRENT_PID_MESSAGE);
OutputAnalyzer oa = builder.doCheckpointToAnalyze();
oa.shouldHaveExitValue(expectedExitValue).shouldNotContain(CURRENT_PID_MESSAGE);
if (null != lastPidSetup) {
oa.shouldContain("spin_last_pid: Invalid argument (" + lastPid + ")");
}
Expand Down
6 changes: 3 additions & 3 deletions test/jdk/jdk/crac/CracLogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class CracLogTest implements CracTest {
@Override
public void test() throws Exception {
var builder = new CracBuilder()
.engine(CracEngine.SIMULATE)
.captureOutput(true);
.engine(CracEngine.SIMULATE);
if (!logLevelStr.equals("not-set")) {
builder = builder.vmOption("-Xlog:crac=" + logLevelStr);
}
final var out = builder.startCheckpoint().waitForSuccess().outputAnalyzer();
final var out = builder.doCheckpointToAnalyze();
out.shouldHaveExitValue(0);

final var checkpointLogLevel = logLevelStrToInt(CHECKPOINT_LOG_LEVEL);
final var selectedLogLevel = logLevelStrToInt(logLevelStr);
Expand Down
63 changes: 27 additions & 36 deletions test/jdk/jdk/crac/DaemonAfterRestore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

import jdk.crac.*;
import jdk.test.lib.crac.CracBuilder;
import jdk.test.lib.crac.CracProcess;
import jdk.test.lib.crac.CracTest;

import java.util.concurrent.CompletableFuture;
import java.lang.ref.Reference;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static jdk.test.lib.Asserts.assertFalse;
import static jdk.test.lib.Asserts.assertTrue;

/**
* @test
Expand All @@ -46,32 +45,38 @@ public class DaemonAfterRestore implements CracTest {

@Override
public void test() throws Exception {
CracBuilder builder = new CracBuilder().captureOutput(true);
CracBuilder builder = new CracBuilder();

CompletableFuture<?> firstOutputFuture = new CompletableFuture<Void>();
CracProcess checkpointProcess = builder.startCheckpoint().watch(
outline -> {
System.out.println(outline);
if (outline.equals(MAIN_THREAD_FINISH)) {
firstOutputFuture.complete(null);
}
},
errline -> {
System.err.println("ERROR: " + errline);
firstOutputFuture.cancel(false);
});
firstOutputFuture.get(10, TimeUnit.SECONDS);
builder.checkpointViaJcmd(checkpointProcess.pid());
checkpointProcess.waitForCheckpointed();
try (var checkpointProcess = builder.startCheckpoint()) {
checkpointProcess.waitForStdout(MAIN_THREAD_FINISH, false);
builder.checkpointViaJcmd(checkpointProcess.pid());
checkpointProcess.waitForCheckpointed();
}

builder.startRestore().waitForSuccess()
.outputAnalyzer().shouldContain(AFTER_RESTORE_MESSAGE);
builder.doRestoreToAnalyze()
.shouldHaveExitValue(0)
.shouldContain(AFTER_RESTORE_MESSAGE);
}

@Override
public void exec() throws RestoreException, CheckpointException {
CountDownLatch start = new CountDownLatch(1);
CountDownLatch finish = new CountDownLatch(1);

Resource resource = new Resource() {
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
assertTrue(Thread.currentThread().isDaemon(), "beforeCheckpoint is expected to be called from daemon thread");
finish.countDown();
}
@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
Thread.sleep(3000);
System.out.println(AFTER_RESTORE_MESSAGE);
}
};
Core.getGlobalContext().register(resource);

Thread workerThread = new Thread(() -> {
System.out.println("worker thread start");
start.countDown();
Expand All @@ -80,6 +85,7 @@ public void exec() throws RestoreException, CheckpointException {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Reference.reachabilityFence(resource);
System.out.println("worker thread finish");
});
assertFalse(workerThread.isDaemon());
Expand All @@ -91,21 +97,6 @@ public void exec() throws RestoreException, CheckpointException {
throw new RuntimeException(e);
}

Resource resource = new Resource() {
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
assert Thread.currentThread().isDaemon() : "beforeCheckpoint is expected to be called from daemon thread";
finish.countDown();
}
@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
Thread.sleep(3000);
System.out.println(AFTER_RESTORE_MESSAGE);
}
};

Core.getGlobalContext().register(resource);

System.out.println(MAIN_THREAD_FINISH);
}
}
4 changes: 1 addition & 3 deletions test/jdk/jdk/crac/DryRunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import jdk.crac.*;
import jdk.test.lib.crac.CracBuilder;
Expand All @@ -50,8 +49,7 @@ public void afterRestore(Context<? extends Resource> context) throws Exception {

@Override
public void test() throws Exception {
new CracBuilder().engine(CracEngine.SIMULATE).printResources(true)
.startCheckpoint().waitForSuccess();
new CracBuilder().engine(CracEngine.SIMULATE).printResources(true).doCheckpoint();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/jdk/crac/FailedResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class FailedResourceTest implements CracTest {

@Override
public void test() throws Exception {
new CracBuilder().engine(CracEngine.SIMULATE).startCheckpoint().waitForSuccess();
new CracBuilder().engine(CracEngine.SIMULATE).doCheckpoint();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
public class JarFileFactoryCacheTest implements CracTest {
@Override
public void test() throws Exception {
new CracBuilder().engine(CracEngine.SIMULATE).printResources(true)
.startCheckpoint().waitForSuccess();
new CracBuilder().engine(CracEngine.SIMULATE).printResources(true).doCheckpoint();
}

@Override
Expand Down
28 changes: 11 additions & 17 deletions test/jdk/jdk/crac/JcmdArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import jdk.test.lib.util.FileUtils;

import java.io.IOException;
import java.lang.ref.Reference;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.LinkedBlockingQueue;

import static jdk.test.lib.Asserts.assertEquals;
import static jdk.test.lib.Asserts.assertTrue;
Expand All @@ -61,15 +61,8 @@ public void test() throws Exception {
FileUtils.deleteFileTreeWithRetry(imageDir);
}

CracProcess process = new CracBuilder().engine(CracEngine.SIMULATE).captureOutput(true).startCheckpoint();
var queue = new LinkedBlockingQueue<String>();
process.watch(line -> {
System.out.println(line);
if (line.startsWith("TEST:")) {
queue.add(line);
}
}, System.err::println);
assertEquals(READY, queue.take());
CracProcess process = new CracBuilder().engine(CracEngine.SIMULATE).startCheckpoint();
process.waitForStdout(READY, false);
String[] args;
if (useFile) {
Path metricsPath = createTemp("metrics", "dummy\t=45\n foo.bar = 123.0 \n");
Expand All @@ -79,9 +72,8 @@ public void test() throws Exception {
args = new String[] { "metrics=foo.bar=123", "labels=xxx=yyy" };
}
new CracBuilder().engine(CracEngine.SIMULATE).checkpointViaJcmd(process.pid(), args);
assertEquals(CHECKPOINTED, queue.take());
process.input().write('\n');
process.input().flush();
process.waitForStdout(CHECKPOINTED, false);
process.sendNewline();
process.waitForSuccess();

assertTrue(Files.readAllLines(imageDir.resolve("score")).stream()
Expand All @@ -99,17 +91,19 @@ private static Path createTemp(String name, String text) throws IOException {

@Override
public void exec() throws Exception {
Core.getGlobalContext().register(new Resource() {
final var resource = new Resource() {
@Override
public void beforeCheckpoint(Context<? extends Resource> context) {
}

@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
public void afterRestore(Context<? extends Resource> context) {
System.out.println(CHECKPOINTED);
}
});
};
Core.getGlobalContext().register(resource);
System.out.println(READY);
System.in.read();
assertEquals((int) '\n', System.in.read());
Reference.reachabilityFence(resource);
}
}
6 changes: 3 additions & 3 deletions test/jdk/jdk/crac/KeepRunningTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class KeepRunningTest implements CracTest {

@Override
public void test() throws Exception {
CracBuilder builder = new CracBuilder().engine(engine).engineOptions("keep_running=true").captureOutput(true);
builder.startCheckpoint().waitForSuccess().outputAnalyzer().shouldContain(RESTORED_MESSAGE);
builder.engineOptions().doRestore().outputAnalyzer().shouldContain(RESTORED_MESSAGE);
CracBuilder builder = new CracBuilder().engine(engine).engineOptions("keep_running=true");
builder.doCheckpointToAnalyze().shouldHaveExitValue(0).shouldContain(RESTORED_MESSAGE);
builder.engineOptions().doRestoreToAnalyze().shouldHaveExitValue(0).shouldContain(RESTORED_MESSAGE);
}

@Override
Expand Down
Loading