Skip to content

Commit

Permalink
8327390: JitTester: Implement temporary folder functionality
Browse files Browse the repository at this point in the history
Reviewed-by: gli, lmesnik
  • Loading branch information
Evgeny Nikitin authored and lmesnik committed Mar 7, 2024
1 parent 784f11c commit 5aae803
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 13 deletions.
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/testlibrary/jittester/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2024, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -80,6 +80,7 @@ TESTLIBRARY_SRC_FILES = $(TESTLIBRARY_SRC_DIR)/Asserts.java \
$(TESTLIBRARY_SRC_DIR)/process/OutputBuffer.java \
$(TESTLIBRARY_SRC_DIR)/process/ProcessTools.java \
$(TESTLIBRARY_SRC_DIR)/process/StreamPumper.java \
$(TESTLIBRARY_SRC_DIR)/util/FileUtils.java \
$(TESTLIBRARY_SRC_DIR)/util/Pair.java

.PHONY: cleantmp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -64,13 +64,13 @@ private void generateSources(IRNode mainClass, IRNode privateClasses) {
}

private void compileJavaFile(String mainClassName) {
String classPath = tmpDir.toString();
String classPath = tmpDir.path.toString();
ProcessBuilder pb = new ProcessBuilder(JAVAC,
"-d", classPath,
"-cp", classPath,
generatorDir.resolve(mainClassName + ".java").toString());
try {
int r = runProcess(pb, tmpDir.resolve(mainClassName + ".javac").toString());
int r = runProcess(pb, tmpDir.path.resolve(mainClassName + ".javac").toString());
if (r != 0) {
throw new Error("Can't compile sources, exit code = " + r);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. 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.
*
* 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.
*/

package jdk.test.lib.jittester;

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

import jdk.test.lib.util.FileUtils;

/**
* A temporary directory wrapper.
* Makes sure that the directory gets deleted after usage.
*/
public class TempDir {
public final Path path;

/**
* Creates a temporary directory with a given suffix.
* The directory is deep deleted on VM shutdown using a ShutdownHook.
*/
public TempDir(String suffix) {
try {
path = Files.createTempDirectory(suffix).toAbsolutePath();
Runtime.getRuntime().addShutdownHook(new Thread(this::delete));
} catch (IOException e) {
throw new Error("Can't create a tmp dir for " + suffix, e);
}

System.out.println("DBG: Temp folder created: '" + path + "'");
}

private void delete() {
try {
FileUtils.deleteFileTreeWithRetry(path);
System.out.println("DBG: Temp folder deleted: '" + path + "'");
} catch (IOException exc) {
throw new Error("Could not deep delete '" + path + "'", exc);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -42,7 +42,7 @@ public abstract class TestsGenerator implements BiConsumer<IRNode, IRNode> {
protected static final String JAVAC = Paths.get(JAVA_BIN, "javac").toString();
protected static final String JAVA = Paths.get(JAVA_BIN, "java").toString();
protected final Path generatorDir;
protected final Path tmpDir;
protected final TempDir tmpDir;
protected final Function<String, String[]> preRunActions;
protected final String jtDriverOptions;
private static final String DISABLE_WARNINGS = "-XX:-PrintWarnings";
Expand All @@ -54,17 +54,13 @@ protected TestsGenerator(String suffix) {
protected TestsGenerator(String suffix, Function<String, String[]> preRunActions,
String jtDriverOptions) {
generatorDir = getRoot().resolve(suffix).toAbsolutePath();
try {
tmpDir = Files.createTempDirectory(suffix).toAbsolutePath();
} catch (IOException e) {
throw new Error("Can't get a tmp dir for " + suffix, e);
}
tmpDir = new TempDir(suffix);
this.preRunActions = preRunActions;
this.jtDriverOptions = jtDriverOptions;
}

protected void generateGoldenOut(String mainClassName) {
String classPath = tmpDir.toString() + File.pathSeparator
String classPath = tmpDir.path.toString() + File.pathSeparator
+ generatorDir.toString();
ProcessBuilder pb = new ProcessBuilder(JAVA, "-Xint", DISABLE_WARNINGS, "-Xverify",
"-cp", classPath, mainClassName);
Expand Down Expand Up @@ -97,7 +93,7 @@ protected static int runProcess(ProcessBuilder pb, String name)
protected void compilePrinter() {
Path root = getRoot();
ProcessBuilder pbPrinter = new ProcessBuilder(JAVAC,
"-d", tmpDir.toString(),
"-d", tmpDir.path.toString(),
root.resolve("jdk")
.resolve("test")
.resolve("lib")
Expand Down

3 comments on commit 5aae803

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@SoniaZaldana
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 5aae803 Dec 2, 2024

Choose a reason for hiding this comment

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

@SoniaZaldana the backport was successfully created on the branch backport-SoniaZaldana-5aae8030-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5aae8030 from the openjdk/jdk repository.

The commit being backported was authored by Evgeny Nikitin on 7 Mar 2024 and was reviewed by Guoxiong Li and Leonid Mesnik.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-5aae8030-master:backport-SoniaZaldana-5aae8030-master
$ git checkout backport-SoniaZaldana-5aae8030-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-5aae8030-master

Please sign in to comment.