react-native-executorch 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/rnexecutorch/TokenizerModule.cpp +3 -2
- package/common/rnexecutorch/TokenizerModule.h +1 -1
- package/package.json +2 -1
- package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
- package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_model.h +84 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_tokenizer_base.h +6 -87
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/hf_tokenizer.h +28 -176
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/map_utils.h +174 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/model.h +151 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/normalizer.h +55 -1
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/padding.h +112 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/post_processor.h +101 -42
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/pre_tokenizer.h +25 -9
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/token_decoder.h +33 -6
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/tokenizer.h +2 -2
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/truncation.h +92 -0
- package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/wordpiece_model.h +74 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/common/rnexecutorch/tests/CMakeLists.txt +0 -253
- package/common/rnexecutorch/tests/README.md +0 -73
- package/common/rnexecutorch/tests/integration/BaseModelTest.cpp +0 -207
- package/common/rnexecutorch/tests/integration/BaseModelTests.h +0 -120
- package/common/rnexecutorch/tests/integration/ClassificationTest.cpp +0 -117
- package/common/rnexecutorch/tests/integration/ImageEmbeddingsTest.cpp +0 -122
- package/common/rnexecutorch/tests/integration/ImageSegmentationTest.cpp +0 -152
- package/common/rnexecutorch/tests/integration/LLMTest.cpp +0 -155
- package/common/rnexecutorch/tests/integration/OCRTest.cpp +0 -128
- package/common/rnexecutorch/tests/integration/ObjectDetectionTest.cpp +0 -135
- package/common/rnexecutorch/tests/integration/SpeechToTextTest.cpp +0 -97
- package/common/rnexecutorch/tests/integration/StyleTransferTest.cpp +0 -112
- package/common/rnexecutorch/tests/integration/TextEmbeddingsTest.cpp +0 -164
- package/common/rnexecutorch/tests/integration/TextToImageTest.cpp +0 -149
- package/common/rnexecutorch/tests/integration/TokenizerModuleTest.cpp +0 -98
- package/common/rnexecutorch/tests/integration/VerticalOCRTest.cpp +0 -238
- package/common/rnexecutorch/tests/integration/VoiceActivityDetectionTest.cpp +0 -99
- package/common/rnexecutorch/tests/integration/assets/test_audio_float.raw +0 -0
- package/common/rnexecutorch/tests/integration/assets/we_are_software_mansion.jpg +0 -0
- package/common/rnexecutorch/tests/integration/libs/libfbjni.so +0 -0
- package/common/rnexecutorch/tests/integration/stubs/jsi_stubs.cpp +0 -45
- package/common/rnexecutorch/tests/integration/utils/TestUtils.h +0 -36
- package/common/rnexecutorch/tests/run_tests.sh +0 -333
- package/common/rnexecutorch/tests/unit/FileUtilsTest.cpp +0 -32
- package/common/rnexecutorch/tests/unit/LogTest.cpp +0 -529
- package/common/rnexecutorch/tests/unit/NumericalTest.cpp +0 -107
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -e
|
|
3
|
-
|
|
4
|
-
# ============================================================================
|
|
5
|
-
# Constants
|
|
6
|
-
# ============================================================================
|
|
7
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
-
PACKAGE_ROOT="$SCRIPT_DIR/../../.."
|
|
9
|
-
ANDROID_ABI="arm64-v8a"
|
|
10
|
-
ANDROID_LIBS_DIR="$PACKAGE_ROOT/third-party/android/libs"
|
|
11
|
-
DEVICE_TEST_DIR="/data/local/tmp/rnexecutorch_tests"
|
|
12
|
-
MODELS_DIR="$SCRIPT_DIR/integration/assets/models"
|
|
13
|
-
|
|
14
|
-
# ============================================================================
|
|
15
|
-
# Test executables
|
|
16
|
-
# ============================================================================
|
|
17
|
-
TEST_EXECUTABLES=(
|
|
18
|
-
"NumericalTests"
|
|
19
|
-
"LogTests"
|
|
20
|
-
"BaseModelTests"
|
|
21
|
-
"ClassificationTests"
|
|
22
|
-
"ObjectDetectionTests"
|
|
23
|
-
"ImageEmbeddingsTests"
|
|
24
|
-
"TextEmbeddingsTests"
|
|
25
|
-
"StyleTransferTests"
|
|
26
|
-
"VADTests"
|
|
27
|
-
"TokenizerModuleTests"
|
|
28
|
-
"SpeechToTextTests"
|
|
29
|
-
"LLMTests"
|
|
30
|
-
"ImageSegmentationTests"
|
|
31
|
-
"TextToImageTests"
|
|
32
|
-
"OCRTests"
|
|
33
|
-
"VerticalOCRTests"
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
# ============================================================================
|
|
37
|
-
# Test assets
|
|
38
|
-
# ============================================================================
|
|
39
|
-
TEST_ASSETS=(
|
|
40
|
-
"integration/assets/test_audio_float.raw"
|
|
41
|
-
"integration/assets/we_are_software_mansion.jpg"
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
# ============================================================================
|
|
45
|
-
# Models to download (format: "filename|url")
|
|
46
|
-
# ============================================================================
|
|
47
|
-
MODELS=(
|
|
48
|
-
"style_transfer_candy_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-style-transfer-candy/resolve/main/xnnpack/style_transfer_candy_xnnpack.pte"
|
|
49
|
-
"efficientnet_v2_s_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-efficientnet-v2-s/resolve/v0.6.0/xnnpack/efficientnet_v2_s_xnnpack.pte"
|
|
50
|
-
"ssdlite320-mobilenetv3-large.pte|https://huggingface.co/software-mansion/react-native-executorch-ssdlite320-mobilenet-v3-large/resolve/v0.6.0/ssdlite320-mobilenetv3-large.pte"
|
|
51
|
-
"test_image.jpg|https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Cat_November_2010-1a.jpg/1200px-Cat_November_2010-1a.jpg"
|
|
52
|
-
"clip-vit-base-patch32-vision_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-clip-vit-base-patch32/resolve/v0.6.0/clip-vit-base-patch32-vision_xnnpack.pte"
|
|
53
|
-
"all-MiniLM-L6-v2_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-all-MiniLM-L6-v2/resolve/v0.6.0/all-MiniLM-L6-v2_xnnpack.pte"
|
|
54
|
-
"tokenizer.json|https://huggingface.co/software-mansion/react-native-executorch-all-MiniLM-L6-v2/resolve/v0.6.0/tokenizer.json"
|
|
55
|
-
"fsmn-vad_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-fsmn-vad/resolve/main/xnnpack/fsmn-vad_xnnpack.pte"
|
|
56
|
-
"whisper_tiny_en_encoder_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/main/xnnpack/whisper_tiny_en_encoder_xnnpack.pte"
|
|
57
|
-
"whisper_tiny_en_decoder_xnnpack.pte|https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/main/xnnpack/whisper_tiny_en_decoder_xnnpack.pte"
|
|
58
|
-
"whisper_tokenizer.json|https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/v0.6.0/tokenizer.json"
|
|
59
|
-
"smolLm2_135M_8da4w.pte|https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.6.0/smolLm-2-135M/quantized/smolLm2_135M_8da4w.pte"
|
|
60
|
-
"smollm_tokenizer.json|https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.6.0/tokenizer.json"
|
|
61
|
-
"deeplabV3_xnnpack_fp32.pte|https://huggingface.co/software-mansion/react-native-executorch-deeplab-v3/resolve/v0.6.0/xnnpack/deeplabV3_xnnpack_fp32.pte"
|
|
62
|
-
"xnnpack_crnn_english.pte|https://huggingface.co/software-mansion/react-native-executorch-recognizer-crnn.en/resolve/v0.7.0/xnnpack/english/xnnpack_crnn_english.pte"
|
|
63
|
-
"xnnpack_craft_quantized.pte|https://huggingface.co/software-mansion/react-native-executorch-detector-craft/resolve/v0.7.0/xnnpack/xnnpack_craft.pte"
|
|
64
|
-
"t2i_tokenizer.json|https://huggingface.co/software-mansion/react-native-executorch-bk-sdm-tiny/resolve/v0.6.0/tokenizer/tokenizer.json"
|
|
65
|
-
"t2i_encoder.pte|https://huggingface.co/software-mansion/react-native-executorch-bk-sdm-tiny/resolve/v0.6.0/text_encoder/model.pte"
|
|
66
|
-
"t2i_unet.pte|https://huggingface.co/software-mansion/react-native-executorch-bk-sdm-tiny/resolve/v0.6.0/unet/model.256.pte"
|
|
67
|
-
"t2i_decoder.pte|https://huggingface.co/software-mansion/react-native-executorch-bk-sdm-tiny/resolve/v0.6.0/vae/model.256.pte"
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
# ============================================================================
|
|
71
|
-
# Libraries to push
|
|
72
|
-
# ============================================================================
|
|
73
|
-
REQUIRED_LIBS=(
|
|
74
|
-
"$ANDROID_LIBS_DIR/executorch/$ANDROID_ABI/libexecutorch.so:libexecutorch_jni.so"
|
|
75
|
-
"$ANDROID_LIBS_DIR/pthreadpool/$ANDROID_ABI/libpthreadpool.so:libpthreadpool.so"
|
|
76
|
-
"$ANDROID_LIBS_DIR/cpuinfo/$ANDROID_ABI/libcpuinfo.so:libcpuinfo.so"
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
# Dynamically find libfbjni.so from CMake builds (exclude node_modules for speed)
|
|
80
|
-
# Get libc++_shared.so directly from NDK
|
|
81
|
-
MONOREPO_ROOT="$PACKAGE_ROOT/../../.."
|
|
82
|
-
|
|
83
|
-
LIBFBJNI_PATH="$SCRIPT_DIR/integration/libs/libfbjni.so"
|
|
84
|
-
|
|
85
|
-
if [ -z "$LIBFBJNI_PATH" ]; then
|
|
86
|
-
echo "Error: libfbjni.so not found."
|
|
87
|
-
echo "Please build an app first: cd apps/computer-vision/android && ./gradlew assembleRelease"
|
|
88
|
-
exit 1
|
|
89
|
-
fi
|
|
90
|
-
|
|
91
|
-
# Get libc++_shared.so from NDK based on host platform
|
|
92
|
-
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
93
|
-
NDK_HOST="darwin-x86_64"
|
|
94
|
-
else
|
|
95
|
-
NDK_HOST="linux-x86_64"
|
|
96
|
-
fi
|
|
97
|
-
|
|
98
|
-
LIBCPP_PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/$NDK_HOST/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so"
|
|
99
|
-
|
|
100
|
-
if [ ! -f "$LIBCPP_PATH" ]; then
|
|
101
|
-
echo "Error: libc++_shared.so not found at: $LIBCPP_PATH"
|
|
102
|
-
exit 1
|
|
103
|
-
fi
|
|
104
|
-
|
|
105
|
-
GRADLE_LIBS=(
|
|
106
|
-
"$LIBFBJNI_PATH:libfbjni.so"
|
|
107
|
-
"$LIBCPP_PATH:libc++_shared.so"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
# ============================================================================
|
|
111
|
-
# Flags
|
|
112
|
-
# ============================================================================
|
|
113
|
-
REFRESH_MODELS=false
|
|
114
|
-
SKIP_BUILD=false
|
|
115
|
-
|
|
116
|
-
# ============================================================================
|
|
117
|
-
# Functions
|
|
118
|
-
# ============================================================================
|
|
119
|
-
|
|
120
|
-
print_usage() {
|
|
121
|
-
cat <<EOF
|
|
122
|
-
Usage: $0 [OPTIONS]
|
|
123
|
-
|
|
124
|
-
Options:
|
|
125
|
-
--refresh-models Force re-download of all models
|
|
126
|
-
--skip-build Skip the CMake build step
|
|
127
|
-
--help Show this help message
|
|
128
|
-
|
|
129
|
-
EOF
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
log() {
|
|
133
|
-
echo "[$(date +'%H:%M:%S')] $*"
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
error() {
|
|
137
|
-
echo "[ERROR] $*" >&2
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
download_if_needed() {
|
|
141
|
-
local url="$1"
|
|
142
|
-
local output="$2"
|
|
143
|
-
local filepath="$MODELS_DIR/$output"
|
|
144
|
-
|
|
145
|
-
if [ "$REFRESH_MODELS" = true ] || [ ! -f "$filepath" ]; then
|
|
146
|
-
log "Downloading $output..."
|
|
147
|
-
wget -q -O "$filepath" "$url"
|
|
148
|
-
else
|
|
149
|
-
log "$output already exists, skipping"
|
|
150
|
-
fi
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
push_file() {
|
|
154
|
-
local src="$1"
|
|
155
|
-
local dest="$2"
|
|
156
|
-
|
|
157
|
-
if [ -f "$src" ]; then
|
|
158
|
-
adb push "$src" "$dest" >/dev/null
|
|
159
|
-
else
|
|
160
|
-
error "File not found: $src"
|
|
161
|
-
fi
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
run_test() {
|
|
165
|
-
local test_exe="$1"
|
|
166
|
-
|
|
167
|
-
if adb shell "[ -f $DEVICE_TEST_DIR/$test_exe ]"; then
|
|
168
|
-
log "Running $test_exe"
|
|
169
|
-
if ! adb shell "cd $DEVICE_TEST_DIR && LD_LIBRARY_PATH=. ./$test_exe --gtest_color=yes"; then
|
|
170
|
-
return 1
|
|
171
|
-
fi
|
|
172
|
-
fi
|
|
173
|
-
return 0
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
# ============================================================================
|
|
177
|
-
# Parse arguments
|
|
178
|
-
# ============================================================================
|
|
179
|
-
for arg in "$@"; do
|
|
180
|
-
case $arg in
|
|
181
|
-
--refresh-models)
|
|
182
|
-
REFRESH_MODELS=true
|
|
183
|
-
shift
|
|
184
|
-
;;
|
|
185
|
-
--skip-build)
|
|
186
|
-
SKIP_BUILD=true
|
|
187
|
-
shift
|
|
188
|
-
;;
|
|
189
|
-
--help)
|
|
190
|
-
print_usage
|
|
191
|
-
exit 0
|
|
192
|
-
;;
|
|
193
|
-
*)
|
|
194
|
-
error "Unknown option: $arg"
|
|
195
|
-
print_usage
|
|
196
|
-
exit 1
|
|
197
|
-
;;
|
|
198
|
-
esac
|
|
199
|
-
done
|
|
200
|
-
|
|
201
|
-
# ============================================================================
|
|
202
|
-
# Validate environment
|
|
203
|
-
# ============================================================================
|
|
204
|
-
if ! adb shell ":"; then
|
|
205
|
-
error "ADB shell couldn't run successfully"
|
|
206
|
-
exit 1
|
|
207
|
-
fi
|
|
208
|
-
|
|
209
|
-
if [ -z "$ANDROID_NDK" ]; then
|
|
210
|
-
error "ANDROID_NDK is not set"
|
|
211
|
-
exit 1
|
|
212
|
-
fi
|
|
213
|
-
|
|
214
|
-
log "ANDROID_NDK = $ANDROID_NDK"
|
|
215
|
-
|
|
216
|
-
# ============================================================================
|
|
217
|
-
# Build tests
|
|
218
|
-
# ============================================================================
|
|
219
|
-
if [ "$SKIP_BUILD" = false ]; then
|
|
220
|
-
log "Building tests..."
|
|
221
|
-
rm -rf build
|
|
222
|
-
mkdir build
|
|
223
|
-
cd build
|
|
224
|
-
|
|
225
|
-
cmake .. \
|
|
226
|
-
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
|
|
227
|
-
-DANDROID_ABI=$ANDROID_ABI \
|
|
228
|
-
-DANDROID_PLATFORM=android-34 \
|
|
229
|
-
-DANDROID_STL=c++_shared
|
|
230
|
-
|
|
231
|
-
make
|
|
232
|
-
else
|
|
233
|
-
if ! [ -d build ]; then
|
|
234
|
-
error "Build was skipped and the build directory doesn't exist"
|
|
235
|
-
exit 1
|
|
236
|
-
fi
|
|
237
|
-
log "Skipping build..."
|
|
238
|
-
cd build
|
|
239
|
-
fi
|
|
240
|
-
|
|
241
|
-
# ============================================================================
|
|
242
|
-
# Prepare device
|
|
243
|
-
# ============================================================================
|
|
244
|
-
log "Creating device test directory..."
|
|
245
|
-
adb shell "mkdir -p $DEVICE_TEST_DIR"
|
|
246
|
-
|
|
247
|
-
# ============================================================================
|
|
248
|
-
# Push test executables
|
|
249
|
-
# ============================================================================
|
|
250
|
-
log "Pushing test executables to device..."
|
|
251
|
-
for test_exe in "${TEST_EXECUTABLES[@]}"; do
|
|
252
|
-
if [ -f "$test_exe" ]; then
|
|
253
|
-
push_file "$test_exe" "$DEVICE_TEST_DIR/"
|
|
254
|
-
adb shell "chmod +x $DEVICE_TEST_DIR/$test_exe"
|
|
255
|
-
fi
|
|
256
|
-
done
|
|
257
|
-
|
|
258
|
-
# ============================================================================
|
|
259
|
-
# Push test assets
|
|
260
|
-
# ============================================================================
|
|
261
|
-
log "Pushing test assets to device..."
|
|
262
|
-
for asset in "${TEST_ASSETS[@]}"; do
|
|
263
|
-
push_file "../$asset" "$DEVICE_TEST_DIR/"
|
|
264
|
-
done
|
|
265
|
-
|
|
266
|
-
# ============================================================================
|
|
267
|
-
# Download models
|
|
268
|
-
# ============================================================================
|
|
269
|
-
log "Downloading models (use --refresh-models to force re-download)..."
|
|
270
|
-
mkdir -p "$MODELS_DIR"
|
|
271
|
-
|
|
272
|
-
for entry in "${MODELS[@]}"; do
|
|
273
|
-
IFS='|' read -r filename url <<<"$entry"
|
|
274
|
-
download_if_needed "$url" "$filename"
|
|
275
|
-
done
|
|
276
|
-
|
|
277
|
-
# ============================================================================
|
|
278
|
-
# Push models
|
|
279
|
-
# ============================================================================
|
|
280
|
-
log "Pushing models to device..."
|
|
281
|
-
for model in "$MODELS_DIR"/*; do
|
|
282
|
-
if [ -f "$model" ]; then
|
|
283
|
-
push_file "$model" "$DEVICE_TEST_DIR/"
|
|
284
|
-
fi
|
|
285
|
-
done
|
|
286
|
-
|
|
287
|
-
# ============================================================================
|
|
288
|
-
# Push libraries
|
|
289
|
-
# ============================================================================
|
|
290
|
-
log "Pushing shared libraries to device..."
|
|
291
|
-
|
|
292
|
-
for lib_entry in "${REQUIRED_LIBS[@]}"; do
|
|
293
|
-
IFS=':' read -r src dest <<<"$lib_entry"
|
|
294
|
-
if [ -f "$src" ]; then
|
|
295
|
-
push_file "$src" "$DEVICE_TEST_DIR/$dest"
|
|
296
|
-
fi
|
|
297
|
-
done
|
|
298
|
-
|
|
299
|
-
for lib_entry in "${GRADLE_LIBS[@]}"; do
|
|
300
|
-
IFS=':' read -r src dest <<<"$lib_entry"
|
|
301
|
-
if [ -f "$src" ]; then
|
|
302
|
-
push_file "$src" "$DEVICE_TEST_DIR/"
|
|
303
|
-
else
|
|
304
|
-
error "Library not found: $src"
|
|
305
|
-
fi
|
|
306
|
-
done
|
|
307
|
-
|
|
308
|
-
# ============================================================================
|
|
309
|
-
# Run tests
|
|
310
|
-
# ============================================================================
|
|
311
|
-
log "Running tests on device..."
|
|
312
|
-
FAILED=0
|
|
313
|
-
for test_exe in "${TEST_EXECUTABLES[@]}"; do
|
|
314
|
-
if ! run_test "$test_exe"; then
|
|
315
|
-
FAILED=1
|
|
316
|
-
fi
|
|
317
|
-
done
|
|
318
|
-
|
|
319
|
-
# ============================================================================
|
|
320
|
-
# Cleanup
|
|
321
|
-
# ============================================================================
|
|
322
|
-
log "Cleaning up device..."
|
|
323
|
-
adb shell "rm -rf $DEVICE_TEST_DIR"
|
|
324
|
-
|
|
325
|
-
cd ..
|
|
326
|
-
|
|
327
|
-
if [ $FAILED -eq 0 ]; then
|
|
328
|
-
log "All tests passed!"
|
|
329
|
-
else
|
|
330
|
-
error "Some tests failed"
|
|
331
|
-
fi
|
|
332
|
-
|
|
333
|
-
exit $FAILED
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#include "../data_processing/FileUtils.h"
|
|
2
|
-
#include <fstream>
|
|
3
|
-
#include <gtest/gtest.h>
|
|
4
|
-
#include <iostream>
|
|
5
|
-
|
|
6
|
-
#include <rnexecutorch/Error.h>
|
|
7
|
-
#include <rnexecutorch/ErrorCodes.h>
|
|
8
|
-
|
|
9
|
-
namespace rnexecutorch::file_utils {
|
|
10
|
-
class FileIOTest : public ::testing::Test {
|
|
11
|
-
protected:
|
|
12
|
-
std::string tempFileName = "temp_test_file.txt";
|
|
13
|
-
|
|
14
|
-
void SetUp() override {
|
|
15
|
-
std::ofstream out(tempFileName, std::ios::binary);
|
|
16
|
-
out << "Hello, world";
|
|
17
|
-
out.close();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
void TearDown() override { std::remove(tempFileName.c_str()); }
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
TEST_F(FileIOTest, LoadBytesFromFileSuccessfully) {
|
|
24
|
-
std::string data = loadBytesFromFile(tempFileName);
|
|
25
|
-
EXPECT_EQ(data, "Hello, world");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
TEST_F(FileIOTest, LoadBytesFromFileFailOnNonExistentFile) {
|
|
29
|
-
EXPECT_THROW(
|
|
30
|
-
{ loadBytesFromFile("non_existent_file.txt"); }, RnExecutorchError);
|
|
31
|
-
}
|
|
32
|
-
} // namespace rnexecutorch::file_utils
|