|
1 | | -cmake_minimum_required(VERSION 3.10) |
| 1 | +if(NOT ANDROID_ABI) |
| 2 | + message(FATAL_ERROR "Tests can be only built for Android simulator") |
| 3 | +endif() |
| 4 | + |
| 5 | +cmake_minimum_required(VERSION 3.13) |
2 | 6 | project(RNExecutorchTests) |
3 | 7 |
|
4 | | -# C++ standard |
5 | 8 | set(CMAKE_CXX_STANDARD 20) |
6 | 9 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
7 | 10 |
|
8 | | -# googletest subdirectory |
9 | | -# Using an absolute path from the top-level source directory |
10 | | -add_subdirectory(${CMAKE_SOURCE_DIR}/../../../../../third-party/googletest ${PROJECT_BINARY_DIR}/googletest) |
| 11 | +# tests/ <- CMAKE_SOURCE_DIR (this file's location) |
| 12 | +# rnexecutorch/ <- RNEXECUTORCH_DIR (parent of tests) |
| 13 | +# common/ <- COMMON_DIR |
| 14 | +# react-native-executorch/ <- PACKAGE_ROOT |
| 15 | +# <monorepo-root>/ <- MONOREPO_ROOT |
| 16 | +# <monorepo-root>/third-party/ <- THIRD_PARTY_DIR |
| 17 | +set(RNEXECUTORCH_DIR "${CMAKE_SOURCE_DIR}/..") |
| 18 | +set(COMMON_DIR "${RNEXECUTORCH_DIR}/..") |
| 19 | +set(PACKAGE_ROOT "${COMMON_DIR}/..") |
| 20 | +set(MONOREPO_ROOT "${PACKAGE_ROOT}/../..") |
| 21 | +set(THIRD_PARTY_DIR "${MONOREPO_ROOT}/third-party") |
| 22 | +set(REACT_NATIVE_DIR "${MONOREPO_ROOT}/node_modules/react-native") |
| 23 | +set(ANDROID_THIRD_PARTY "${PACKAGE_ROOT}/third-party/android/libs/") |
| 24 | + |
| 25 | +# Add Gtest as a subdirectory |
| 26 | +add_subdirectory(${THIRD_PARTY_DIR}/googletest ${PROJECT_BINARY_DIR}/googletest) |
| 27 | + |
| 28 | +# ExecuTorch Prebuilt binaries |
| 29 | +add_library(executorch_prebuilt SHARED IMPORTED) |
| 30 | +set_target_properties(executorch_prebuilt PROPERTIES |
| 31 | + IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/executorch/${ANDROID_ABI}/libexecutorch.so" |
| 32 | +) |
| 33 | + |
| 34 | +# pthreadpool and cpuinfo (needed for OpenMP/OpenCV) |
| 35 | +if(ANDROID_ABI STREQUAL "arm64-v8a") |
| 36 | + add_library(pthreadpool SHARED IMPORTED) |
| 37 | + set_target_properties(pthreadpool PROPERTIES |
| 38 | + IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so" |
| 39 | + ) |
| 40 | + |
| 41 | + add_library(cpuinfo SHARED IMPORTED) |
| 42 | + set_target_properties(cpuinfo PROPERTIES |
| 43 | + IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so" |
| 44 | + ) |
| 45 | + |
| 46 | + set(EXECUTORCH_LIBS pthreadpool cpuinfo) |
| 47 | +else() |
| 48 | + set(EXECUTORCH_LIBS "") |
| 49 | +endif() |
| 50 | + |
| 51 | +# OpenCV (Interface Library) |
| 52 | +set(OPENCV_LIBS_DIR "${ANDROID_THIRD_PARTY}/opencv/${ANDROID_ABI}") |
| 53 | +set(OPENCV_THIRD_PARTY_DIR "${ANDROID_THIRD_PARTY}/opencv-third-party/${ANDROID_ABI}") |
11 | 54 |
|
12 | | -# Directories to include |
13 | | -include_directories(${CMAKE_SOURCE_DIR}/../data_processing) |
14 | | -include_directories(${CMAKE_SOURCE_DIR}/..) |
| 55 | +if(ANDROID_ABI STREQUAL "arm64-v8a") |
| 56 | + set(OPENCV_THIRD_PARTY_LIBS |
| 57 | + "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_hal.a" |
| 58 | + "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_thread.a" |
| 59 | + "${OPENCV_THIRD_PARTY_DIR}/libkleidicv.a" |
| 60 | + ) |
| 61 | +elseif(ANDROID_ABI STREQUAL "x86_64") |
| 62 | + set(OPENCV_THIRD_PARTY_LIBS "") |
| 63 | +endif() |
15 | 64 |
|
16 | | -# Source files |
17 | | -set(SOURCE_FILES ${CMAKE_SOURCE_DIR}/../data_processing/Numerical.cpp |
18 | | - ${CMAKE_SOURCE_DIR}/../data_processing/FileUtils.h) |
19 | 65 |
|
20 | | -# Executables for the tests |
21 | | -add_executable(NumericalTests NumericalTest.cpp ${SOURCE_FILES}) |
22 | | -add_executable(FileUtilsTests FileUtilsTest.cpp ${SOURCE_FILES}) |
23 | | -add_executable(LogTests LogTest.cpp) |
| 66 | +add_library(opencv_deps INTERFACE) |
| 67 | +target_link_libraries(opencv_deps INTERFACE |
| 68 | + ${OPENCV_LIBS_DIR}/libopencv_core.a |
| 69 | + ${OPENCV_LIBS_DIR}/libopencv_features2d.a |
| 70 | + ${OPENCV_LIBS_DIR}/libopencv_highgui.a |
| 71 | + ${OPENCV_LIBS_DIR}/libopencv_imgproc.a |
| 72 | + ${OPENCV_LIBS_DIR}/libopencv_photo.a |
| 73 | + ${OPENCV_LIBS_DIR}/libopencv_video.a |
| 74 | + ${OPENCV_THIRD_PARTY_LIBS} |
| 75 | + ${EXECUTORCH_LIBS} |
| 76 | + z |
| 77 | + dl |
| 78 | + m |
| 79 | + log |
| 80 | +) |
| 81 | +target_link_options(opencv_deps INTERFACE -fopenmp -static-openmp) |
24 | 82 |
|
25 | | -# Libraries linking |
26 | | -target_link_libraries(NumericalTests gtest gtest_main) |
27 | | -target_link_libraries(FileUtilsTests gtest gtest_main) |
28 | | -target_link_libraries(LogTests gtest gtest_main) |
| 83 | +# Tokenizers (Interface Library) |
| 84 | +set(TOKENIZERS_LIBS_DIR "${ANDROID_THIRD_PARTY}/tokenizers-cpp/${ANDROID_ABI}") |
| 85 | +add_library(tokenizers_deps INTERFACE) |
| 86 | +target_link_libraries(tokenizers_deps INTERFACE |
| 87 | + ${TOKENIZERS_LIBS_DIR}/libtokenizers_cpp.a |
| 88 | + ${TOKENIZERS_LIBS_DIR}/libtokenizers_c.a |
| 89 | + ${TOKENIZERS_LIBS_DIR}/libsentencepiece.a |
| 90 | +) |
| 91 | + |
| 92 | +# Source Definitions |
| 93 | +set(CORE_SOURCES |
| 94 | + ${RNEXECUTORCH_DIR}/models/BaseModel.cpp |
| 95 | + ${RNEXECUTORCH_DIR}/data_processing/Numerical.cpp |
| 96 | + ${CMAKE_SOURCE_DIR}/integration/stubs/jsi_stubs.cpp |
| 97 | +) |
| 98 | + |
| 99 | +set(IMAGE_UTILS_SOURCES |
| 100 | + ${RNEXECUTORCH_DIR}/data_processing/ImageProcessing.cpp |
| 101 | + ${RNEXECUTORCH_DIR}/data_processing/base64.cpp |
| 102 | + ${COMMON_DIR}/ada/ada.cpp |
| 103 | +) |
| 104 | + |
| 105 | +set(TOKENIZER_SOURCES ${RNEXECUTORCH_DIR}/TokenizerModule.cpp) |
| 106 | +set(DSP_SOURCES ${RNEXECUTORCH_DIR}/data_processing/dsp.cpp) |
| 107 | + |
| 108 | +# Core Library |
| 109 | +add_library(rntests_core STATIC ${CORE_SOURCES}) |
| 110 | + |
| 111 | +target_include_directories(rntests_core PUBLIC |
| 112 | + ${RNEXECUTORCH_DIR}/data_processing |
| 113 | + ${RNEXECUTORCH_DIR} |
| 114 | + ${COMMON_DIR} |
| 115 | + ${PACKAGE_ROOT}/third-party/include |
| 116 | + ${REACT_NATIVE_DIR}/ReactCommon |
| 117 | + ${REACT_NATIVE_DIR}/ReactCommon/jsi |
| 118 | + ${REACT_NATIVE_DIR}/ReactCommon/callinvoker |
| 119 | + ${COMMON_DIR}/ada |
| 120 | +) |
| 121 | + |
| 122 | +target_link_libraries(rntests_core PUBLIC |
| 123 | + executorch_prebuilt |
| 124 | + gtest |
| 125 | + log |
| 126 | +) |
29 | 127 |
|
30 | | -# Testing functionalities |
31 | 128 | enable_testing() |
32 | | -add_test(NAME NumericalTests COMMAND NumericalTests) |
33 | | -add_test(NAME FileUtilsTests COMMAND FileUtilsTests) |
34 | | -add_test(NAME LogTests COMMAND LogTests) |
| 129 | +function(add_rn_test TEST_TARGET TEST_FILENAME) |
| 130 | + cmake_parse_arguments(ARG "" "" "SOURCES;LIBS" ${ARGN}) |
| 131 | + # Create executable using the explicit filename provided |
| 132 | + add_executable(${TEST_TARGET} ${TEST_FILENAME} ${ARG_SOURCES}) |
| 133 | + |
| 134 | + target_compile_definitions(${TEST_TARGET} PRIVATE TEST_BUILD) |
| 135 | + target_link_libraries(${TEST_TARGET} PRIVATE rntests_core gtest_main ${ARG_LIBS}) |
| 136 | + target_link_options(${TEST_TARGET} PRIVATE "LINKER:-z,max-page-size=16384") |
| 137 | + |
| 138 | + add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET}) |
| 139 | +endfunction() |
| 140 | + |
| 141 | +add_rn_test(NumericalTests unit/NumericalTest.cpp) |
| 142 | +add_rn_test(LogTests unit/LogTest.cpp) |
| 143 | +add_rn_test(BaseModelTests integration/BaseModelTest.cpp) |
| 144 | + |
| 145 | +add_rn_test(ClassificationTests integration/ClassificationTest.cpp |
| 146 | + SOURCES |
| 147 | + ${RNEXECUTORCH_DIR}/models/classification/Classification.cpp |
| 148 | + ${IMAGE_UTILS_SOURCES} |
| 149 | + LIBS opencv_deps |
| 150 | +) |
| 151 | + |
| 152 | +add_rn_test(ObjectDetectionTests integration/ObjectDetectionTest.cpp |
| 153 | + SOURCES |
| 154 | + ${RNEXECUTORCH_DIR}/models/object_detection/ObjectDetection.cpp |
| 155 | + ${RNEXECUTORCH_DIR}/models/object_detection/Utils.cpp |
| 156 | + ${IMAGE_UTILS_SOURCES} |
| 157 | + LIBS opencv_deps |
| 158 | +) |
| 159 | + |
| 160 | +add_rn_test(ImageEmbeddingsTests integration/ImageEmbeddingsTest.cpp |
| 161 | + SOURCES |
| 162 | + ${RNEXECUTORCH_DIR}/models/embeddings/image/ImageEmbeddings.cpp |
| 163 | + ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp |
| 164 | + ${IMAGE_UTILS_SOURCES} |
| 165 | + LIBS opencv_deps |
| 166 | +) |
| 167 | + |
| 168 | +add_rn_test(TextEmbeddingsTests integration/TextEmbeddingsTest.cpp |
| 169 | + SOURCES |
| 170 | + ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp |
| 171 | + ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp |
| 172 | + ${TOKENIZER_SOURCES} |
| 173 | + LIBS tokenizers_deps |
| 174 | +) |
| 175 | + |
| 176 | +add_rn_test(StyleTransferTests integration/StyleTransferTest.cpp |
| 177 | + SOURCES |
| 178 | + ${RNEXECUTORCH_DIR}/models/style_transfer/StyleTransfer.cpp |
| 179 | + ${IMAGE_UTILS_SOURCES} |
| 180 | + LIBS opencv_deps |
| 181 | +) |
| 182 | + |
| 183 | +add_rn_test(VADTests integration/VoiceActivityDetectionTest.cpp |
| 184 | + SOURCES |
| 185 | + ${RNEXECUTORCH_DIR}/models/voice_activity_detection/VoiceActivityDetection.cpp |
| 186 | + ${RNEXECUTORCH_DIR}/models/voice_activity_detection/Utils.cpp |
| 187 | + ${DSP_SOURCES} |
| 188 | +) |
| 189 | + |
| 190 | +add_rn_test(TokenizerModuleTests integration/TokenizerModuleTest.cpp |
| 191 | + SOURCES ${TOKENIZER_SOURCES} |
| 192 | + LIBS tokenizers_deps |
| 193 | +) |
| 194 | + |
| 195 | +add_rn_test(SpeechToTextTests integration/SpeechToTextTest.cpp |
| 196 | + SOURCES |
| 197 | + ${RNEXECUTORCH_DIR}/models/speech_to_text/SpeechToText.cpp |
| 198 | + ${RNEXECUTORCH_DIR}/models/speech_to_text/asr/ASR.cpp |
| 199 | + ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/HypothesisBuffer.cpp |
| 200 | + ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/OnlineASRProcessor.cpp |
| 201 | + ${RNEXECUTORCH_DIR}/data_processing/gzip.cpp |
| 202 | + ${TOKENIZER_SOURCES} |
| 203 | + ${DSP_SOURCES} |
| 204 | + LIBS tokenizers_deps z |
| 205 | +) |
| 206 | + |
| 207 | +add_rn_test(LLMTests integration/LLMTest.cpp |
| 208 | + SOURCES |
| 209 | + ${RNEXECUTORCH_DIR}/models/llm/LLM.cpp |
| 210 | + ${COMMON_DIR}/runner/runner.cpp |
| 211 | + ${COMMON_DIR}/runner/text_prefiller.cpp |
| 212 | + ${COMMON_DIR}/runner/text_decoder_runner.cpp |
| 213 | + ${COMMON_DIR}/runner/sampler.cpp |
| 214 | + ${COMMON_DIR}/runner/arange_util.cpp |
| 215 | + LIBS tokenizers_deps |
| 216 | +) |
| 217 | + |
| 218 | +add_rn_test(TextToImageTests integration/TextToImageTest.cpp |
| 219 | + SOURCES |
| 220 | + ${RNEXECUTORCH_DIR}/models/text_to_image/TextToImage.cpp |
| 221 | + ${RNEXECUTORCH_DIR}/models/text_to_image/Encoder.cpp |
| 222 | + ${RNEXECUTORCH_DIR}/models/text_to_image/UNet.cpp |
| 223 | + ${RNEXECUTORCH_DIR}/models/text_to_image/Decoder.cpp |
| 224 | + ${RNEXECUTORCH_DIR}/models/text_to_image/Scheduler.cpp |
| 225 | + ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp |
| 226 | + ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp |
| 227 | + ${TOKENIZER_SOURCES} |
| 228 | + LIBS tokenizers_deps |
| 229 | +) |
| 230 | + |
| 231 | +add_rn_test(OCRTests integration/OCRTest.cpp |
| 232 | + SOURCES |
| 233 | + ${RNEXECUTORCH_DIR}/models/ocr/OCR.cpp |
| 234 | + ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp |
| 235 | + ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp |
| 236 | + ${RNEXECUTORCH_DIR}/models/ocr/RecognitionHandler.cpp |
| 237 | + ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp |
| 238 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp |
| 239 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp |
| 240 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp |
| 241 | + ${IMAGE_UTILS_SOURCES} |
| 242 | + LIBS opencv_deps |
| 243 | +) |
| 244 | + |
| 245 | +add_rn_test(VerticalOCRTests integration/VerticalOCRTest.cpp |
| 246 | + SOURCES |
| 247 | + ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalOCR.cpp |
| 248 | + ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalDetector.cpp |
| 249 | + ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp |
| 250 | + ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp |
| 251 | + ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp |
| 252 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp |
| 253 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp |
| 254 | + ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp |
| 255 | + ${IMAGE_UTILS_SOURCES} |
| 256 | + LIBS opencv_deps |
| 257 | +) |
0 commit comments