Skip to content

Commit

Permalink
Define expected tests output based on GraalVM version
Browse files Browse the repository at this point in the history
  • Loading branch information
dnestoro committed Dec 23, 2024
1 parent e05d314 commit f699e18
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,31 @@

package org.graalvm.buildtools.maven

import org.graalvm.buildtools.utils.NativeImageUtils
import spock.lang.Issue
import spock.lang.Unroll

class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctionalTest {

def getCurrentJDKVersion() {
return NativeImageUtils.getMajorJDKVersion(GraalVMSupport.getGraalVMHomeVersionString())
}

def metadataInSingleConfigFile() {
return getCurrentJDKVersion() >= 23
}

def metadataExistsAt(String path) {
if (metadataInSingleConfigFile()) {
return file("${path}/reachability-metadata.json").exists()
}

boolean allFilesExist = ['jni', 'proxy', 'reflect', 'resource', 'serialization'].every { name ->
file("${path}/${name}-config.json").exists()
}

return allFilesExist
}

@Issue("https://github.com/graalvm/native-build-tools/issues/179")
def "agent is used for JVM tests when native image tests are skipped via -DskipNativeTests"() {
given:
Expand All @@ -60,11 +80,10 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
// Agent is used with Surefire
outputContains '-agentlib:native-image-agent='


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

and:
// Surefire / JVM tests run
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.graalvm.buildtools.maven

class GraalVMSupport {

static String getJavaHomeVersionString() {
String javaHomeLocation = System.getenv("JAVA_HOME")
return extractVersionString(javaHomeLocation)
}

static String getGraalVMHomeVersionString() {
String graalvmHomeLocation = System.getenv("GRAALVM_HOME")
return extractVersionString(graalvmHomeLocation)
}

private static String extractVersionString(String location) {
def sout = new StringBuilder(), serr = new StringBuilder()
String command = getSystemBasedCommand(location);
def proc = command.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
assert serr.toString().isEmpty()

return sout.toString()
}

private static String getSystemBasedCommand(String location) {
if (System.getProperty("os.name", "unknown").contains("Windows")) {
return location + '\\bin\\native-image.cmd --version'
} else {
return location + '/bin/native-image --version'
}
}
}

0 comments on commit f699e18

Please sign in to comment.