Skip to content

Commit

Permalink
Fixed Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Karm committed Dec 5, 2023
1 parent 075aa33 commit bfd35de
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ linux.executable.size.threshold.kB=90000
```

Properties are being added to a map top to bottom, overwriting their previous values
unless an `@If` constraint fails.
unless an `@If` constraint fails. If a condition fails, the following properties are
not added to the map until the next `@If` constraint is met.

If two `@If` constraints follow immediately one after the other, they both MUST be true
to process the following properties.

Take a look at [ThresholdsTest.java](./ThresholdsTest.java) and its `threshold-*.conf` test [files](../../../../../../../../test/resources/) for a comprehensive overview.

The parsing logic is compatible with plain `.properties` files as we have been using before,
i.e. any key-value pair where the value is interpreted as the long type.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.graalvm.tests.integration.utils.thresholds;

import org.apache.logging.log4j.util.Strings;
import org.graalvm.home.Version;
import org.graalvm.tests.integration.utils.versions.QuarkusVersion;
import org.graalvm.tests.integration.utils.versions.UsedVersion;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -151,7 +152,13 @@ public static Boolean ifMandrel(final String line) {
final String minJDK = mVerMatch.group("minJDK");
final String maxJDK = mVerMatch.group("maxJDK");
final boolean inContainer = Boolean.parseBoolean(mVerMatch.group("inContainer"));
return (jdkConstraintSatisfied(minJDK, maxJDK, inContainer) && mandrelConstraintSatisfied(UsedVersion.getVersion(inContainer), min, max));
Version version = UsedVersion.getVersion(inContainer);
if (inContainer && version == null) {
LOGGER.error("There is probably no container runtime configured and thus no way to " +
"determine the version of Mandrel for `inContainer = true`. Trying to fall back to the host runtime.");
version = UsedVersion.getVersion(false);
}
return (jdkConstraintSatisfied(minJDK, maxJDK, inContainer) && mandrelConstraintSatisfied(version, min, max));
}
LOGGER.error("Line '" + line + "' does not match the pattern '" + MVERSION_PATTERN.pattern() + "' although it starts with '@IfMandrel.*'. Ignoring.");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import java.util.Map;
import java.util.regex.Matcher;

import static java.lang.System.clearProperty;
import static java.lang.System.lineSeparator;
import static java.lang.System.setProperty;
import static org.graalvm.tests.integration.RuntimesSmokeTest.BASE_DIR;
import static org.graalvm.tests.integration.utils.Commands.IS_THIS_WINDOWS;
import static org.graalvm.tests.integration.utils.Commands.getProperty;
Expand Down Expand Up @@ -135,63 +138,55 @@ public void testQuarkusVersion(String expression, String min, String max) {
// Native-image version string | Config file | Q version | a | b | c
"native-image 21.0.1 2023-10-17\\n" +
"OpenJDK Runtime Environment Mandrel-23.1.1.0-Final (build 21.0.1+12-LTS)\\n" +
"OpenJDK 64-Bit Server VM Mandrel-23.1.1.0-Final (build 21.0.1+12-LTS, mixed mode)\\n | threshold-1.conf | 3.3.3.Final | 150 | 250 | 350 ",
"OpenJDK 64-Bit Server VM Mandrel-23.1.1.0-Final (build 21.0.1+12-LTS, mixed mode) | threshold-1.conf | 3.3.3.Final | 150 | 250 | 350 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 21.0.1 2023-10-17\\n" +
"GraalVM Runtime Environment GraalVM CE 21.0.1-dev+12.1 (build 21.0.1+12-jvmci-23.1-b22)\\n" +
"Substrate VM GraalVM CE 21.0.1-dev+12.1 (build 21.0.1+12, serial gc)\\n | threshold-1.conf | 3.1.9.Final | 160 | 260 | 360 ",
"Substrate VM GraalVM CE 21.0.1-dev+12.1 (build 21.0.1+12, serial gc) | threshold-1.conf | 3.1.9.Final | 160 | 260 | 360 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 23 2026-09-01\\n" +
"GraalVM Runtime Environment GraalVM CE 23+35.1 (build 23+35-jvmci-24.1-b99)\\n" +
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc)\\n | threshold-1.conf | 3.7.0 | 170 | 270 | 100 ",
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc) | threshold-1.conf | 3.7.0 | 170 | 270 | 100 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 21.3.6.0-Final Mandrel Distribution (Java Version 17.0.7+7)\\n | threshold-1.conf | 3.6.0 | N/A | 90 | 100 ",
"native-image 21.3.6.0-Final Mandrel Distribution (Java Version 17.0.7+7) | threshold-1.conf | 3.6.0 | N/A | 90 | 100 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 22.3.4.0-Final Mandrel Distribution (Java Version 17.0.9+9)\\n | threshold-2.conf | 2.7.9.Final | 200 | 300 | 400 ",
"native-image 22.3.4.0-Final Mandrel Distribution (Java Version 17.0.9+9) | threshold-2.conf | 2.7.9.Final | 200 | 300 | 400 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 17.0.9 2023-10-17\\n" +
"OpenJDK Runtime Environment Mandrel-23.0.2.1-Final (build 17.0.9+9)\\n" +
"OpenJDK 64-Bit Server VM Mandrel-23.0.2.1-Final (build 17.0.9+9, mixed mode)\\n | threshold-3.conf | 3.6.0 | 100 | 200 | 300 ",
"OpenJDK 64-Bit Server VM Mandrel-23.0.2.1-Final (build 17.0.9+9, mixed mode) | threshold-3.conf | 3.6.0 | 100 | 200 | 300 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 20.0.2 2023-07-18\\n" +
"OpenJDK Runtime Environment Mandrel-23.0.1.2-Final (build 20.0.2+9)\\n" +
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.2+9, mixed mode)\\n | threshold-4.conf | 3.6.0 | 100 | 200 | 300 ",
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.2+9, mixed mode) | threshold-4.conf | 3.6.0 | 100 | 200 | 300 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 20.0.2 2023-07-18\\n" +
"OpenJDK Runtime Environment Mandrel-23.0.1.2-Final (build 20.0.2+9)\\n" +
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.2+9, mixed mode)\\n | threshold-4.conf | 3.8.0 | 300 | 400 | 100 ",
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.2+9, mixed mode) | threshold-4.conf | 3.8.0 | 300 | 400 | 100 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 20.0.8 2023-07-18\\n" +
"OpenJDK Runtime Environment Mandrel-23.0.1.2-Final (build 20.0.8+9)\\n" +
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.8+9, mixed mode)\\n | threshold-4.conf | 3.0.0 | 191 | 192 | 193 ",
"OpenJDK 64-Bit Server VM Mandrel-23.0.1.2-Final (build 20.0.8+9, mixed mode) | threshold-4.conf | 3.0.0 | 191 | 192 | 193 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 23 2026-09-01\\n" +
"GraalVM Runtime Environment GraalVM CE 23+35.1 (build 23+35-jvmci-24.1-b99)\\n" +
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc)\\n | threshold-5.conf | 3.5.5 | 110 | 210 | 310 ",
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc) | threshold-5.conf | 3.5.5 | 110 | 210 | 310 ",
// -----------------------------------------------------------------------------------------------------------------------------------------
"native-image 23 2026-09-01\\n" +
"GraalVM Runtime Environment GraalVM CE 23+35.1 (build 23+35-jvmci-24.1-b99)\\n" +
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc)\\n | threshold-5.conf | 3.6.0 | 100 | 200 | 300 ",
"Substrate VM GraalVM CE 23+35.1 (build 23+35, serial gc) | threshold-5.conf | 3.6.0 | 100 | 200 | 300 ",
}, delimiter = '|')
//@formatter:on
public void testThreshold1(String nativeImageVersion, String conf, String quarkusVersion, String a, String b, String c) throws IOException {
public void testThreshold(String nativeImageVersion, String conf, String quarkusVersion, String a, String b, String c) throws IOException {
final Path config = Path.of(BASE_DIR, "testsuite", "src", "test", "resources", conf);
assertTrue(Files.exists(config), "Config file '" + config + "' MUST exist.");
final Path tmpDir = Files.createTempDirectory(ThresholdsTest.class.getSimpleName());
final Path nativeImage = tmpDir.resolve(Path.of(IS_THIS_WINDOWS ? "native-image.cmd" : "native-image"));
final String quarkusVersionTmp = getProperty("QUARKUS_VERSION", QuarkusVersion.DEFAULT_VERSION);
System.setProperty("FAKE_NATIVE_IMAGE_DIR", tmpDir.toAbsolutePath() + File.separator);
System.setProperty("QUARKUS_VERSION", quarkusVersion);
// Why this \\\\n? @CsvSource does not like \n in its values.
final String nativeImageText = nativeImageVersion.replaceAll("\\\\n", System.lineSeparator());
setProperty("FAKE_NATIVE_IMAGE_DIR", tmpDir.toAbsolutePath() + File.separator);
setProperty("QUARKUS_VERSION", quarkusVersion);
final String nativeImageText = createFakeNativeImageFile(nativeImage, nativeImageVersion);
try {
Files.writeString(nativeImage, IS_THIS_WINDOWS
? "@echo off" + System.lineSeparator() + "echo " + nativeImageText
: "#!/bin/sh" + System.lineSeparator() + "echo '" + nativeImageText + "'",
StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
if (!IS_THIS_WINDOWS) {
Files.setPosixFilePermissions(nativeImage, PosixFilePermissions.fromString("rwxr-xr-x"));
}
// Reset parsed instances to avoid side effects on other tests
// Note that container instance isn't being used, so isn't reset.
UsedVersion.Locally.resetInstance();
Expand All @@ -208,11 +203,34 @@ public void testThreshold1(String nativeImageVersion, String conf, String quarku
"Conf: %s\n", propNames[i], expected[i], thresholds.get(k), nativeImageText, quarkusVersion, config));
}
} finally {
System.clearProperty("FAKE_NATIVE_IMAGE_DIR");
System.setProperty("QUARKUS_VERSION", quarkusVersionTmp);
clearProperty("FAKE_NATIVE_IMAGE_DIR");
setProperty("QUARKUS_VERSION", quarkusVersionTmp);
Files.deleteIfExists(nativeImage);
Files.deleteIfExists(tmpDir);
}
}

/**
* @param file path to the fake native-image file
* @param contents <p>if multiline, all newlines must be escaped as \\n (double backslash), the reason is that JUnit's @CsvSource doesn't like \n in its parameters.</p>
* @return the contents of the fake native-image file
*/
public static String createFakeNativeImageFile(final Path file, final String contents) throws IOException {
// Why this \\\\n? @CsvSource does not like \n in its values.
final String nativeImageText;
if (IS_THIS_WINDOWS) {
nativeImageText = "@echo off" + lineSeparator() +
"setlocal EnableDelayedExpansion" + lineSeparator() +
"set LINE=^&echo." + lineSeparator() +
"echo " + contents.replaceAll("\\\\n", "%LINE%");
} else {
nativeImageText = "#!/bin/sh" + lineSeparator() +
"echo '" + contents.replaceAll("\\\\n", lineSeparator()) + "'";
}
Files.writeString(file, nativeImageText, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
if (!IS_THIS_WINDOWS) {
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("rwxr-xr-x"));
}
return nativeImageText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ public static int jdkUpdate(boolean inContainer) {
// Implements version parsing after https://github.com/oracle/graal/pull/6302
static final class VersionParseHelper {

//@formatter:off
private static final Map<Integer, String> GRAAL_MAPPING = Map.of(22, "24.0",
23, "24.1",
24, "25.0",
25, "25.1");

//@formatter:on
private static final String JVMCI_BUILD_PREFIX = "jvmci-";
private static final String MANDREL_VERS_PREFIX = "Mandrel-";

Expand Down Expand Up @@ -206,7 +207,7 @@ private static String matchVersion(String version) {
private static String graalVersion(String buildInfo, int jdkFeatureVers) {
if (jdkFeatureVers >= 22) {
// short-circuit new version scheme with a mapping
return GRAAL_MAPPING.get(Integer.valueOf(jdkFeatureVers));
return GRAAL_MAPPING.get(jdkFeatureVers);
}
if (buildInfo == null) {
return null;
Expand Down Expand Up @@ -263,6 +264,9 @@ public static MVersion of(boolean inContainer) {
mandrelVersion = VersionParseHelper.parse(lines);
} else {
mandrelVersion = UNKNOWN_VERSION;
LOGGER.warn("Failed to correctly parse native-image version command output. " +
"Is it on PATH? Unknown version format? " +
"Output reads in " + lines.size() + " lines, see them in an array: " + lines);
}
LOGGER.infof("The test suite runs with Mandrel version %s %s, JDK %d.%d.%d%s.",
mandrelVersion.version == null ? "UNKNOWN" : mandrelVersion.version.toString(),
Expand Down Expand Up @@ -410,12 +414,12 @@ public static void resetInstance() { // used in tests
public static int[] featureInterimUpdate(Pattern pattern, String version, int defaultValue) {
final Matcher m;
if (version == null || !(m = pattern.matcher(version)).matches()) {
return new int[]{defaultValue, defaultValue, defaultValue};
return new int[] { defaultValue, defaultValue, defaultValue };
}
final String jFeature = m.group("jfeature");
final String jInterim = m.group("jinterim");
final String jUpdate = m.group("jupdate");
return new int[]{
return new int[] {
jFeature == null ? defaultValue : Integer.parseInt(jFeature),
jInterim == null ? defaultValue : Integer.parseInt(jInterim),
jUpdate == null ? defaultValue : Integer.parseInt(jUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFilePermissions;

import static org.graalvm.tests.integration.utils.Commands.IS_THIS_WINDOWS;
import static org.graalvm.tests.integration.utils.Commands.getProperty;
import static org.graalvm.tests.integration.utils.thresholds.ThresholdsTest.createFakeNativeImageFile;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand Down Expand Up @@ -77,13 +77,7 @@ public class VersionsTest {
public static void setup() throws IOException {
System.setProperty("FAKE_NATIVE_IMAGE_DIR", TEMP_DIR.toAbsolutePath() + File.separator);
System.setProperty("QUARKUS_VERSION", QUARKUS_VERSION);
Files.writeString(NATIVE_IMAGE, IS_THIS_WINDOWS
? "@echo off" + System.lineSeparator() + "echo " + VERSION + System.lineSeparator()
: "#!/bin/sh" + System.lineSeparator() + "echo '" + VERSION + "'" + System.lineSeparator(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);
if (!IS_THIS_WINDOWS) {
Files.setPosixFilePermissions(NATIVE_IMAGE, PosixFilePermissions.fromString("rwxr-xr-x"));
}
createFakeNativeImageFile(NATIVE_IMAGE, VERSION);
Files.deleteIfExists(LOG);
// Reset parsed instances to avoid side effects on other tests
// Note that container instance isn't being used, so isn't reset.
Expand Down

0 comments on commit bfd35de

Please sign in to comment.