From a0f1022303556b77d15f5ee004895b5918fa6188 Mon Sep 17 00:00:00 2001 From: Navneet Verma Date: Sun, 17 Mar 2024 14:37:18 -0700 Subject: [PATCH] Enable running jni test during gradle build Signed-off-by: Navneet Verma --- CHANGELOG.md | 1 + DEVELOPER_GUIDE.md | 15 +++++++++++++++ build.gradle | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a669bfb2f..25b196691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Infrastructure * Manually install zlib for win CI [#1513](https://github.com/opensearch-project/k-NN/pull/1513) * Update k-NN build artifact script to enable SIMD on ARM for Faiss [#1543](https://github.com/opensearch-project/k-NN/pull/1543) +* Enable running jni test during gradle build [#1553](https://github.com/opensearch-project/k-NN/pull/1553) ### Documentation ### Maintenance * Bump faiss lib commit to 32f0e8cf92cd2275b60364517bb1cce67aa29a55 [#1443](https://github.com/opensearch-project/k-NN/pull/1443) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index ca5e7cc52..8cfb83e66 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -219,6 +219,21 @@ run: ./bin/jni_test --gtest_filter=Faiss* ``` +To run JNI Tests via gradle: +``` +# To run all tests +./gradlew jniTest + +# To run nmslib tests +./gradlew jniTest -Dgtest_filter=Nmslib* + +# To run faiss tests +./gradlew jniTest -Dgtest_filter=Faiss* +``` + +The task `jniTest` is a dependency if `check` task which ensures that JNI tests are running as part of `./gradlew build` command. + + ### JNI Library Artifacts We build and distribute binary library artifacts with OpenSearch. We build the library binaries in diff --git a/build.gradle b/build.gradle index 1c6ae5efd..0b92765ce 100644 --- a/build.gradle +++ b/build.gradle @@ -310,6 +310,23 @@ task cmakeJniLib(type:Exec) { } } +tasks.register('jniTest', Exec) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + dependsOn cmakeJniLib + var args = '' + if (System.getProperty("gtest_filter") != null) { + args = '--gtest_filter=' + System.getProperty("gtest_filter") + } + workingDir 'jni' + commandLine 'make' , 'jni_test' + commandLine './bin/jni_test' , "${args}" + } +} + +// Ensure that jniTest task is running during the ./gradlew build +check.dependsOn jniTest + + task buildJniLib(type:Exec) { dependsOn cmakeJniLib workingDir 'jni'