-
Notifications
You must be signed in to change notification settings - Fork 60
test: add native integration tests setup #754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chmjkb
wants to merge
28
commits into
main
Choose a base branch
from
@chmjkb/basemodel-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,870
−62
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
252748f
wip
chmjkb 3bc9aff
feat: basic on-device gtest run
chmjkb f05bcac
feat: extend cmake to use 3rd party android libs
chmjkb 0a6a8ae
feat(wip): add a run_tests script to run tests on emulator
chmjkb 147894b
feat: add some tests along with 3p stubs
chmjkb a596818
feat: add more tests
chmjkb bbe3291
feat: add llm tests
chmjkb c885a99
chore: remove logs, add jsi stubs
chmjkb 34cdb66
chore: void cast to avoid [[nodiscard]] warnings
chmjkb 64e2d17
feat: add tti tests
chmjkb 43513ac
chore: avoid redownloading when model file exists
chmjkb bee34e1
chore: add .pte files to gitignore
chmjkb 3ae1a3d
chore: separate integration and unit tests, add some more tests
chmjkb 88059a7
chore: use typed tests for basemodel tests
chmjkb 1d416c3
feat: improve tests
chmjkb e397e23
feat: add some more tests
chmjkb c565649
chore: remove pointless tests
chmjkb da04969
feat: add vertical ocr tests
chmjkb 6ea237d
chore: rename variable
chmjkb 53c7106
fix: expect throw rnexecutorch error instead of std
chmjkb 4540c13
chore: update readme and the run tests script
chmjkb 916b3b3
chore: add missing assets
chmjkb 8863fa2
fix: use proper image name in vertical ocr test
chmjkb 17189b6
chore: review suggestions
chmjkb 8fc251d
Apply suggestion from @chmjkb
chmjkb 22baead
chore: review changes
chmjkb c740a1f
chore: dynamically find required static libs
chmjkb 5a844d1
chore: update cspell wordlist
chmjkb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,3 +94,6 @@ Português | |
| codegen | ||
| cstdint | ||
| ocurred | ||
| libfbjni | ||
| libc | ||
| gradlew | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,3 +93,4 @@ apps/*/android/ | |
| # custom | ||
| *.tgz | ||
| Makefile | ||
| *.pte | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
269 changes: 246 additions & 23 deletions
269
packages/react-native-executorch/common/rnexecutorch/tests/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,257 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
| if(NOT ANDROID_ABI) | ||
| message(FATAL_ERROR "Tests can be only built for Android simulator") | ||
| endif() | ||
|
|
||
| cmake_minimum_required(VERSION 3.13) | ||
| project(RNExecutorchTests) | ||
|
|
||
| # C++ standard | ||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED TRUE) | ||
|
|
||
| # googletest subdirectory | ||
| # Using an absolute path from the top-level source directory | ||
| add_subdirectory(${CMAKE_SOURCE_DIR}/../../../../../third-party/googletest ${PROJECT_BINARY_DIR}/googletest) | ||
| # tests/ <- CMAKE_SOURCE_DIR (this file's location) | ||
| # rnexecutorch/ <- RNEXECUTORCH_DIR (parent of tests) | ||
| # common/ <- COMMON_DIR | ||
| # react-native-executorch/ <- PACKAGE_ROOT | ||
| # <monorepo-root>/ <- MONOREPO_ROOT | ||
| # <monorepo-root>/third-party/ <- THIRD_PARTY_DIR | ||
| set(RNEXECUTORCH_DIR "${CMAKE_SOURCE_DIR}/..") | ||
| set(COMMON_DIR "${RNEXECUTORCH_DIR}/..") | ||
| set(PACKAGE_ROOT "${COMMON_DIR}/..") | ||
| set(MONOREPO_ROOT "${PACKAGE_ROOT}/../..") | ||
| set(THIRD_PARTY_DIR "${MONOREPO_ROOT}/third-party") | ||
| set(REACT_NATIVE_DIR "${MONOREPO_ROOT}/node_modules/react-native") | ||
| set(ANDROID_THIRD_PARTY "${PACKAGE_ROOT}/third-party/android/libs/") | ||
|
|
||
| # Add Gtest as a subdirectory | ||
| add_subdirectory(${THIRD_PARTY_DIR}/googletest ${PROJECT_BINARY_DIR}/googletest) | ||
|
|
||
| # ExecuTorch Prebuilt binaries | ||
| add_library(executorch_prebuilt SHARED IMPORTED) | ||
| set_target_properties(executorch_prebuilt PROPERTIES | ||
| IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/executorch/${ANDROID_ABI}/libexecutorch.so" | ||
| ) | ||
|
|
||
| # pthreadpool and cpuinfo (needed for OpenMP/OpenCV) | ||
| if(ANDROID_ABI STREQUAL "arm64-v8a") | ||
| add_library(pthreadpool SHARED IMPORTED) | ||
| set_target_properties(pthreadpool PROPERTIES | ||
| IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so" | ||
| ) | ||
|
|
||
| add_library(cpuinfo SHARED IMPORTED) | ||
| set_target_properties(cpuinfo PROPERTIES | ||
| IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so" | ||
| ) | ||
|
|
||
| set(EXECUTORCH_LIBS pthreadpool cpuinfo) | ||
| else() | ||
| set(EXECUTORCH_LIBS "") | ||
| endif() | ||
|
|
||
| # OpenCV (Interface Library) | ||
| set(OPENCV_LIBS_DIR "${ANDROID_THIRD_PARTY}/opencv/${ANDROID_ABI}") | ||
| set(OPENCV_THIRD_PARTY_DIR "${ANDROID_THIRD_PARTY}/opencv-third-party/${ANDROID_ABI}") | ||
|
|
||
| # Directories to include | ||
| include_directories(${CMAKE_SOURCE_DIR}/../data_processing) | ||
| include_directories(${CMAKE_SOURCE_DIR}/..) | ||
| if(ANDROID_ABI STREQUAL "arm64-v8a") | ||
| set(OPENCV_THIRD_PARTY_LIBS | ||
| "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_hal.a" | ||
| "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_thread.a" | ||
| "${OPENCV_THIRD_PARTY_DIR}/libkleidicv.a" | ||
| ) | ||
| elseif(ANDROID_ABI STREQUAL "x86_64") | ||
| set(OPENCV_THIRD_PARTY_LIBS "") | ||
| endif() | ||
|
|
||
| # Source files | ||
| set(SOURCE_FILES ${CMAKE_SOURCE_DIR}/../data_processing/Numerical.cpp | ||
| ${CMAKE_SOURCE_DIR}/../data_processing/FileUtils.h) | ||
|
|
||
| # Executables for the tests | ||
| add_executable(NumericalTests NumericalTest.cpp ${SOURCE_FILES}) | ||
| add_executable(FileUtilsTests FileUtilsTest.cpp ${SOURCE_FILES}) | ||
| add_executable(LogTests LogTest.cpp) | ||
| add_library(opencv_deps INTERFACE) | ||
| target_link_libraries(opencv_deps INTERFACE | ||
| ${OPENCV_LIBS_DIR}/libopencv_core.a | ||
| ${OPENCV_LIBS_DIR}/libopencv_features2d.a | ||
| ${OPENCV_LIBS_DIR}/libopencv_highgui.a | ||
| ${OPENCV_LIBS_DIR}/libopencv_imgproc.a | ||
| ${OPENCV_LIBS_DIR}/libopencv_photo.a | ||
| ${OPENCV_LIBS_DIR}/libopencv_video.a | ||
| ${OPENCV_THIRD_PARTY_LIBS} | ||
| ${EXECUTORCH_LIBS} | ||
| z | ||
| dl | ||
| m | ||
| log | ||
| ) | ||
| target_link_options(opencv_deps INTERFACE -fopenmp -static-openmp) | ||
|
|
||
| # Libraries linking | ||
| target_link_libraries(NumericalTests gtest gtest_main) | ||
| target_link_libraries(FileUtilsTests gtest gtest_main) | ||
| target_link_libraries(LogTests gtest gtest_main) | ||
| # Tokenizers (Interface Library) | ||
| set(TOKENIZERS_LIBS_DIR "${ANDROID_THIRD_PARTY}/tokenizers-cpp/${ANDROID_ABI}") | ||
| add_library(tokenizers_deps INTERFACE) | ||
| target_link_libraries(tokenizers_deps INTERFACE | ||
| ${TOKENIZERS_LIBS_DIR}/libtokenizers_cpp.a | ||
| ${TOKENIZERS_LIBS_DIR}/libtokenizers_c.a | ||
| ${TOKENIZERS_LIBS_DIR}/libsentencepiece.a | ||
| ) | ||
|
|
||
| # Source Definitions | ||
| set(CORE_SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/BaseModel.cpp | ||
| ${RNEXECUTORCH_DIR}/data_processing/Numerical.cpp | ||
| ${CMAKE_SOURCE_DIR}/integration/stubs/jsi_stubs.cpp | ||
| ) | ||
|
|
||
| set(IMAGE_UTILS_SOURCES | ||
| ${RNEXECUTORCH_DIR}/data_processing/ImageProcessing.cpp | ||
| ${RNEXECUTORCH_DIR}/data_processing/base64.cpp | ||
| ${COMMON_DIR}/ada/ada.cpp | ||
| ) | ||
|
|
||
| set(TOKENIZER_SOURCES ${RNEXECUTORCH_DIR}/TokenizerModule.cpp) | ||
| set(DSP_SOURCES ${RNEXECUTORCH_DIR}/data_processing/dsp.cpp) | ||
|
|
||
| # Core Library | ||
| add_library(rntests_core STATIC ${CORE_SOURCES}) | ||
|
|
||
| target_include_directories(rntests_core PUBLIC | ||
| ${RNEXECUTORCH_DIR}/data_processing | ||
| ${RNEXECUTORCH_DIR} | ||
| ${COMMON_DIR} | ||
| ${PACKAGE_ROOT}/third-party/include | ||
| ${REACT_NATIVE_DIR}/ReactCommon | ||
| ${REACT_NATIVE_DIR}/ReactCommon/jsi | ||
| ${REACT_NATIVE_DIR}/ReactCommon/callinvoker | ||
| ${COMMON_DIR}/ada | ||
| ) | ||
|
|
||
| target_link_libraries(rntests_core PUBLIC | ||
| executorch_prebuilt | ||
| gtest | ||
| log | ||
| ) | ||
|
|
||
| # Testing functionalities | ||
| enable_testing() | ||
| add_test(NAME NumericalTests COMMAND NumericalTests) | ||
| add_test(NAME FileUtilsTests COMMAND FileUtilsTests) | ||
| add_test(NAME LogTests COMMAND LogTests) | ||
| function(add_rn_test TEST_TARGET TEST_FILENAME) | ||
| cmake_parse_arguments(ARG "" "" "SOURCES;LIBS" ${ARGN}) | ||
| # Create executable using the explicit filename provided | ||
| add_executable(${TEST_TARGET} ${TEST_FILENAME} ${ARG_SOURCES}) | ||
|
|
||
| target_compile_definitions(${TEST_TARGET} PRIVATE TEST_BUILD) | ||
| target_link_libraries(${TEST_TARGET} PRIVATE rntests_core gtest_main ${ARG_LIBS}) | ||
| target_link_options(${TEST_TARGET} PRIVATE "LINKER:-z,max-page-size=16384") | ||
|
|
||
| add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET}) | ||
| endfunction() | ||
|
|
||
| add_rn_test(NumericalTests unit/NumericalTest.cpp) | ||
| add_rn_test(LogTests unit/LogTest.cpp) | ||
| add_rn_test(BaseModelTests integration/BaseModelTest.cpp) | ||
|
|
||
| add_rn_test(ClassificationTests integration/ClassificationTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/classification/Classification.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) | ||
|
|
||
| add_rn_test(ObjectDetectionTests integration/ObjectDetectionTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/object_detection/ObjectDetection.cpp | ||
| ${RNEXECUTORCH_DIR}/models/object_detection/Utils.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) | ||
|
|
||
| add_rn_test(ImageEmbeddingsTests integration/ImageEmbeddingsTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/image/ImageEmbeddings.cpp | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) | ||
|
|
||
| add_rn_test(TextEmbeddingsTests integration/TextEmbeddingsTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp | ||
| ${TOKENIZER_SOURCES} | ||
| LIBS tokenizers_deps | ||
| ) | ||
|
|
||
| add_rn_test(StyleTransferTests integration/StyleTransferTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/style_transfer/StyleTransfer.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) | ||
|
|
||
| add_rn_test(VADTests integration/VoiceActivityDetectionTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/voice_activity_detection/VoiceActivityDetection.cpp | ||
| ${RNEXECUTORCH_DIR}/models/voice_activity_detection/Utils.cpp | ||
| ${DSP_SOURCES} | ||
| ) | ||
|
|
||
| add_rn_test(TokenizerModuleTests integration/TokenizerModuleTest.cpp | ||
| SOURCES ${TOKENIZER_SOURCES} | ||
| LIBS tokenizers_deps | ||
| ) | ||
|
|
||
| add_rn_test(SpeechToTextTests integration/SpeechToTextTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/speech_to_text/SpeechToText.cpp | ||
| ${RNEXECUTORCH_DIR}/models/speech_to_text/asr/ASR.cpp | ||
| ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/HypothesisBuffer.cpp | ||
| ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/OnlineASRProcessor.cpp | ||
| ${RNEXECUTORCH_DIR}/data_processing/gzip.cpp | ||
| ${TOKENIZER_SOURCES} | ||
| ${DSP_SOURCES} | ||
| LIBS tokenizers_deps z | ||
| ) | ||
|
|
||
| add_rn_test(LLMTests integration/LLMTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/llm/LLM.cpp | ||
| ${COMMON_DIR}/runner/runner.cpp | ||
| ${COMMON_DIR}/runner/text_prefiller.cpp | ||
| ${COMMON_DIR}/runner/text_decoder_runner.cpp | ||
| ${COMMON_DIR}/runner/sampler.cpp | ||
| ${COMMON_DIR}/runner/arange_util.cpp | ||
| LIBS tokenizers_deps | ||
| ) | ||
|
|
||
| add_rn_test(TextToImageTests integration/TextToImageTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/text_to_image/TextToImage.cpp | ||
| ${RNEXECUTORCH_DIR}/models/text_to_image/Encoder.cpp | ||
| ${RNEXECUTORCH_DIR}/models/text_to_image/UNet.cpp | ||
| ${RNEXECUTORCH_DIR}/models/text_to_image/Decoder.cpp | ||
| ${RNEXECUTORCH_DIR}/models/text_to_image/Scheduler.cpp | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp | ||
| ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp | ||
| ${TOKENIZER_SOURCES} | ||
| LIBS tokenizers_deps | ||
| ) | ||
|
|
||
| add_rn_test(OCRTests integration/OCRTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/ocr/OCR.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/RecognitionHandler.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) | ||
|
|
||
| add_rn_test(VerticalOCRTests integration/VerticalOCRTest.cpp | ||
| SOURCES | ||
| ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalOCR.cpp | ||
| ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalDetector.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp | ||
| ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp | ||
| ${IMAGE_UTILS_SOURCES} | ||
| LIBS opencv_deps | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.