Skip to content

Commit

Permalink
Move jssc.boot.library.path to pom per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Nov 9, 2023
1 parent cd632f9 commit 9944b62
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 36 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.surfire.version}</version>
<configuration>
<!-- Ensure junit tests can access recently compiled binaries -->
<systemPropertyVariables>
<jssc.boot.library.path>${project.build.directory}/cmake/natives/</jssc.boot.library.path>
</systemPropertyVariables>

<!-- Separate JVMs between classes; Needed for "jssc.boot.library.path" test to be effective -->
<reuseForks>false</reuseForks>
<excludes>
<!--suppress UnresolvedMavenProperty -->
Expand Down
7 changes: 0 additions & 7 deletions src/test/java/jssc/SerialNativeInterfaceTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jssc;

import jssc.bootpath.Helper;
import org.junit.Assume;
import org.junit.Test;

Expand All @@ -11,12 +10,6 @@
import static org.junit.Assert.fail;

public class SerialNativeInterfaceTest {
// Ensure library is loaded from /target/cmake/natives
static {
Helper.fixNativesPath();
}


@Test
public void testInitNativeInterface() {
SerialNativeInterface serial = new SerialNativeInterface();
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/jssc/VirtualPortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import jssc.bootpath.Helper;
import jssc.junit.rules.VirtualPortRule;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;

public class VirtualPortTest {
static {
Helper.fixNativesPath();
}

private static final String HELLO_WORLD = "Hello, world!";

private final byte[] bytes;
Expand Down
20 changes: 0 additions & 20 deletions src/test/java/jssc/bootpath/Helper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@
* Tests if a valid <code>jssc.boot.library.path</code> which does NOT contain a native library
* will predictably fail. This test can be run regardless of whether or not a native binary was
* created during the build process.
*
* <code>jssc.boot.library.path</code> is configured in surefire's <code>systemPropertyVariables</code> section,
* so we must override it below.
*
* IMPORTANT: Invocations MUST be in their own class to run in a separate JVM (https://stackoverflow.com/questions/68657855)
* - JUnit does NOT currently offer JVM unloading between methods.
* - maven-surefire-plugin DOES offer JVM unloading between classes using <code>reuseForks=false</code>
* - Unloading is needed due to NativeLoader.loadLibrary(...) calls System.loadLibrary(...) which is static
*/
public class ManualBootLibraryPathFailedTest {
@Test
public void testBootPathOverride() {
// Ensure library is not found
Helper.breakNativesPath();
System.setProperty("jssc.boot.library.path", "/" /* unlikely location */);
try {
SerialNativeInterface.getNativeLibraryVersion();
fail("Library loading should fail if path provided exists but does not contain a native library");
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/jssc/bootpath/ManualBootLibraryPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@

/**
* Tests if a valid <code>jssc.boot.library.path</code> which DOES contain a native library
* will predictably pass. This test can ONLY be run regardless if a native binary was created
* will predictably pass. This test can ONLY be run if a native binary was created
* during the build process. See also <code>maven.exclude.tests</code>.
*
* <code>jssc.boot.library.path</code> is configured in surefire's <code>systemPropertyVariables</code> section.
*
* IMPORTANT: Invocations MUST be in their own class to run in a separate JVM (https://stackoverflow.com/questions/68657855)
* - JUnit does NOT currently offer JVM unloading between methods.
* - maven-surefire-plugin DOES offer JVM unloading between classes using <code>reuseForks=false</code>
* - Unloading is needed due to NativeLoader.loadLibrary(...) calls System.loadLibrary(...) which is static
*/
public class ManualBootLibraryPathTest {
@Test
public void testBootPathOverride() {
// Ensure library is loaded from /target/cmake/natives
Helper.fixNativesPath();
try {
final String nativeLibraryVersion = SerialNativeInterface.getNativeLibraryVersion();
assertThat(nativeLibraryVersion, is(not(nullValue())));
Expand Down

0 comments on commit 9944b62

Please sign in to comment.