forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·337 lines (310 loc) · 10 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# test script for MNN-Release
#
# 0. arg = local: [ test for your local build ]
# 1. unit-test;
# 2. model-test;
# 3. onnx convert test
# 4. tf convert test
# 5. tflite convert test
# 6. torch convert test
# 7. ptq test
#
# 1. arg = linux: [ all test on linux with coverage ]
# 0. static check
# 1. build for linux;
# 2. unit-test;
# 3. model-test;
# 4. onnx convert test
# 5. tf convert test
# 6. tflite convert test
# 7. torch convert test
# 8. ptq test
# 9. convert-report;
#
# 2. arg = android: [ simple test on android ]
# 1. build Android with static_stl
# 2. build Android arm64
# 3. unit-test for Android arm64
# 4. build Android arm32
# 5. unit-test for Android arm32
# 0. build for android
USER_NAME=`whoami`
USER_HOME="$(echo -n $(bash -c "cd ~${USER_NAME} && pwd"))"
failed() {
printf "TEST_NAME_EXCEPTION: Exception\nTEST_CASE_AMOUNT_EXCEPTION: {\"blocked\":0,\"failed\":1,\"passed\":0,\"skipped\":0}\n"
exit 1
}
static_check() {
changefiles=$(git show --name-only | grep -E "^source/.*\.(cpp|cc|c|h|hpp)$")
if [ -n "$changefiles" ]; then
cppcheck --error-exitcode=1 --addon=tools/script/mnn_rules.py $changefiles 1> /dev/null
fi
static_check_wrong=$[$? > 0]
printf "TEST_NAME_STATIC_CHECK: cppcheck静态分析\nTEST_CASE_AMOUNT_STATIC_CHECK: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" \
$static_check_wrong $[1 - $static_check_wrong]
if [ $static_check_wrong -ne 0 ]; then
echo '### cppcheck静态分析失败,测试终止!'
failed
fi
}
android_static_build() {
BASH_FILE="$USER_HOME/.zshrc"
if [ -f "$BASH_FILE" ]; then
source $BASH_FILE
fi
if [ ! $ANDROID_NDK ] || [ ! -d $ANDROID_NDK ]; then
export ANDROID_NDK="$USER_HOME/android-ndk-r21"
fi
mkdir android_build
pushd android_build
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_STL=c++_static \
-DMNN_USE_LOGCAT=false \
-DMNN_BUILD_BENCHMARK=ON \
-DANDROID_NATIVE_API_LEVEL=android-21 \
-DMNN_BUILD_FOR_ANDROID_COMMAND=true \
-DMNN_OPENGL=true \
-DMNN_BUILD_TRAIN=true \
-DMNN_VULKAN=true \
-DMNN_SUPPORT_BF16=true \
-DMNN_OPENCL=true -DMNN_ARM82=true \
-DNATIVE_LIBRARY_OUTPUT=. -DNATIVE_INCLUDE_OUTPUT=. $1 $2 $3
make -j16
android_build_wrong=$[$? > 0]
printf "TEST_NAME_ANDROID_STATIC: AndroidStatic编译测试\nTEST_CASE_AMOUNT_ANDROID_STATIC: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" \
$android_build_wrong $[1 - $android_build_wrong]
if [ $android_build_wrong -ne 0 ]; then
echo '### AndroidStatic编译失败,测试终止!'
failed
fi
popd
:<<!
mkdir android_build_32
pushd android_build_32
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_ABI="armeabi-v7a" \
-DANDROID_STL=c++_shared \
-DMNN_USE_LOGCAT=false \
-DMNN_BUILD_BENCHMARK=ON \
-DANDROID_NATIVE_API_LEVEL=android-21 \
-DMNN_BUILD_FOR_ANDROID_COMMAND=true \
-DMNN_OPENGL=true \
-DMNN_BUILD_TRAIN=true \
-DMNN_VULKAN=true \
-DMNN_BUILD_MINI=true \
-DMNN_SUPPORT_BF16=true \
-DMNN_OPENCL=true\
-DNATIVE_LIBRARY_OUTPUT=. -DNATIVE_INCLUDE_OUTPUT=.
make -j16
android_build_wrong=$[$? > 0]
printf "TEST_NAME_ANDROID_32: Android 32-Mini 编译测试\nTEST_CASE_AMOUNT_ANDROID_32: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" $android_build_wrong $[1 - $android_build_wrong]
if [ $android_build_wrong -ne 0 ]; then
echo '### Android编译失败,测试终止!'
failed
fi
popd
!
}
linux_build() {
if [ $# -gt 0 ]; then
COVERAGE=ON
else
COVERAGE=OFF
fi
mkdir build_non_sse
pushd build_non_sse
cmake .. -DMNN_USE_SSE=OFF && make -j16
linux_build_wrong=$[$? > 0]
popd
mkdir build
pushd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DMNN_BUILD_TEST=ON \
-DMNN_CUDA=ON \
-DMNN_BUILD_QUANTOOLS=ON \
-DMNN_BUILD_DEMO=ON \
-DMNN_BUILD_CONVERTER=ON \
-DMNN_BUILD_TORCH=ON \
-DMNN_ENABLE_COVERAGE=$COVERAGE
make -j16
linux_build_wrong+=$[$? > 0]
printf "TEST_NAME_LINUX: Linux编译测试\nTEST_CASE_AMOUNT_LINUX: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" $linux_build_wrong $[2 - $linux_build_wrong]
if [ $linux_build_wrong -ne 0 ]; then
echo '### Linux编译失败,测试终止!'
failed
fi
# Don't remove this! It turn off MNN_CUDA and MNN_TENSORRT in build, workaround some bug in PTQTest
cmake .. -DMNN_CUDA=OFF -DMNN_TENSORRT=OFF && make -j16
}
unit_test() {
./run_test.out
if [ $? -ne 0 ]; then
echo '### 单元测试失败,测试终止!'
failed
fi
./run_test.out op 0 0 4
if [ $? -ne 0 ]; then
echo '### 多线程单元测试失败,测试终止!'
failed
fi
}
model_test() {
../tools/script/modelTest.py ~/AliNNModel 0 0.002
if [ $? -ne 0 ]; then
echo '### 模型测试失败,测试终止!'
failed
fi
../tools/script/modelTest.py ~/AliNNModel 0 0.002 0 1
if [ $? -ne 0 ]; then
echo '### 静态模型测试失败,测试终止!'
failed
fi
}
onnx_convert_test() {
../tools/script/convertOnnxTest.py ~/AliNNModel
if [ $? -ne 0 ]; then
echo '### ONNXConvert测试失败,测试终止!'
failed
fi
}
tf_convert_test() {
../tools/script/convertTfTest.py ~/AliNNModel
if [ $? -ne 0 ]; then
echo '### TFConvert测试失败,测试终止!'
failed
fi
}
tflite_convert_test() {
../tools/script/convertTfliteTest.py ~/AliNNModel
if [ $? -ne 0 ]; then
echo '### TFLITEConvert测试失败,测试终止!'
failed
fi
}
torch_convert_test() {
../tools/script/convertTorchTest.py ~/AliNNModel
if [ $? -ne 0 ]; then
echo '### TORCHConvert测试失败,测试终止!'
failed
fi
}
ptq_test() {
../tools/script/testPTQ.py ~/AliNNModel
if [ $? -ne 0 ]; then
echo '### PTQ测试失败,测试终止!'
failed
fi
}
coverage_init() {
popd
lcov -c -i -d ./ -o init.info
pushd build
}
coverage_report() {
popd
cover_report_dir="../../../../CoverageReport"
lcov -c -d ./ -o cover.info
lcov -a init.info -a cover.info -o total.info
lcov --remove total.info \
'*/usr/include/*' '*/usr/lib/*' '*/usr/lib64/*' '*/usr/local/include/*' '*/usr/local/lib/*' '*/usr/local/lib64/*' \
'*/3rd_party/*' '*/build/*' '*/schema/*' '*/test/*' '/tmp/*' \
-o final.info
commitId=$(git log | head -n1 | awk '{print $2}')
genhtml -o cover_report --legend --title "MNN Coverage Report [commit SHA1:${commitId}]" --prefix=`pwd` final.info
coverage_wrong=$[$? > 0]
printf "TEST_NAME_COVERAGE: 代码覆盖率(点击\"通过\"查看报告)\nTEST_CASE_AMOUNT_COVERAGE: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" $coverage_wrong $[1 - $coverage_wrong]
if [ $coverage_wrong -ne 0 ]; then
echo '### 代码覆盖率生成失败,测试终止!'
failed
else
hostIp=$(cat .aoneci.yml | grep host -m 1 | awk '{print $2}')
testId=$(pwd | awk -F "/" '{print $(NF-1)}')
mv cover_report $cover_report_dir/$testId
echo "TEST_REPORT_COVERAGE: http://$hostIp/$testId"
fi
# clean test dir
cd ../.. && rm -rf $testId
}
android_test() {
pushd project/android
# 1. build Android32
mkdir build_32
pushd build_32
../build_32.sh
android32_build_wrong=$[$? > 0]
mnn32_size=$(ls -lh libMNN.so | awk '{print $5}')
expr32_size=$(ls -lh libMNN_Express.so | awk '{print $5}')
printf "TEST_NAME_ANDROID_32: Android32编译测试(libMNN.so - %s, libMNN_Express.so - %s)\nTEST_CASE_AMOUNT_ANDROID_32: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" \
$mnn32_size $expr32_size $android32_build_wrong $[1 - $android32_build_wrong]
if [ $android32_build_wrong -ne 0 ]; then
echo '### Android32编译失败,测试终止!'
failed
fi
# 2. test Androird32
python3 ../../../tools/script/AndroidTest.py ~/AliNNModel 32 unit
if [ $? -ne 0 ]; then
echo '### AndroidTest32测试失败,测试终止!'
failed
fi
popd
# 3. build Android64
mkdir build_64
pushd build_64
../build_64.sh
android64_build_wrong=$[$? > 0]
mnn64_size=$(ls -lh libMNN.so | awk '{print $5}')
expr64_size=$(ls -lh libMNN_Express.so | awk '{print $5}')
printf "TEST_NAME_ANDROID_64: Android64编译测试(libMNN.so - %s, libMNN_Express.so - %s)\nTEST_CASE_AMOUNT_ANDROID_64: {\"blocked\":0,\"failed\":%d,\"passed\":%d,\"skipped\":0}\n" \
$mnn64_size $expr64_size $android64_build_wrong $[1 - $android64_build_wrong]
if [ $android64_build_wrong -ne 0 ]; then
echo '### Android64编译失败,测试终止!'
failed
fi
# 4. test Android64
python3 ../../../tools/script/AndroidTest.py ~/AliNNModel 64 unit
if [ $? -ne 0 ]; then
echo '### AndroidTest64测试失败,测试终止!'
failed
fi
popd
popd
}
case "$1" in
local)
pushd build
unit_test
model_test
onnx_convert_test
tf_convert_test
tflite_convert_test
torch_convert_test
ptq_test
;;
linux)
static_check
linux_build 1
coverage_init
unit_test
model_test
onnx_convert_test
tf_convert_test
tflite_convert_test
torch_convert_test
ptq_test
coverage_report
;;
android)
android_static_build
android_test
;;
*)
echo $"Usage: $0 {local|linux|android}"
exit 2
esac
exit $?