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 smoke test for enabled JEP 493 for Eclipse Temurin builds #4040

Merged
merged 3 commits into from
Nov 16, 2024
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
Expand Up @@ -15,12 +15,15 @@

package net.adoptium.test;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.io.IOException;
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;
Expand All @@ -40,6 +43,71 @@ public class FeatureTests {

private final JdkPlatform jdkPlatform = new JdkPlatform();

private String testJdkHome = null;

/**
* Ensure TEST_JDK_HOME environment variable is set for every test in this class.
*/
@BeforeTest
public final void ensureTestJDKSet() {
String tmpJdkHome = System.getenv("TEST_JDK_HOME");
if (tmpJdkHome == null) {
throw new AssertionError("TEST_JDK_HOME is not set");
}
this.testJdkHome = tmpJdkHome;
}

/**
* Tests whether JEP 493 is enabled for Eclipse Temurin builds.
*
* @see <a href="https://openjdk.java.net/jeps/493">JEP 493: Linking Run-Time Images without JMODs</a>
*/
@Test
public void testLinkableRuntimeJDK24Plus() {
// Only JDK 24 and better and temurin builds have this enabled
if (jdkVersion.isNewerOrEqual(24) && isVendorAdoptium()) {
List<String> command = new ArrayList<>();
command.add(String.format("%s/bin/jlink", testJdkHome));
command.add("-J-Duser.lang=en");
command.add("--help");

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

String stdout = StreamUtils.consumeStream(process.getInputStream());
if (process.waitFor() != 0) {
throw new AssertionError("Could not run jlink --help");
}
String[] lines = stdout.split(Pattern.quote(System.lineSeparator()));
boolean seenCapabilities = false;
String capLine = "";
for (int i = 0; i < lines.length; i++) {
if (lines[i].trim().startsWith("Capabilities:")) {
seenCapabilities = true;
continue; // skip Capabilities line
}
if (!seenCapabilities) {
continue;
}
if (seenCapabilities) {
capLine = lines[i].trim();
break;
}
}
LOGGER.info(String.format("Matched 'Capabilities:' line: %s", capLine));
assertEquals(capLine, "Linking from run-time image enabled",
"jlink should have enabled run-time image link capability");
} catch (InterruptedException | IOException e) {
throw new RuntimeException("Failed to launch JVM", e);
}
}
}

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

/**
* Tests whether Shenandoah GC is available.
* <p/>
Expand All @@ -53,10 +121,6 @@ public class FeatureTests {
*/
@Test
public void testShenandoahAvailable() {
String testJdkHome = System.getenv("TEST_JDK_HOME");
if (testJdkHome == null) {
throw new AssertionError("TEST_JDK_HOME is not set");
}

boolean shouldBePresent = false;
if ((jdkVersion.isNewerOrEqual(15) || jdkVersion.isNewerOrEqualSameFeature(11, 0, 9))) {
Expand All @@ -73,7 +137,7 @@ public void testShenandoahAvailable() {
}
}
if (jdkVersion.isNewerOrEqual(17) && jdkPlatform.runsOn(OperatingSystem.LINUX, Architecture.PPC64LE)) {
shouldBePresent = true;
shouldBePresent = true;
}
if (jdkVersion.isNewerOrEqual(19)
|| jdkVersion.isNewerOrEqualSameFeature(17, 0, 9)
Expand Down Expand Up @@ -116,10 +180,6 @@ public void testShenandoahAvailable() {
*/
@Test
public void testZGCAvailable() {
String testJdkHome = System.getenv("TEST_JDK_HOME");
if (testJdkHome == null) {
throw new AssertionError("TEST_JDK_HOME is not set");
}

boolean shouldBePresent = false;
if (jdkVersion.isNewerOrEqual(15)) {
Expand Down Expand Up @@ -184,10 +244,6 @@ public void testZGCAvailable() {
*/
@Test
public void testJFRAvailable() {
String testJdkHome = System.getenv("TEST_JDK_HOME");
if (testJdkHome == null) {
throw new AssertionError("TEST_JDK_HOME is not set");
}
boolean shouldBePresent = false;
if (jdkVersion.isNewerOrEqual(11) || jdkVersion.isNewerOrEqualSameFeature(8, 0, 262)) {
if (!jdkPlatform.runsOn(OperatingSystem.AIX) || jdkVersion.isNewerOrEqual(20)) {
Expand All @@ -213,4 +269,5 @@ public void testJFRAvailable() {
throw new RuntimeException("Failed to launch JVM", e);
}
}

}
Loading