Skip to content

Commit f699e18

Browse files
committed
Define expected tests output based on GraalVM version
1 parent e05d314 commit f699e18

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithAgentFunctionalTest.groovy

+23-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,31 @@
4141

4242
package org.graalvm.buildtools.maven
4343

44+
import org.graalvm.buildtools.utils.NativeImageUtils
4445
import spock.lang.Issue
45-
import spock.lang.Unroll
4646

4747
class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
4848

49+
def getCurrentJDKVersion() {
50+
return NativeImageUtils.getMajorJDKVersion(GraalVMSupport.getGraalVMHomeVersionString())
51+
}
52+
53+
def metadataInSingleConfigFile() {
54+
return getCurrentJDKVersion() >= 23
55+
}
56+
57+
def metadataExistsAt(String path) {
58+
if (metadataInSingleConfigFile()) {
59+
return file("${path}/reachability-metadata.json").exists()
60+
}
61+
62+
boolean allFilesExist = ['jni', 'proxy', 'reflect', 'resource', 'serialization'].every { name ->
63+
file("${path}/${name}-config.json").exists()
64+
}
65+
66+
return allFilesExist
67+
}
68+
4969
@Issue("https://github.com/graalvm/native-build-tools/issues/179")
5070
def "agent is used for JVM tests when native image tests are skipped via -DskipNativeTests"() {
5171
given:
@@ -60,11 +80,10 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
6080
// Agent is used with Surefire
6181
outputContains '-agentlib:native-image-agent='
6282

83+
6384
and:
6485
// Agent generates files
65-
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
66-
assert file("target/native/agent-output/test/${name}-config.json").exists()
67-
}
86+
metadataExistsAt("target/native/agent-output/test/")
6887

6988
and:
7089
// Surefire / JVM tests run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.graalvm.buildtools.maven
2+
3+
class GraalVMSupport {
4+
5+
static String getJavaHomeVersionString() {
6+
String javaHomeLocation = System.getenv("JAVA_HOME")
7+
return extractVersionString(javaHomeLocation)
8+
}
9+
10+
static String getGraalVMHomeVersionString() {
11+
String graalvmHomeLocation = System.getenv("GRAALVM_HOME")
12+
return extractVersionString(graalvmHomeLocation)
13+
}
14+
15+
private static String extractVersionString(String location) {
16+
def sout = new StringBuilder(), serr = new StringBuilder()
17+
String command = getSystemBasedCommand(location);
18+
def proc = command.execute()
19+
proc.consumeProcessOutput(sout, serr)
20+
proc.waitForOrKill(1000)
21+
assert serr.toString().isEmpty()
22+
23+
return sout.toString()
24+
}
25+
26+
private static String getSystemBasedCommand(String location) {
27+
if (System.getProperty("os.name", "unknown").contains("Windows")) {
28+
return location + '\\bin\\native-image.cmd --version'
29+
} else {
30+
return location + '/bin/native-image --version'
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)