Skip to content

Commit

Permalink
Merge branch 'master' into cc/issue-665
Browse files Browse the repository at this point in the history
  • Loading branch information
melix authored Jan 10, 2025
2 parents 3383344 + caae59f commit 098b55a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void addDefaultAccessFilter() {
}

long pid = ProcessHandle.current().pid();
long time = System.currentTimeMillis();
long time = System.nanoTime();
Path tmpAccessFilter = agentDir.resolve(ACCESS_FILTER_PREFIX + '_' + pid + '_' + time + '_' + ACCESS_FILTER_SUFFIX);
Files.copy(accessFilterData, tmpAccessFilter);

Expand Down
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 098b55a

Please sign in to comment.