Skip to content

Commit

Permalink
Add JNI test support (#37)
Browse files Browse the repository at this point in the history
* Add JNI test support

* Fix cross

* Fixes
  • Loading branch information
ThadHouse authored Dec 3, 2024
1 parent 93767cf commit 9419c4c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
35 changes: 34 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import edu.wpi.first.toolchain.*

plugins {
id 'cpp'
id 'java'
Expand Down Expand Up @@ -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
Expand All @@ -68,6 +87,12 @@ nativeUtils {
}
}

ext.getCurrentArch = {
return NativePlatforms.desktop
}

def systemArch = getCurrentArch()

model {
components {
Vendor(NativeLibrarySpec) {
Expand Down Expand Up @@ -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")
Expand All @@ -133,7 +167,6 @@ model {
include '**/*.cpp'
}
}

nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared", "googletest_static")
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/vendor/jni/VendorJNITest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 9419c4c

Please sign in to comment.