forked from Karm/mandrel-integration-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depending on the graal vm version in use, use the appropriate native-image option to allow for VM inspection. Closes: Karm#107
- Loading branch information
Showing
5 changed files
with
172 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,25 @@ | |
* @author Michal Karm Babacek <[email protected]> | ||
*/ | ||
public class Commands { | ||
|
||
public enum JFROption { | ||
MONITOR_22("--enable-monitoring"), | ||
MONITOR_21("-H:+AllowVMInspection"), | ||
NONE(""); | ||
|
||
private String replacement; | ||
|
||
JFROption(String rep) { | ||
this.replacement = rep; | ||
} | ||
|
||
String replacement() { | ||
return this.replacement; | ||
} | ||
} | ||
|
||
private static final Logger LOGGER = Logger.getLogger(Commands.class.getName()); | ||
public static final String JFR_MONITORING_SWITCH_TOKEN = "<ALLOW_VM_INSPECTION>"; | ||
public static final String CONTAINER_RUNTIME = getProperty( | ||
new String[]{"QUARKUS_NATIVE_CONTAINER_RUNTIME", "quarkus.native.container-runtime"}, | ||
"docker"); | ||
|
@@ -109,6 +127,23 @@ public static String getProperty(String[] alternatives, String defaultValue) { | |
return prop; | ||
} | ||
|
||
public static boolean isVersion22_3OrBetter(String version) { | ||
if (version == null) { | ||
return false; | ||
} | ||
try { | ||
String[] tokens = version.split("\\."); | ||
if (tokens.length < 2) { | ||
return false; | ||
} | ||
int major = Integer.parseInt(tokens[0]); | ||
int minor = Integer.parseInt(tokens[1]); | ||
return major >= 22 && minor > 2; | ||
} catch (NumberFormatException e) { | ||
return false; // assume default of 21 | ||
} | ||
} | ||
|
||
public static String getUnixUIDGID() { | ||
final UnixSystem s = new UnixSystem(); | ||
return s.getUid() + ":" + s.getGid(); | ||
|
@@ -694,13 +729,22 @@ public static boolean waitForBufferToMatch(StringBuffer stringBuffer, Pattern pa | |
} | ||
|
||
public static void builderRoutine(int steps, Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog, Map<String, String> env) throws InterruptedException { | ||
builderRoutine(steps, app, report, cn, mn, appDir, processLog, env, JFROption.NONE); | ||
} | ||
|
||
public static void builderRoutine(int steps, Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog, Map<String, String> env, JFROption jfrOpt) throws InterruptedException { | ||
// The last command is reserved for running it | ||
assertTrue(app.buildAndRunCmds.cmds.length > 1); | ||
Logs.appendln(report, "# " + cn + ", " + mn); | ||
for (int i = 0; i < steps; i++) { | ||
// We cannot run commands in parallel, we need them to follow one after another | ||
final ExecutorService buildService = Executors.newFixedThreadPool(1); | ||
final List<String> cmd = Commands.getRunCommand(app.buildAndRunCmds.cmds[i]); | ||
// Replace actual option for JFR enabled builds so that the appropriate command option | ||
// gets passed and doesn't produce a deprecation warning | ||
if (jfrOpt != JFROption.NONE) { | ||
replaceMonitoringSwitch(cmd, jfrOpt.replacement); | ||
} | ||
buildService.submit(new Commands.ProcessRunner(appDir, processLog, cmd, 10, env)); // might take a long time.... | ||
Logs.appendln(report, (new Date()).toString()); | ||
Logs.appendln(report, appDir.getAbsolutePath()); | ||
|
@@ -710,6 +754,15 @@ public static void builderRoutine(int steps, Apps app, StringBuilder report, Str | |
assertTrue(processLog.exists()); | ||
} | ||
|
||
private static void replaceMonitoringSwitch(List<String> cmd, String replacement) { | ||
for (int i = 0; i < cmd.size(); i++) { | ||
if (cmd.get(i).trim().equals(JFR_MONITORING_SWITCH_TOKEN)) { | ||
cmd.set(i, replacement); | ||
} | ||
} | ||
} | ||
|
||
|
||
// Copied from | ||
// https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ExecutorService.html | ||
private static void shutdownAndAwaitTermination(ExecutorService pool, long timeout, TimeUnit unit) { | ||
|
@@ -731,15 +784,19 @@ private static void shutdownAndAwaitTermination(ExecutorService pool, long timeo | |
} | ||
|
||
public static void builderRoutine(Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog) throws InterruptedException { | ||
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, null); | ||
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, null, JFROption.NONE); | ||
} | ||
|
||
public static void builderRoutine(Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog, Map<String, String> env) throws InterruptedException { | ||
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, env); | ||
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog, env, JFROption.NONE); | ||
} | ||
|
||
public static void builderRoutine(int steps, Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog) throws InterruptedException { | ||
builderRoutine(steps, app, report, cn, mn, appDir, processLog, null); | ||
builderRoutine(steps, app, report, cn, mn, appDir, processLog, null, JFROption.NONE); | ||
} | ||
|
||
public static void builderRoutine(int steps, Apps app, StringBuilder report, String cn, String mn, File appDir, File processLog, JFROption jfrOpt) throws InterruptedException { | ||
builderRoutine(steps, app, report, cn, mn, appDir, processLog, null, jfrOpt); | ||
} | ||
|
||
public static void replaceInSmallTextFile(Pattern search, String replace, Path file, Charset charset) throws IOException { | ||
|
41 changes: 41 additions & 0 deletions
41
...uite/src/it/java/org/graalvm/tests/integration/utils/versions/GraalVersionPropSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2022, Red Hat Inc. All rights reserved. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package org.graalvm.tests.integration.utils.versions; | ||
|
||
import org.graalvm.home.Version; | ||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
public class GraalVersionPropSetter implements AfterEachCallback, BeforeEachCallback { | ||
|
||
@Override | ||
public void afterEach(ExtensionContext extensionContext) throws Exception { | ||
final GraalVersionProperty annotation = extensionContext.getTestMethod().get().getAnnotation(GraalVersionProperty.class); | ||
System.clearProperty(GraalVersionProperty.NAME); | ||
} | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext extensionContext) throws Exception { | ||
final GraalVersionProperty annotation = extensionContext.getTestMethod().get().getAnnotation(GraalVersionProperty.class); | ||
final Version usedVersion = UsedVersion.getVersion(annotation.inContainer()); | ||
System.setProperty(GraalVersionProperty.NAME, usedVersion.toString()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
testsuite/src/it/java/org/graalvm/tests/integration/utils/versions/GraalVersionProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2021, Red Hat Inc. All rights reserved. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package org.graalvm.tests.integration.utils.versions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Sets the property specified by {@code name} (default 'graal.vm.version') | ||
* to the currently in-use Graal version for the annotated test run | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(GraalVersionPropSetter.class) | ||
@Test | ||
public @interface GraalVersionProperty { | ||
|
||
public final static String NAME = "graal.vm.version"; | ||
|
||
boolean inContainer() default false; | ||
} |