Skip to content

Commit

Permalink
Fix AppReproducersTest#timezonesBakedIn
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jerboaa committed Sep 26, 2024
1 parent ad85ce7 commit 6a05d48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<TZ_INCLUDE_TOKEN_1>";
public static final String LOCALEINCLUDES_TOKEN_2 = "<TZ_INCLUDE_TOKEN_2>";

@Test
@Tag("randomNumbers")
Expand Down Expand Up @@ -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<String, String> 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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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[][]{
Expand Down

0 comments on commit 6a05d48

Please sign in to comment.