Skip to content

Commit

Permalink
Refactor BuildAndRunCmds to semantically separate build from run comm…
Browse files Browse the repository at this point in the history
…ands
  • Loading branch information
zakkak committed Oct 10, 2024
1 parent eb523a2 commit d9eb99b
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ public void randomNumbersReinit(TestInfo testInfo) throws IOException, Interrupt
builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...#1");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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);
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", cmd));

LOGGER.info("Running...#2");
cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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 Expand Up @@ -468,7 +468,7 @@ public void resLocations(TestInfo testInfo, Apps app, String expectedOutput) thr
builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...");
final List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
final List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
final String output = runCommand(cmd, appDir).trim();
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", cmd));
Expand Down Expand Up @@ -531,8 +531,7 @@ public void imageioAWT(TestInfo testInfo, Apps app) throws IOException, Interrup
// Build
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();

builderRoutine(0, app.buildAndRunCmds.cmds.length - 1,
app, report, cn, mn, appDir, processLog, null, getSwitches(app));
builderRoutine(app, report, cn, mn, appDir, processLog, null, getSwitches(app));

// Record images' hashsums as created by a Java process
final List<String> errors = new ArrayList<>(12);
Expand Down Expand Up @@ -573,15 +572,15 @@ public void imageioAWT(TestInfo testInfo, Apps app) throws IOException, Interrup
// Details: https://github.com/Karm/mandrel-integration-tests/issues/151#issuecomment-1516802244
Files.createDirectories(Path.of(appDir.toString(), "lib")).toFile().deleteOnExit();

final List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
final List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
process = runCommand(cmd, appDir, processLog, app);
assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName());
process.waitFor(15, TimeUnit.SECONDS);
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", cmd));

// Test output
final boolean inContainer = app == Apps.IMAGEIO_BUILDER_IMAGE;
final boolean inContainer = app.runtimeContainer != ContainerNames.NONE;
controlData.forEach((fileName, hash) -> {
final File picture = new File(appDir, fileName);
if (picture.exists() && picture.isFile()) {
Expand Down Expand Up @@ -720,10 +719,10 @@ public void timezonesBakedIn(TestInfo testInfo) throws IOException, InterruptedE
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);
builderRoutine(app, report, cn, mn, appDir, processLog, null, switches);

LOGGER.info("Running...");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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);
Expand Down Expand Up @@ -783,24 +782,26 @@ public void timezonesBakedIn(TestInfo testInfo) throws IOException, InterruptedE
@Tag("builder-image")
@IfMandrelVersion(minJDK = "21.0.3", inContainer = true)
public void monitorFieldOffsetContainerTest(TestInfo testInfo) throws IOException, InterruptedException {
monitorFieldOffset(testInfo, Apps.MONITOR_OFFSET_BUILDER_IMAGE);
monitorFieldOffsetOK(testInfo, Apps.MONITOR_OFFSET_OK_BUILDER_IMAGE);
monitorFieldOffsetNOK(testInfo, Apps.MONITOR_OFFSET_NOK_BUILDER_IMAGE);
}

@Test
@IfMandrelVersion(minJDK = "21.0.3")
public void monitorFieldOffsetTest(TestInfo testInfo) throws IOException, InterruptedException {
monitorFieldOffset(testInfo, Apps.MONITOR_OFFSET);
monitorFieldOffsetOK(testInfo, Apps.MONITOR_OFFSET_OK);
monitorFieldOffsetNOK(testInfo, Apps.MONITOR_OFFSET_NOK);
}

public void monitorFieldOffset(TestInfo testInfo, Apps app) throws IOException, InterruptedException {
public void monitorFieldOffsetOK(TestInfo testInfo, Apps app) throws IOException, InterruptedException {
LOGGER.info("Testing app: " + app);
Process process = null;
File processLog = null;
final StringBuilder report = new StringBuilder();
final File appDir = Path.of(BASE_DIR, app.dir).toFile();
final String cn = testInfo.getTestClass().get().getCanonicalName();
final String mn = testInfo.getTestMethod().get().getName();
final boolean inContainer = app == Apps.MONITOR_OFFSET_BUILDER_IMAGE;
final boolean inContainer = app.runtimeContainer != ContainerNames.NONE;
try {
// Cleanup
cleanTarget(app);
Expand All @@ -811,9 +812,9 @@ public void monitorFieldOffset(TestInfo testInfo, Apps app) throws IOException,

// OK version
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();
builderRoutine(inContainer ? 3 : 2, app, report, cn, mn, appDir, processLog);
builderRoutine(app, report, cn, mn, appDir, processLog);
LOGGER.info("Running...");
final List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 3]);
final List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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 All @@ -824,13 +825,31 @@ public void monitorFieldOffset(TestInfo testInfo, Apps app) throws IOException,
final Pattern pok = Pattern.compile(".*Done all 9000 iterations.*");
assertTrue(searchLogLines(pok, processLog, Charset.defaultCharset()), "Expected pattern " + pok + " was not found in the log." +
"Perhaps ContendedPaddingWidth default has changed from 128 bytes to something else?");
} finally {
cleanup(process, cn, mn, report, app, processLog);
}
}

public void monitorFieldOffsetNOK(TestInfo testInfo, Apps app) throws IOException, InterruptedException {
LOGGER.info("Testing app: " + app);
Process process = null;
File processLog = null;
final StringBuilder report = new StringBuilder();
final File appDir = Path.of(BASE_DIR, app.dir).toFile();
final String cn = testInfo.getTestClass().get().getCanonicalName();
final String mn = testInfo.getTestMethod().get().getName();
final boolean inContainer = app.runtimeContainer != ContainerNames.NONE;
try {
// Cleanup
cleanTarget(app);
if (inContainer) {
removeContainers(app.runtimeContainer.name);
}
Files.createDirectories(Paths.get(appDir.getAbsolutePath() + File.separator + "logs"));

// NOK version
builderRoutine(inContainer ? 4 : 3, app.buildAndRunCmds.cmds.length, app, report, cn, mn, appDir, processLog);
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();
builderRoutine(app, report, cn, mn, appDir, processLog);
Logs.checkLog(cn, mn, app, processLog);
final Pattern pnok = Pattern.compile(".*Class monitor_field_offset.Main480 has an invalid monitor field offset.*");
assertTrue(searchLogLines(pnok, processLog, Charset.defaultCharset()), "Expected pattern " + pnok + " was not found in the log.");
Expand Down Expand Up @@ -873,7 +892,7 @@ public void forSerialization(TestInfo testInfo, Apps app) throws IOException, In
final File metaINF = Path.of(BASE_DIR, app.dir, "src", "main", "resources", "META-INF", "native-image").toFile();
final String cn = testInfo.getTestClass().get().getCanonicalName();
final String mn = testInfo.getTestMethod().get().getName();
final boolean inContainer = app == Apps.FOR_SERIALIZATION_BUILDER_IMAGE;
final boolean inContainer = app.runtimeContainer != ContainerNames.NONE;
try {
// Cleanup
cleanTarget(app);
Expand All @@ -885,11 +904,11 @@ public void forSerialization(TestInfo testInfo, Apps app) throws IOException, In
}
Files.createDirectories(Paths.get(appDir.getAbsolutePath() + File.separator + "logs"));
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();
builderRoutine(inContainer ? 4 : 3, app, report, cn, mn, appDir, processLog);
builderRoutine(app, report, cn, mn, appDir, processLog);
LOGGER.info("Running...");

final List<String> cmdHotSpot = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 2]);
final List<String> cmdNative = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
final List<String> cmdHotSpot = getRunCommand(app.buildAndRunCmds.runCommands[0]);
final List<String> cmdNative = getRunCommand(app.buildAndRunCmds.runCommands[1]);
final String hotSpotOutput = runCommand(cmdHotSpot, appDir);
final String nativeOutput = runCommand(cmdNative, appDir);
Logs.appendln(report, appDir.getAbsolutePath());
Expand Down Expand Up @@ -937,7 +956,7 @@ public void calendarsBakedIn(TestInfo testInfo) throws IOException, InterruptedE
builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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 Expand Up @@ -982,7 +1001,7 @@ public void recordAnnotationsWork(TestInfo testInfo) throws IOException, Interru
builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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 Expand Up @@ -1023,10 +1042,10 @@ public void versionsParsingMandrel(TestInfo testInfo) throws IOException, Interr
// Build
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();

builderRoutine(2, app, report, cn, mn, appDir, processLog);
builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
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 Expand Up @@ -1068,15 +1087,13 @@ public void nativeJVMTextProcessing(TestInfo testInfo) throws IOException, Inter
// Build
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();

// In this case, the two last commands are used for running the app; one in JVM mode and the other in Native mode.
// We should somehow capture this semantically in an Enum or something. This is fragile...
builderRoutine(app.buildAndRunCmds.cmds.length - 2, app, report, cn, mn, appDir, processLog, null, getSwitches(app));
builderRoutine(app, report, cn, mn, appDir, processLog, null, getSwitches(app));

final File inputData = new File(BASE_DIR + File.separator + app.dir + File.separator + "target" + File.separator + "test_data.txt");

LOGGER.info("Running JVM mode...");
long start = System.currentTimeMillis();
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 2]);
List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
process = runCommand(cmd, appDir, processLog, app, inputData);
assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName());
process.waitFor(30, TimeUnit.SECONDS);
Expand All @@ -1086,7 +1103,7 @@ public void nativeJVMTextProcessing(TestInfo testInfo) throws IOException, Inter

LOGGER.info("Running Native mode...");
start = System.currentTimeMillis();
cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
cmd = getRunCommand(app.buildAndRunCmds.runCommands[1]);
process = runCommand(cmd, appDir, processLog, app, inputData);
assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName());
process.waitFor(30, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void debugSymbolsSmokeGDB(TestInfo testInfo) throws IOException, Interrup

// In this case, the two last commands are used for running the app; one in JVM mode and the other in Native mode.
// We should somehow capture this semantically in an Enum or something. This is fragile...
builderRoutine(app.buildAndRunCmds.cmds.length - 2, app, report, cn, mn, appDir, processLog, null, getSwitches());
builderRoutine(app, report, cn, mn, appDir, processLog, null, getSwitches());

assertTrue(Files.exists(Path.of(appDir.getAbsolutePath(), "target", "debug-symbols-smoke")),
"debug-symbols-smoke executable does not exist. Compilation failed. Check the logs.");
Expand Down Expand Up @@ -231,7 +231,7 @@ public void debugSymbolsQuarkus(TestInfo testInfo) throws IOException, Interrupt
} else {
switches = null;
}
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, null, switches);
builderRoutine(app, report, cn, mn, appDir, processLog, null, switches);

assertTrue(Files.exists(Path.of(appDir.getAbsolutePath(), "target", "quarkus-runner")),
"Quarkus executable does not exist. Compilation failed. Check the logs.");
Expand Down Expand Up @@ -341,12 +341,12 @@ public void debugSymbolsQuarkusContainer(TestInfo testInfo) throws IOException,

// Build app and start db
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog);
builderRoutine(app, report, cn, mn, appDir, processLog);
waitForContainerLogToMatch("quarkus_test_db", dbReady, 20, 1, TimeUnit.SECONDS);

// Start app
LOGGER.info("Running...");
final List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
final List<String> cmd = getRunCommand(app.buildAndRunCmds.runCommands[0]);
runCommand(cmd, appDir, processLog, app);
Files.writeString(processLog.toPath(), String.join(" ", cmd) + "\n", StandardOpenOption.APPEND,
StandardOpenOption.CREATE);
Expand Down
Loading

0 comments on commit d9eb99b

Please sign in to comment.