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

Add basic jlink smoke test for Temurin #4067

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ********************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) with this work for additional
* information regarding copyright ownership.
Expand All @@ -15,20 +15,27 @@

package net.adoptium.test;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import static net.adoptium.test.JdkPlatform.Architecture;
import static net.adoptium.test.JdkPlatform.OperatingSystem;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import net.adoptium.test.JdkPlatform.Architecture;
import net.adoptium.test.JdkPlatform.OperatingSystem;

/**
* Tests the availability of various features like garbage collectors, flight recorder, that need to be enabled via
Expand Down Expand Up @@ -104,6 +111,68 @@ public void testLinkableRuntimeJDK24Plus() {
}
}

/**
* Tests whether basic jlink works using the default module path. The only
* included module in the output image is {@code java.base}.
*/
@Test
public void testJlinkJdk11AndBetter() throws IOException {
// Only JDK 11 (JDK 9, really) and better have jlink
if (jdkVersion.isNewerOrEqual(11)) {
Path output = Paths.get("java.base-image");
ensureOutputDirectoryDeleted(output);
List<String> command = new ArrayList<>();
command.add(String.format("%s/bin/jlink", testJdkHome));
command.add("--add-modules");
command.add("java.base");
command.add("--output");
command.add(output.toString());
command.add("--verbose");

try {
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.inheritIO();
Process process = processBuilder.start();

if (process.waitFor() != 0) {
throw new AssertionError("Basic jlink smoke test failed! " + command);
}
LOGGER.info("Basic jlink smoke test passed. Command was: " + command);
} catch (InterruptedException | IOException e) {
throw new RuntimeException("Failed to launch JVM", e);
} finally {
ensureOutputDirectoryDeleted(output);
}
}
}

private static void ensureOutputDirectoryDeleted(final Path path) throws IOException {
if (Files.exists(path)) {
deleteDirRecursively(path);
}
}

private static void deleteDirRecursively(final Path path) throws IOException {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

@Override
public FileVisitResult postVisitDirectory(final Path dir, final IOException e) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if (Files.isDirectory(file)) {
// deleted in post-visit
return FileVisitResult.CONTINUE;
}
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
}

private boolean isVendorAdoptium() {
return System.getProperty("java.vendor", "").toLowerCase(Locale.US).contains("adoptium");
}
Expand Down
Loading