From 6a05d4872c5d268adbdbc9b33fac5482ef40f822 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 26 Sep 2024 12:36:55 +0200 Subject: [PATCH] Fix AppReproducersTest#timezonesBakedIn With GraalVM prior to 24.2.0 the default locale (and included locale) for a native image was determined by the -Duser.language and -Duser.country settings as image build time. With GraalVM >= 24.2.0 the build settings of language/country have no effect in terms of included locales in the resulting native image. Therefore, -H:IncludeLocales, needs to be used at build time instead. Also at image runtime the default language is determined by the system locale. For the purpose of the test we'd want the French language which we need to set at image runtime when the test runs. Closes: #285 --- .../tests/integration/AppReproducersTest.java | 24 ++++++++++++++++++- .../integration/utils/BuildAndRunCmds.java | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java b/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java index 7d5952c..96ad8cf 100644 --- a/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java +++ b/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java @@ -85,8 +85,15 @@ public class AppReproducersTest { private static final Logger LOGGER = Logger.getLogger(AppReproducersTest.class.getName()); + private static final String LOCALEINCLUDES_SWITCH_REPLACEMENT_1_MANDREL_PRE_24_2_0 = "-J-Duser.country=CA"; + private static final String LOCALEINCLUDES_SWITCH_REPLACEMENT_2_MANDREL_PRE_24_2_0 = "-J-Duser.language=fr"; + private static final String LOCALEINCLUDES_SWITCH_REPLACEMENT_1_MANDREL_POST_24_2_0 = "-H:IncludeLocales=fr-CA"; + private static final String LOCALEINCLUDES_SWITCH_REPLACEMENT_2_MANDREL_POST_24_2_0 = ""; + private static final String EXTRA_TZONES_OPTS = "-Duser.language=fr"; public static final String BASE_DIR = getBaseDir(); + public static final String LOCALEINCLUDES_TOKEN_1 = ""; + public static final String LOCALEINCLUDES_TOKEN_2 = ""; @Test @Tag("randomNumbers") @@ -702,10 +709,25 @@ public void timezonesBakedIn(TestInfo testInfo) throws IOException, InterruptedE // Build processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile(); - builderRoutine(app, report, cn, mn, appDir, processLog); + Map switches = null; + final boolean inContainer = app.runtimeContainer != ContainerNames.NONE; + if (UsedVersion.getVersion(inContainer).compareTo(Version.create(24, 2, 0)) >= 0) { + // Locale inclusion for Mandrel 24.2 ignores -Duser.language and -Duser.country settings + // at build time. + switches = Map.of(LOCALEINCLUDES_TOKEN_1, LOCALEINCLUDES_SWITCH_REPLACEMENT_1_MANDREL_POST_24_2_0, + LOCALEINCLUDES_TOKEN_2, LOCALEINCLUDES_SWITCH_REPLACEMENT_2_MANDREL_POST_24_2_0); + } else { + switches = Map.of(LOCALEINCLUDES_TOKEN_1, LOCALEINCLUDES_SWITCH_REPLACEMENT_1_MANDREL_PRE_24_2_0, + LOCALEINCLUDES_TOKEN_2, LOCALEINCLUDES_SWITCH_REPLACEMENT_2_MANDREL_PRE_24_2_0); + } + builderRoutine(0, app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, null, switches); LOGGER.info("Running..."); List cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]); + if (UsedVersion.getVersion(inContainer).compareTo(Version.create(24, 2, 0)) >= 0) { + // Mandrel 24.2 needs the desired language set at runtime + cmd.add(EXTRA_TZONES_OPTS); + } process = runCommand(cmd, appDir, processLog, app); assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName()); process.waitFor(5, TimeUnit.SECONDS); diff --git a/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java b/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java index d8623fe..314cfac 100755 --- a/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java +++ b/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java @@ -22,6 +22,8 @@ import java.io.File; import static org.graalvm.tests.integration.AppReproducersTest.BASE_DIR; +import static org.graalvm.tests.integration.AppReproducersTest.LOCALEINCLUDES_TOKEN_1; +import static org.graalvm.tests.integration.AppReproducersTest.LOCALEINCLUDES_TOKEN_2; import static org.graalvm.tests.integration.JFRTest.JFR_FLIGHT_RECORDER_HOTSPOT_TOKEN; import static org.graalvm.tests.integration.JFRTest.JFR_MONITORING_SWITCH_TOKEN; import static org.graalvm.tests.integration.PerfCheckTest.FINAL_NAME_TOKEN; @@ -191,7 +193,7 @@ public enum BuildAndRunCmds { }), TIMEZONES(new String[][]{ new String[]{"mvn", "package"}, - new String[]{"native-image", "-J-Duser.country=CA", "-J-Duser.language=fr", "-jar", "target/timezones.jar", "target/timezones"}, + new String[]{"native-image", LOCALEINCLUDES_TOKEN_1, LOCALEINCLUDES_TOKEN_2, "-jar", "target/timezones.jar", "target/timezones"}, new String[]{IS_THIS_WINDOWS ? "target\\timezones.exe" : "./target/timezones"} }), CALENDARS(new String[][]{