From 9419c4cf30cc98308c5d9d14896b9a8ccb732a85 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 2 Dec 2024 22:24:21 -0800 Subject: [PATCH] Add JNI test support (#37) * Add JNI test support * Fix cross * Fixes --- build.gradle | 35 ++++++++++++++++++- .../java/com/vendor/jni/VendorJNITest.java | 11 ++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/vendor/jni/VendorJNITest.java diff --git a/build.gradle b/build.gradle index 7b83b9f..5e3fa38 100644 --- a/build.gradle +++ b/build.gradle @@ -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") } } diff --git a/src/test/java/com/vendor/jni/VendorJNITest.java b/src/test/java/com/vendor/jni/VendorJNITest.java new file mode 100644 index 0000000..2b444cc --- /dev/null +++ b/src/test/java/com/vendor/jni/VendorJNITest.java @@ -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(); + } +} \ No newline at end of file