Add JNI test support (#37)

* Add JNI test support

* Fix cross

* Fixes
This commit is contained in:
Thad House 2024-12-02 22:24:21 -08:00 committed by GitHub
parent 93767cf757
commit 9419c4cf30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import edu.wpi.first.toolchain.*
plugins {
id 'cpp'
id 'java'
@ -44,6 +46,23 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:2.15.2"
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"
implementation 'edu.wpi.first.thirdparty.frc2024.opencv:opencv-java:4.8.0-4'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
// Set up java tests
test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
testLogging {
events "failed"
exceptionFormat "full"
}
}
if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64') || project.hasProperty('onlywindowsarm64') || project.hasProperty('onlylinuxsystemcore')) {
test.enabled = false
}
// Setup Javadocs to link back to WPILib docs
@ -68,6 +87,12 @@ nativeUtils {
}
}
ext.getCurrentArch = {
return NativePlatforms.desktop
}
def systemArch = getCurrentArch()
model {
components {
Vendor(NativeLibrarySpec) {
@ -121,6 +146,15 @@ model {
binaries.all {
lib library: 'VendorDriver', linkage: 'shared'
def arch = it.targetPlatform.name
if (systemArch == arch && it.buildType.name == 'debug') {
def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
test.dependsOn it.tasks.install
test.systemProperty 'java.library.path', filePath
test.environment 'LD_LIBRARY_PATH', filePath
test.workingDir filePath
}
}
nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared", "googletest_static")
@ -133,7 +167,6 @@ model {
include '**/*.cpp'
}
}
nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared", "googletest_static")
}
}

View File

@ -0,0 +1,11 @@
package com.vendor.jni;
import org.junit.jupiter.api.Test;
public class VendorJNITest {
@Test
void jniLinkTest() {
// Test to verify that the JNI test link works correctly.
VendorJNI.initialize();
}
}