Skip to content

Commit

Permalink
Add native image tests (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
luneo7 authored Oct 15, 2024
1 parent d95323b commit f131c70
Show file tree
Hide file tree
Showing 31 changed files with 945 additions and 760 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:

- name: Tests
run: mvn "-Dh3.system.prune=true" "-Dh3.dockcross.only=${{ matrix.dockcross-only }}" -B -V clean test site
env:
OCI_EXE: docker

- name: Format check for C
run: git diff --exit-code
Expand Down Expand Up @@ -91,6 +93,8 @@ jobs:
- name: Tests
run: mvn "-Dh3.system.prune=true" "-Dh3.dockcross.tag=${{ matrix.dockcross-tag }}" "-Dh3.dockcross.only=${{ matrix.dockcross-only }}" -B -V clean test
env:
OCI_EXE: docker

tests-no-docker:
name: Java (No Docker) ${{ matrix.java-version }} ${{ matrix.os }}
Expand Down Expand Up @@ -217,3 +221,53 @@ jobs:
mvn clean test -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=true
env:
GH_TOKEN: ${{ github.token }}

tests-native:
name: Native image ${{ matrix.java-version }} ${{ matrix.os }}
needs:
- tests
- tests-no-docker
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
java-distribution: [ graalvm ]
java-version: [ 21 ]

steps:
- uses: actions/checkout@v2.1.1
with:
submodules: recursive

- uses: actions/setup-java@v4
with:
distribution: "${{ matrix.java-distribution }}"
java-version: "${{ matrix.java-version }}"

- uses: actions/cache@v2
id: maven-cache
with:
path: ~/.m2/
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Download Docker binaries
uses: actions/download-artifact@v4.1.7
with:
pattern: docker-built-shared-objects-*
merge-multiple: true
path: src/main/resources/

- name: Download Mac binaries
uses: actions/download-artifact@v4.1.7
with:
name: macos-built-shared-objects
path: src/main/resources/

- name: Download and test
run: |
mvn clean verify -Dnative -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=true
env:
GH_TOKEN: ${{ github.token }}
79 changes: 71 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.openjdk.jmh.version>1.19</org.openjdk.jmh.version>
<maven.javadoc.plugin.version>3.1.1</maven.javadoc.plugin.version>
<maven-surefire.version>3.5.1</maven-surefire.version>
<native-maven-plugin.version>0.10.3</native-maven-plugin.version>

<h3.git.remote>https://github.com/uber/h3.git</h3.git.remote>
<h3.use.docker>true</h3.use.docker>
Expand Down Expand Up @@ -163,15 +165,41 @@
</plugins>
</build>
</profile>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
</configuration>
<executions>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand All @@ -187,7 +215,19 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.1-jre</version>
<version>33.3.1-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.11.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -212,10 +252,33 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<systemPropertyVariables>
<junit.platform.listeners.uid.tracking.enabled>true</junit.platform.listeners.uid.tracking.enabled>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"resources": {
"includes": [
{"pattern": "**libh3-java**"}
{"pattern": ".*libh3-java.*"}
]
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/uber/h3core/BaseTestH3Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
package com.uber.h3core;

import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;

/** Base class for tests of the class {@link H3Core} */
public abstract class BaseTestH3Core {
public static final double EPSILON = 1e-6;

protected static H3Core h3;

@BeforeClass
@BeforeAll
public static void setup() throws IOException {
h3 = H3Core.newInstance();
}
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/uber/h3core/TestBindingCompleteness.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.uber.h3core;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.ImmutableSet;
import java.io.File;
Expand All @@ -24,18 +24,20 @@
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledInNativeImage;

/** Tests all expected functions are exposed. */
public class TestBindingCompleteness {
class TestBindingCompleteness {
/** Functions to ignore from the bindings. */
private static final Set<String> WHITELIST =
ImmutableSet.of(
// These are provided by the Java library (java.lang.Math)
"degsToRads", "radsToDegs");

@Test
public void test() throws IOException {
@DisabledInNativeImage
void test() throws IOException {
Set<String> exposed = new HashSet<>();
for (Method m : H3Core.class.getMethods()) {
exposed.add(m.getName());
Expand All @@ -50,10 +52,10 @@ public void test() throws IOException {
continue;
}

assertTrue(function + " is exposed in binding", exposed.contains(function));
assertTrue(exposed.contains(function), function + " is exposed in binding");
checkedFunctions++;
}
}
assertTrue("Checked that the API exists", checkedFunctions > 10);
assertTrue(checkedFunctions > 10, "Checked that the API exists");
}
}
26 changes: 14 additions & 12 deletions src/test/java/com/uber/h3core/TestDirectedEdges.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
*/
package com.uber.h3core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.uber.h3core.exceptions.H3Exception;
import com.uber.h3core.util.LatLng;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/** Tests for unidirectional edge functions. */
public class TestDirectedEdges extends BaseTestH3Core {
class TestDirectedEdges extends BaseTestH3Core {
@Test
public void testUnidirectionalEdges() {
void unidirectionalEdges() {
String start = "891ea6d6533ffff";
String adjacent = "891ea6d65afffff";
String notAdjacent = "891ea6992dbffff";
Expand Down Expand Up @@ -59,13 +60,14 @@ public void testUnidirectionalEdges() {
assertEquals(2, boundary.size());
}

@Test(expected = H3Exception.class)
public void testUnidirectionalEdgesNotNeighbors() {
h3.cellsToDirectedEdge("891ea6d6533ffff", "891ea6992dbffff");
@Test
void unidirectionalEdgesNotNeighbors() {
assertThrows(
H3Exception.class, () -> h3.cellsToDirectedEdge("891ea6d6533ffff", "891ea6992dbffff"));
}

@Test(expected = H3Exception.class)
public void testDirectedEdgeInvalid() {
h3.getDirectedEdgeOrigin(0);
@Test
void directedEdgeInvalid() {
assertThrows(H3Exception.class, () -> h3.getDirectedEdgeOrigin(0));
}
}
20 changes: 10 additions & 10 deletions src/test/java/com/uber/h3core/TestH3CoreCrossCompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
*/
package com.uber.h3core;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* Test that particular resource names exist in the built artifact when cross compiling. Although we
* cannot test that those resources run correctly (since they can't be loaded), we can at least test
* that the cross compiler put resources in the right locations. This test is only run if the system
* property <code>h3.use.docker</code> has the value <code>true</code>.
*/
public class TestH3CoreCrossCompile {
@BeforeClass
public static void assumptions() {
class TestH3CoreCrossCompile {
@BeforeAll
static void assumptions() {
assumeTrue(
"Docker cross compilation enabled", "true".equals(System.getProperty("h3.use.docker")));
"true".equals(System.getProperty("h3.use.docker")), "Docker cross compilation enabled");
}

@Test
public void testResourcesExist() throws IOException {
void resourcesExist() throws IOException {
List<String> resources =
ImmutableList.of(
"/linux-x64/libh3-java.so",
Expand All @@ -56,7 +56,7 @@ public void testResourcesExist() throws IOException {
"/android-arm/libh3-java.so",
"/android-arm64/libh3-java.so");
for (String name : resources) {
assertNotNull(name + " is an included resource", H3CoreLoader.class.getResource(name));
assertNotNull(H3CoreLoader.class.getResource(name), name + " is an included resource");
}
}
}
Loading

0 comments on commit f131c70

Please sign in to comment.