From 6419a47e61a5b15b6b37c57faa7381aa289b8a31 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 14 Nov 2024 19:10:30 +0100 Subject: [PATCH 1/3] Add smoke test for linkable runtime --- .../src/net/adoptium/test/FeatureTests.java | 80 ++++++++++++++++--- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java index 6c22f83e6..e1395d460 100644 --- a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java +++ b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java @@ -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; @@ -40,6 +43,68 @@ public class FeatureTests { private final JdkPlatform jdkPlatform = new JdkPlatform(); + private String testJdkHome = null; + + @BeforeTest + public void ensureTestJDKSet() { + String testJdkHome = System.getenv("TEST_JDK_HOME"); + if (testJdkHome == null) { + throw new AssertionError("TEST_JDK_HOME is not set"); + } + this.testJdkHome = testJdkHome; + } + + /** + * Tests whether JEP 493 is enabled for Eclipse Temurin builds + * + * @see JEP 493: Linking Run-Time Images without JMODs + */ + @Test + public void testLinkableRuntimeJDK24Plus() { + // Only JDK 24 and better and temurin builds have this enabled + if (jdkVersion.isNewerOrEqual(24) && isVendorAdoptium()) { + List 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. *

@@ -53,10 +118,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))) { @@ -73,7 +134,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) @@ -116,10 +177,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)) { @@ -184,10 +241,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)) { @@ -213,4 +266,5 @@ public void testJFRAvailable() { throw new RuntimeException("Failed to launch JVM", e); } } + } From 224a74d2fe9e1497e7cc5956a61bfc1e49eeba1c Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Fri, 15 Nov 2024 10:46:36 +0100 Subject: [PATCH 2/3] Fix linting errors --- .../src/net/adoptium/test/FeatureTests.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java index e1395d460..ea9e5fdea 100644 --- a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java +++ b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java @@ -46,16 +46,16 @@ public class FeatureTests { private String testJdkHome = null; @BeforeTest - public void ensureTestJDKSet() { - String testJdkHome = System.getenv("TEST_JDK_HOME"); - if (testJdkHome == null) { + 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 = testJdkHome; + this.testJdkHome = tmpJdkHome; } /** - * Tests whether JEP 493 is enabled for Eclipse Temurin builds + * Tests whether JEP 493 is enabled for Eclipse Temurin builds. * * @see JEP 493: Linking Run-Time Images without JMODs */ From 26b69deed093380bc2cc10725d2870c163189626 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Fri, 15 Nov 2024 10:51:31 +0100 Subject: [PATCH 3/3] More linter fixes --- .../buildAndPackage/src/net/adoptium/test/FeatureTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java index ea9e5fdea..976e92b74 100644 --- a/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java +++ b/test/functional/buildAndPackage/src/net/adoptium/test/FeatureTests.java @@ -45,6 +45,9 @@ public class FeatureTests { 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");