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

Test CRIU restore with output redirected to file during checkpoint #132

Draft
wants to merge 1 commit into
base: crac
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
60 changes: 60 additions & 0 deletions test/jdk/jdk/crac/fileDescriptors/OutputToFileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2022, Azul Systems, Inc. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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 jdk.crac.Core;
import jdk.test.lib.crac.CracBuilder;
import jdk.test.lib.crac.CracTest;

import java.nio.file.Files;
import java.nio.file.Path;

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

/**
* @test
* @requires (os.family == "linux")
* @library /test/lib
* @build OutputToFileTest
* @run driver jdk.test.lib.crac.CracTest
*/
public class OutputToFileTest implements CracTest {
@Override
public void test() throws Exception {
Path stdin = Files.createTempFile(getClass().getSimpleName(), ".in");
Files.writeString(stdin, "foobar");
Path stdout = Files.createTempFile(getClass().getSimpleName(), ".out");
Path stderr = Files.createTempFile(getClass().getSimpleName(), ".err");
new CracBuilder().inputFrom(stdin).outputTo(stdout, stderr).doCheckpoint();
assertTrue(stdin.toFile().delete());
assertTrue(stdout.toFile().delete());
assertTrue(stderr.toFile().delete());
new CracBuilder().doRestore();
}

@Override
public void exec() throws Exception {
Core.checkpointRestore();
}
}
15 changes: 14 additions & 1 deletion test/lib/jdk/test/lib/crac/CracBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jdk.test.lib.containers.docker.DockerfileConfig;
import jdk.test.lib.util.FileUtils;

import javax.imageio.IIOException;
import java.io.File;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -46,6 +45,9 @@ public class CracBuilder {
Class<?> main;
String[] args;
boolean captureOutput;
Path stdinPath;
Path stdoutPath;
Path stderrPath;
String dockerImageBaseName;
String dockerImageBaseVersion;
String dockerImageName;
Expand Down Expand Up @@ -199,6 +201,17 @@ public CracBuilder captureOutput(boolean captureOutput) {
return this;
}

public CracBuilder inputFrom(Path stdinPath) {
this.stdinPath = stdinPath;
return this;
}

public CracBuilder outputTo(Path stdoutPath, Path stderrPath) {
this.stdoutPath = stdoutPath;
this.stderrPath = stderrPath;
return this;
}

public CracBuilder withBaseImage(String name, String tag) {
assertNull(dockerImageBaseName);
assertNull(dockerImageBaseVersion);
Expand Down
12 changes: 12 additions & 0 deletions test/lib/jdk/test/lib/crac/CracProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.StreamPumper;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
Expand All @@ -24,6 +25,17 @@ public CracProcess(CracBuilder builder, List<String> cmd) throws IOException {
if (builder.captureOutput) {
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
pb.redirectError(ProcessBuilder.Redirect.PIPE);
assertNull(builder.stdoutPath);
assertNull(builder.stderrPath);
}
if (builder.stdinPath != null) {
pb.redirectInput(builder.stdinPath.toFile());
}
if (builder.stdoutPath != null) {
pb.redirectOutput(builder.stdoutPath.toFile());
}
if (builder.stderrPath != null) {
pb.redirectError(builder.stderrPath.toFile());
}
pb.environment().putAll(builder.env);
this.process = pb.command(cmd).start();
Expand Down