test_wamr.sh 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. function DEBUG() {
  7. [[ -n $(env | grep "\<DEBUG\>") ]] && $@
  8. }
  9. DEBUG set -xv pipefail
  10. function help()
  11. {
  12. echo "test_wamr.sh [options]"
  13. echo "-c clean previous test results, not start test"
  14. echo "-s {suite_name} test only one suite (spec|wasi_certification)"
  15. echo "-m set compile target of iwasm(x86_64|x86_32|armv7_vfp|thumbv7_vfp|riscv64_lp64d|riscv64_lp64)"
  16. echo "-t set compile type of iwasm(classic-interp|fast-interp|jit|aot|fast-jit|multi-tier-jit)"
  17. echo "-M enable multi module feature"
  18. echo "-p enable multi thread feature"
  19. echo "-S enable SIMD feature"
  20. echo "-G enable GC feature"
  21. echo "-X enable XIP feature"
  22. echo "-x test SGX"
  23. echo "-w enable WASI threads"
  24. echo "-b use the wabt binary release package instead of compiling from the source code"
  25. echo "-g build iwasm with debug version"
  26. echo "-v enable GC heap verification"
  27. echo "-P run the spec test parallelly"
  28. echo "-Q enable qemu"
  29. echo "-F set the firmware path used by qemu"
  30. echo "-C enable code coverage collect"
  31. }
  32. OPT_PARSED=""
  33. WABT_BINARY_RELEASE="NO"
  34. #default type
  35. TYPE=("classic-interp" "fast-interp" "jit" "aot" "fast-jit" "multi-tier-jit")
  36. #default target
  37. TARGET="X86_64"
  38. ENABLE_WASI_THREADS=0
  39. ENABLE_MULTI_MODULE=0
  40. ENABLE_MULTI_THREAD=0
  41. COLLECT_CODE_COVERAGE=0
  42. ENABLE_SIMD=0
  43. ENABLE_GC=0
  44. ENABLE_XIP=0
  45. ENABLE_DEBUG_VERSION=0
  46. ENABLE_GC_HEAP_VERIFY=0
  47. #unit test case arrary
  48. TEST_CASE_ARR=()
  49. SGX_OPT=""
  50. PLATFORM=$(uname -s | tr A-Z a-z)
  51. PARALLELISM=0
  52. ENABLE_QEMU=0
  53. QEMU_FIRMWARE=""
  54. WASI_TESTSUITE_COMMIT="aca78d919355ae00af141e6741a439039615b257"
  55. while getopts ":s:cabgvt:m:MCpSXxwPGQF:" opt
  56. do
  57. OPT_PARSED="TRUE"
  58. case $opt in
  59. s)
  60. TEST_CASE_ARR+=($OPTARG)
  61. # get next suite if there are multiple vaule in -s
  62. eval "nxarg=\${$((OPTIND))}"
  63. # just get test cases, loop until the next symbol '-'
  64. # IN ====> -s spec wasi unit -t fast-classic
  65. # GET ====> spec wasi unit
  66. while [[ "${nxarg}" != -* && ${nxarg} ]];
  67. do
  68. TEST_CASE_ARR+=(${nxarg})
  69. OPTIND=$((OPTIND+1))
  70. eval "nxarg=\${$((OPTIND))}"
  71. done
  72. echo "test following cases: ${TEST_CASE_ARR[@]}"
  73. ;;
  74. c)
  75. read -t 5 -p "Are you sure to delete all reports. y/n " cmd
  76. if [[ $cmd == "y" && $(ls -A workspace/report) ]];then
  77. rm -fr workspace/report/*
  78. rm -fr /tmp/*.wasm /tmp/*.wast /tmp/*.aot
  79. echo "cleaned all reports and temp files"
  80. fi
  81. exit 0;;
  82. a)
  83. TEST_ALL_AOT_RUNTIME="all"
  84. echo "test all runtimes in sightglass_aot"
  85. ;;
  86. b)
  87. WABT_BINARY_RELEASE="YES"
  88. echo "use a WABT binary release instead of compiling from source code"
  89. ;;
  90. t)
  91. echo "set compile type of wamr " ${OPTARG}
  92. if [[ ${OPTARG} != "classic-interp" && ${OPTARG} != "fast-interp" \
  93. && ${OPTARG} != "jit" && ${OPTARG} != "aot"
  94. && ${OPTARG} != "fast-jit" && ${OPTARG} != "multi-tier-jit" ]]; then
  95. echo "*----- please varify a type of compile when using -t! -----*"
  96. help
  97. exit 1
  98. fi
  99. TYPE=(${OPTARG})
  100. ;;
  101. m)
  102. echo "set compile target of wamr" ${OPTARG}
  103. TARGET=${OPTARG^^} # set target to uppercase if input x86_32 or x86_64 --> X86_32 and X86_64
  104. ;;
  105. w)
  106. echo "enable WASI threads"
  107. ENABLE_WASI_THREADS=1
  108. ;;
  109. M)
  110. echo "enable multi module feature"
  111. ENABLE_MULTI_MODULE=1
  112. ;;
  113. C)
  114. echo "enable code coverage"
  115. COLLECT_CODE_COVERAGE=1
  116. ;;
  117. p)
  118. echo "enable multi thread feature"
  119. ENABLE_MULTI_THREAD=1
  120. ;;
  121. S)
  122. echo "enable SIMD feature"
  123. ENABLE_SIMD=1
  124. ;;
  125. X)
  126. echo "enable XIP feature"
  127. ENABLE_XIP=1
  128. ;;
  129. x)
  130. echo "test SGX"
  131. SGX_OPT="--sgx"
  132. ;;
  133. g)
  134. echo "enable build iwasm with debug version"
  135. ENABLE_DEBUG_VERSION=1
  136. ;;
  137. v)
  138. echo "enable GC heap verification"
  139. ENABLE_GC_HEAP_VERIFY=1
  140. ;;
  141. G)
  142. echo "enable GC feature"
  143. ENABLE_GC=1
  144. ;;
  145. P)
  146. PARALLELISM=1
  147. ;;
  148. Q)
  149. echo "enable QEMU"
  150. ENABLE_QEMU=1
  151. ;;
  152. F)
  153. echo "QEMU firmware" ${OPTARG}
  154. QEMU_FIRMWARE=${OPTARG}
  155. ;;
  156. ?)
  157. help
  158. exit 1;;
  159. esac
  160. done
  161. # Parameters are not allowed, use options instead
  162. if [ -z "$OPT_PARSED" ];
  163. then
  164. if [ ! -z "$1" ];
  165. then
  166. help
  167. exit 1
  168. fi
  169. fi
  170. mkdir -p workspace
  171. cd workspace
  172. readonly WORK_DIR=$PWD
  173. readonly DATE=$(date +%Y-%m-%d_%H:%M:%S)
  174. readonly REPORT_DIR=${WORK_DIR}/report/${DATE}
  175. mkdir -p ${REPORT_DIR}
  176. readonly WAMR_DIR=${WORK_DIR}/../../..
  177. if [[ ${SGX_OPT} == "--sgx" ]];then
  178. readonly IWASM_LINUX_ROOT_DIR="${WAMR_DIR}/product-mini/platforms/linux-sgx"
  179. readonly IWASM_CMD="${WAMR_DIR}/product-mini/platforms/linux-sgx/enclave-sample/iwasm"
  180. else
  181. readonly IWASM_LINUX_ROOT_DIR="${WAMR_DIR}/product-mini/platforms/${PLATFORM}"
  182. readonly IWASM_CMD="${WAMR_DIR}/product-mini/platforms/${PLATFORM}/build/iwasm"
  183. fi
  184. readonly WAMRC_CMD="${WAMR_DIR}/wamr-compiler/build/wamrc"
  185. readonly CLASSIC_INTERP_COMPILE_FLAGS="\
  186. -DWAMR_BUILD_TARGET=${TARGET} \
  187. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  188. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \
  189. -DWAMR_BUILD_SPEC_TEST=1 \
  190. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  191. readonly FAST_INTERP_COMPILE_FLAGS="\
  192. -DWAMR_BUILD_TARGET=${TARGET} \
  193. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 \
  194. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \
  195. -DWAMR_BUILD_SPEC_TEST=1 \
  196. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  197. # jit: report linking error if set COLLECT_CODE_COVERAGE,
  198. # now we don't collect code coverage of jit type
  199. readonly ORC_EAGER_JIT_COMPILE_FLAGS="\
  200. -DWAMR_BUILD_TARGET=${TARGET} \
  201. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  202. -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \
  203. -DWAMR_BUILD_LAZY_JIT=0 \
  204. -DWAMR_BUILD_SPEC_TEST=1 \
  205. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  206. readonly ORC_LAZY_JIT_COMPILE_FLAGS="\
  207. -DWAMR_BUILD_TARGET=${TARGET} \
  208. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  209. -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \
  210. -DWAMR_BUILD_LAZY_JIT=1 \
  211. -DWAMR_BUILD_SPEC_TEST=1 \
  212. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  213. readonly AOT_COMPILE_FLAGS="\
  214. -DWAMR_BUILD_TARGET=${TARGET} \
  215. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  216. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=1 \
  217. -DWAMR_BUILD_SPEC_TEST=1 \
  218. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  219. readonly FAST_JIT_COMPILE_FLAGS="\
  220. -DWAMR_BUILD_TARGET=${TARGET} \
  221. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  222. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \
  223. -DWAMR_BUILD_FAST_JIT=1 \
  224. -DWAMR_BUILD_SPEC_TEST=1 \
  225. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  226. readonly MULTI_TIER_JIT_COMPILE_FLAGS="\
  227. -DWAMR_BUILD_TARGET=${TARGET} \
  228. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  229. -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
  230. -DWAMR_BUILD_SPEC_TEST=1 \
  231. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  232. readonly COMPILE_FLAGS=(
  233. "${CLASSIC_INTERP_COMPILE_FLAGS}"
  234. "${FAST_INTERP_COMPILE_FLAGS}"
  235. "${ORC_EAGER_JIT_COMPILE_FLAGS}"
  236. "${ORC_LAZY_JIT_COMPILE_FLAGS}"
  237. "${AOT_COMPILE_FLAGS}"
  238. "${FAST_JIT_COMPILE_FLAGS}"
  239. "${MULTI_TIER_JIT_COMPILE_FLAGS}"
  240. )
  241. function unit_test()
  242. {
  243. echo "Now start unit tests"
  244. cd ${WORK_DIR}
  245. rm -fr unittest-build && mkdir unittest-build
  246. cd unittest-build
  247. echo "Build unit test"
  248. touch ${REPORT_DIR}/unit_test_report.txt
  249. cmake ${WORK_DIR}/../../unit -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}
  250. make -j
  251. make test | tee -a ${REPORT_DIR}/unit_test_report.txt
  252. echo "Finish unit tests"
  253. }
  254. function sightglass_test()
  255. {
  256. echo "Now start sightglass benchmark tests"
  257. cd ${WORK_DIR}/../sightglass/benchmarks
  258. # build iwasm first
  259. if [[ $1 == "classic-interp" || $1 == "fast-interp" ]];then
  260. ./test_interp.sh ${SGX_OPT}
  261. cp report.txt ${REPORT_DIR}/sightglass_$1_test_report.txt
  262. fi
  263. if [[ $1 == "aot" ]];then
  264. ./test_aot.sh ${SGX_OPT}
  265. cp report.txt ${REPORT_DIR}/sightglass_aot_test_report.txt
  266. fi
  267. if [[ $1 == "jit" ]];then
  268. [[ $TEST_ALL_AOT_RUNTIME ]] && ./test_aot.sh ${TEST_ALL_AOT_RUNTIME} ${SGX_OPT} \
  269. || ./test_aot.sh jit ${SGX_OPT}
  270. cp report.txt ${REPORT_DIR}/sightglass_jit_test_report.txt
  271. fi
  272. echo "Finish sightglass benchmark tests"
  273. }
  274. # TODO: with iwasm only
  275. function spec_test()
  276. {
  277. echo "Now start spec tests"
  278. touch ${REPORT_DIR}/spec_test_report.txt
  279. cd ${WORK_DIR}
  280. if [ ! -d "spec" ];then
  281. echo "spec not exist, clone it from github"
  282. git clone -b master --single-branch https://github.com/WebAssembly/spec
  283. fi
  284. pushd spec
  285. # restore and clean everything
  286. git reset --hard HEAD
  287. # update basic test cases
  288. echo "update spec test cases"
  289. git fetch origin main
  290. # restore from XX_ignore_cases.patch
  291. # resotre branch
  292. git checkout -B main
  293. # [spec] Update note on module initialization trapping (#1493)
  294. git reset --hard 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b
  295. git apply ../../spec-test-script/ignore_cases.patch
  296. if [[ ${ENABLE_SIMD} == 1 ]]; then
  297. git apply ../../spec-test-script/simd_ignore_cases.patch
  298. fi
  299. # udpate thread cases
  300. if [ ${ENABLE_MULTI_THREAD} == 1 ]; then
  301. echo "checkout spec for threads proposal"
  302. if [[ -z $(git remote -v | grep "\<threads\>") ]]; then
  303. git remote add threads https://github.com/WebAssembly/threads
  304. fi
  305. # fetch spec for threads proposal
  306. git fetch threads
  307. # Fix error in Web embedding desc for atomic.notify (#185)
  308. git reset --hard 85b562cd6805947876ec5e8b975ab0127c55a0a2
  309. git checkout threads/main
  310. git apply ../../spec-test-script/thread_proposal_ignore_cases.patch
  311. git apply ../../spec-test-script/thread_proposal_fix_atomic_case.patch
  312. fi
  313. # update GC cases
  314. if [[ ${ENABLE_GC} == 1 ]]; then
  315. echo "checkout spec for GC proposal"
  316. popd
  317. rm -fr spec
  318. # check spec test cases for GC
  319. git clone -b main --single-branch https://github.com/WebAssembly/gc.git spec
  320. pushd spec
  321. git restore . && git clean -ffd .
  322. # Sync constant expression descriptions
  323. git reset --hard 62beb94ddd41987517781732f17f213d8b866dcc
  324. git apply ../../spec-test-script/gc_ignore_cases.patch
  325. echo "compile the reference intepreter"
  326. pushd interpreter
  327. make opt
  328. popd
  329. fi
  330. popd
  331. echo $(pwd)
  332. if [ ${WABT_BINARY_RELEASE} == "YES" ]; then
  333. echo "download a binary release and install"
  334. local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
  335. if [ ! -f ${WAT2WASM} ]; then
  336. case ${PLATFORM} in
  337. linux)
  338. WABT_PLATFORM=ubuntu
  339. ;;
  340. darwin)
  341. WABT_PLATFORM=macos
  342. ;;
  343. *)
  344. echo "wabt platform for ${PLATFORM} in unknown"
  345. exit 1
  346. ;;
  347. esac
  348. if [ ! -f /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz ]; then
  349. wget \
  350. https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
  351. -P /tmp
  352. fi
  353. cd /tmp \
  354. && tar zxf wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
  355. && mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \
  356. && install wabt-1.0.31/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \
  357. && cd -
  358. fi
  359. else
  360. echo "download source code and compile and install"
  361. if [ ! -d "wabt" ];then
  362. echo "wabt not exist, clone it from github"
  363. git clone --recursive https://github.com/WebAssembly/wabt
  364. fi
  365. echo "upate wabt"
  366. cd wabt
  367. git pull
  368. git reset --hard origin/main
  369. cd ..
  370. make -C wabt gcc-release -j 4
  371. fi
  372. ln -sf ${WORK_DIR}/../spec-test-script/all.py .
  373. ln -sf ${WORK_DIR}/../spec-test-script/runtest.py .
  374. local ARGS_FOR_SPEC_TEST=""
  375. # multi-module only enable in interp mode
  376. if [[ 1 == ${ENABLE_MULTI_MODULE} ]]; then
  377. if [[ $1 == 'classic-interp' || $1 == 'fast-interp' ]]; then
  378. ARGS_FOR_SPEC_TEST+="-M "
  379. fi
  380. fi
  381. # sgx only enable in interp mode and aot mode
  382. if [[ ${SGX_OPT} == "--sgx" ]];then
  383. if [[ $1 == 'classic-interp' || $1 == 'fast-interp' || $1 == 'aot' ]]; then
  384. ARGS_FOR_SPEC_TEST+="-x "
  385. fi
  386. fi
  387. # simd only enable in jit mode and aot mode
  388. if [[ ${ENABLE_SIMD} == 1 ]]; then
  389. if [[ $1 == 'jit' || $1 == 'aot' ]]; then
  390. ARGS_FOR_SPEC_TEST+="-S "
  391. fi
  392. fi
  393. if [[ ${ENABLE_MULTI_THREAD} == 1 ]]; then
  394. ARGS_FOR_SPEC_TEST+="-p "
  395. if [[ $1 == 'fast-jit' ]]; then
  396. echo "fast-jit doesn't support multi-thread feature yet, skip it"
  397. return
  398. fi
  399. if [[ $1 == 'multi-tier-jit' ]]; then
  400. echo "multi-tier-jit doesn't support multi-thread feature yet, skip it"
  401. return
  402. fi
  403. fi
  404. if [[ ${ENABLE_XIP} == 1 ]]; then
  405. ARGS_FOR_SPEC_TEST+="-X "
  406. fi
  407. # set the current running target
  408. ARGS_FOR_SPEC_TEST+="-m ${TARGET} "
  409. # require warmc only in aot mode
  410. if [[ $1 == 'aot' ]]; then
  411. ARGS_FOR_SPEC_TEST+="-t "
  412. fi
  413. if [[ ${PARALLELISM} == 1 ]]; then
  414. ARGS_FOR_SPEC_TEST+="--parl "
  415. fi
  416. if [[ ${ENABLE_GC} == 1 ]]; then
  417. ARGS_FOR_SPEC_TEST+="--gc "
  418. fi
  419. if [[ ${ENABLE_QEMU} == 1 ]]; then
  420. ARGS_FOR_SPEC_TEST+="--qemu "
  421. ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
  422. fi
  423. # set log directory
  424. ARGS_FOR_SPEC_TEST+="--log ${REPORT_DIR}"
  425. cd ${WORK_DIR}
  426. echo "python3 ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt"
  427. python3 ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt
  428. if [[ ${PIPESTATUS[0]} -ne 0 ]];then
  429. echo -e "\nspec tests FAILED" | tee -a ${REPORT_DIR}/spec_test_report.txt
  430. exit 1
  431. fi
  432. cd -
  433. echo -e "\nFinish spec tests" | tee -a ${REPORT_DIR}/spec_test_report.txt
  434. }
  435. function wasi_test()
  436. {
  437. echo "Now start wasi tests"
  438. touch ${REPORT_DIR}/wasi_test_report.txt
  439. cd ${WORK_DIR}/../../wasi
  440. [[ $1 != "aot" ]] && \
  441. python wasi_test.py --interpreter ${IWASM_CMD} ${SGX_OPT}\
  442. | tee ${REPORT_DIR}/wasi_test_report.txt \
  443. || \
  444. python wasi_test.py --aot --aot-compiler ${WAMRC_CMD} ${SGX_OPT}\
  445. --interpreter ${IWASM_CMD} \
  446. | tee ${REPORT_DIR}/wasi_test_report.txt
  447. echo "Finish wasi tests"
  448. }
  449. function wasi_certification_test()
  450. {
  451. echo "Now start wasi certification tests"
  452. cd ${WORK_DIR}
  453. if [ ! -d "wasi-testsuite" ]; then
  454. echo "wasi not exist, clone it from github"
  455. git clone -b prod/testsuite-all \
  456. --single-branch https://github.com/WebAssembly/wasi-testsuite.git
  457. fi
  458. cd wasi-testsuite
  459. git reset --hard ${WASI_TESTSUITE_COMMIT}
  460. bash ../../wasi-test-script/run_wasi_tests.sh $1 $TARGET \
  461. | tee -a ${REPORT_DIR}/wasi_test_report.txt
  462. ret=${PIPESTATUS[0]}
  463. if [[ ${ret} -ne 0 ]];then
  464. echo -e "\nwasi tests FAILED" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  465. exit 1
  466. fi
  467. echo -e "\nFinish wasi tests" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  468. }
  469. function polybench_test()
  470. {
  471. echo "Now start polybench tests"
  472. cd ${WORK_DIR}/../polybench
  473. if [[ $1 == "aot" || $1 == "jit" ]];then
  474. ./build.sh AOT ${SGX_OPT}
  475. ./test_aot.sh $1 ${SGX_OPT}
  476. else
  477. ./build.sh
  478. ./test_interp.sh ${SGX_OPT}
  479. fi
  480. cp report.txt ${REPORT_DIR}/polybench_$1_test_report.txt
  481. echo "Finish polybench tests"
  482. }
  483. function libsodium_test()
  484. {
  485. echo "Now start libsodium tests"
  486. cd ${WORK_DIR}/../libsodium
  487. if [[ $1 == "aot" || $1 == "jit" ]];then
  488. ./build.sh ${SGX_OPT}
  489. ./test_aot.sh $1 ${SGX_OPT}
  490. else
  491. ./test_interp.sh ${SGX_OPT}
  492. fi
  493. cp report.txt ${REPORT_DIR}/libsodium_$1_test_report.txt
  494. echo "Finish libsodium tests"
  495. }
  496. function malformed_test()
  497. {
  498. # build iwasm firstly
  499. cd ${WORK_DIR}/../../malformed
  500. ./malformed_test.py --run ${IWASM_CMD} | tee ${REPORT_DIR}/malfomed_$1_test_report.txt
  501. }
  502. function collect_standalone()
  503. {
  504. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  505. pushd ${WORK_DIR} > /dev/null 2>&1
  506. CODE_COV_FILE=""
  507. if [[ -z "${CODE_COV_FILE}" ]]; then
  508. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  509. else
  510. CODE_COV_FILE="${CODE_COV_FILE}"
  511. fi
  512. STANDALONE_DIR=${WORK_DIR}/../../standalone
  513. echo "Collect code coverage of standalone dump-call-stack"
  514. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-call-stack/build"
  515. echo "Collect code coverage of standalone dump-mem-profiling"
  516. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-mem-profiling/build"
  517. echo "Collect code coverage of standalone dump-perf-profiling"
  518. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-perf-profiling/build"
  519. if [[ $1 == "aot" ]]; then
  520. echo "Collect code coverage of standalone pad-test"
  521. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/pad-test/build"
  522. fi
  523. echo "Collect code coverage of standalone test-invoke-native"
  524. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-invoke-native/build"
  525. echo "Collect code coverage of standalone test-running-modes"
  526. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/build"
  527. echo "Collect code coverage of standalone test-running-modes/c-embed"
  528. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/c-embed/build"
  529. echo "Collect code coverage of standalone test-ts2"
  530. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-ts2/build"
  531. popd > /dev/null 2>&1
  532. fi
  533. }
  534. function standalone_test()
  535. {
  536. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  537. export COLLECT_CODE_COVERAGE=1
  538. fi
  539. cd ${WORK_DIR}/../../standalone
  540. args="--$1"
  541. [[ ${SGX_OPT} == "--sgx" ]] && args="$args --sgx" || args="$args --no-sgx"
  542. [[ ${ENABLE_MULTI_THREAD} == 1 ]] && args="$args --thread" || args="$args --no-thread"
  543. [[ ${ENABLE_SIMD} == 1 ]] && args="$args --simd" || args="$args --no-simd"
  544. args="$args ${TARGET}"
  545. ./standalone.sh $args | tee ${REPORT_DIR}/standalone_$1_test_report.txt
  546. collect_standalone "$1"
  547. }
  548. function build_iwasm_with_cfg()
  549. {
  550. echo "Build iwasm with compile flags with " $* " for spec test" \
  551. | tee -a ${REPORT_DIR}/spec_test_report.txt
  552. if [[ ${SGX_OPT} == "--sgx" ]];then
  553. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx \
  554. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  555. && cd build \
  556. && cmake $* .. \
  557. && make -j 4
  558. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx/enclave-sample \
  559. && make clean \
  560. && make SPEC_TEST=1
  561. else
  562. cd ${WAMR_DIR}/product-mini/platforms/${PLATFORM} \
  563. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  564. && cd build \
  565. && cmake $* .. \
  566. && make -j 4
  567. fi
  568. if [ "$?" != 0 ];then
  569. echo -e "build iwasm failed"
  570. exit 1
  571. fi
  572. }
  573. function build_wamrc()
  574. {
  575. if [[ $TARGET == "ARMV7_VFP" || $TARGET == "THUMBV7_VFP"
  576. || $TARGET == "RISCV32" || $TARGET == "RISCV32_ILP32" || $TARGET == "RISCV32_ILP32D"
  577. || $TARGET == "RISCV64" || $TARGET == "RISCV64_LP64D" || $TARGET == "RISCV64_LP64" ]];then
  578. echo "suppose wamrc is already built"
  579. return
  580. fi
  581. echo "Build wamrc for spec test under aot compile type"
  582. cd ${WAMR_DIR}/wamr-compiler \
  583. && ./build_llvm.sh \
  584. && if [ -d build ]; then rm -r build/*; else mkdir build; fi \
  585. && cd build \
  586. && cmake .. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
  587. && make -j 4
  588. }
  589. ### Need to add a test suite?
  590. ### The function name should be ${suite_name}_test
  591. # function xxx_test()
  592. # {
  593. #
  594. # }
  595. function collect_coverage()
  596. {
  597. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  598. ln -sf ${WORK_DIR}/../spec-test-script/collect_coverage.sh ${WORK_DIR}
  599. CODE_COV_FILE=""
  600. if [[ -z "${CODE_COV_FILE}" ]]; then
  601. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  602. else
  603. CODE_COV_FILE="${CODE_COV_FILE}"
  604. fi
  605. pushd ${WORK_DIR} > /dev/null 2>&1
  606. echo "Collect code coverage of iwasm"
  607. ./collect_coverage.sh ${CODE_COV_FILE} ${IWASM_LINUX_ROOT_DIR}/build
  608. if [[ $1 == "llvm-aot" ]]; then
  609. echo "Collect code coverage of wamrc"
  610. ./collect_coverage.sh ${CODE_COV_FILE} ${WAMR_DIR}/wamr-compiler/build
  611. fi
  612. for suite in "${TEST_CASE_ARR[@]}"; do
  613. if [[ ${suite} = "unit" ]]; then
  614. echo "Collect code coverage of unit test"
  615. ./collect_coverage.sh ${CODE_COV_FILE} ${WORK_DIR}/unittest-build
  616. break
  617. fi
  618. done
  619. popd > /dev/null 2>&1
  620. else
  621. echo "code coverage isn't collected"
  622. fi
  623. }
  624. function trigger()
  625. {
  626. local EXTRA_COMPILE_FLAGS=""
  627. # default enabled features
  628. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  629. if [[ ${ENABLE_MULTI_MODULE} == 1 ]];then
  630. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=1"
  631. else
  632. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=0"
  633. fi
  634. if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
  635. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
  636. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=0"
  637. else
  638. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
  639. fi
  640. if [[ ${ENABLE_SIMD} == 1 ]]; then
  641. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=1"
  642. else
  643. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=0"
  644. fi
  645. if [[ ${ENABLE_GC} == 1 ]]; then
  646. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC=1"
  647. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
  648. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  649. fi
  650. if [[ ${ENABLE_DEBUG_VERSION} == 1 ]]; then
  651. EXTRA_COMPILE_FLAGS+=" -DCMAKE_BUILD_TYPE=Debug"
  652. fi
  653. if [[ ${ENABLE_GC_HEAP_VERIFY} == 1 ]]; then
  654. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC_HEAP_VERIFY=1"
  655. fi
  656. if [[ ${ENABLE_WASI_THREADS} == 1 ]]; then
  657. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_WASI_THREADS=1"
  658. fi
  659. for t in "${TYPE[@]}"; do
  660. case $t in
  661. "classic-interp")
  662. if [[ ${ENABLE_SIMD} == 1 ]]; then
  663. echo "does not support SIMD in interp mode, bypass"
  664. continue
  665. fi
  666. echo "work in classic-interp mode"
  667. # classic-interp
  668. BUILD_FLAGS="$CLASSIC_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  669. if [[ ${ENABLE_QEMU} == 0 ]]; then
  670. build_iwasm_with_cfg $BUILD_FLAGS
  671. fi
  672. for suite in "${TEST_CASE_ARR[@]}"; do
  673. $suite"_test" classic-interp
  674. done
  675. collect_coverage classic-interp
  676. ;;
  677. "fast-interp")
  678. if [[ ${ENABLE_SIMD} == 1 ]]; then
  679. echo "does not support SIMD in interp mode, bypass"
  680. continue
  681. fi
  682. echo "work in fast-interp mode"
  683. # fast-interp
  684. BUILD_FLAGS="$FAST_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  685. if [[ ${ENABLE_QEMU} == 0 ]]; then
  686. build_iwasm_with_cfg $BUILD_FLAGS
  687. fi
  688. for suite in "${TEST_CASE_ARR[@]}"; do
  689. $suite"_test" fast-interp
  690. done
  691. collect_coverage fast-interp
  692. ;;
  693. "jit")
  694. if [[ ${TARGET} == "X86_32" ]]; then
  695. echo "does not support an X86_32 target in JIT mode, bypass"
  696. continue
  697. fi
  698. echo "work in orc jit eager compilation mode"
  699. BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  700. build_iwasm_with_cfg $BUILD_FLAGS
  701. for suite in "${TEST_CASE_ARR[@]}"; do
  702. $suite"_test" jit
  703. done
  704. collect_coverage llvm-jit
  705. echo "work in orc jit lazy compilation mode"
  706. BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  707. build_iwasm_with_cfg $BUILD_FLAGS
  708. for suite in "${TEST_CASE_ARR[@]}"; do
  709. $suite"_test" jit
  710. done
  711. collect_coverage llvm-jit
  712. ;;
  713. "aot")
  714. echo "work in aot mode"
  715. # aot
  716. BUILD_FLAGS="$AOT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  717. if [[ ${ENABLE_QEMU} == 0 ]]; then
  718. build_iwasm_with_cfg $BUILD_FLAGS
  719. fi
  720. build_wamrc
  721. for suite in "${TEST_CASE_ARR[@]}"; do
  722. $suite"_test" aot
  723. done
  724. collect_coverage llvm-aot
  725. ;;
  726. "fast-jit")
  727. echo "work in fast-jit mode"
  728. # fast-jit
  729. BUILD_FLAGS="$FAST_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  730. build_iwasm_with_cfg $BUILD_FLAGS
  731. for suite in "${TEST_CASE_ARR[@]}"; do
  732. $suite"_test" fast-jit
  733. done
  734. collect_coverage fast-jit
  735. ;;
  736. "multi-tier-jit")
  737. echo "work in multi-tier-jit mode"
  738. # multi-tier-jit
  739. BUILD_FLAGS="$MULTI_TIER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  740. build_iwasm_with_cfg $BUILD_FLAGS
  741. for suite in "${TEST_CASE_ARR[@]}"; do
  742. $suite"_test" multi-tier-jit
  743. done
  744. collect_coverage multi-tier-jit
  745. ;;
  746. *)
  747. echo "unexpected mode, do nothing"
  748. ;;
  749. esac
  750. done
  751. }
  752. # if collect code coverage, ignore -s, test all test cases.
  753. if [[ $TEST_CASE_ARR ]];then
  754. trigger || (echo "TEST FAILED"; exit 1)
  755. else
  756. # test all suite, ignore polybench and libsodium because of long time cost
  757. TEST_CASE_ARR=("spec")
  758. : '
  759. if [[ $COLLECT_CODE_COVERAGE == 1 ]];then
  760. # add polybench if collecting code coverage data
  761. TEST_CASE_ARR+=("polybench")
  762. # add libsodium if needed, which takes long time to run
  763. TEST_CASE_ARR+=("libsodium")
  764. fi
  765. '
  766. trigger || (echo "TEST FAILED"; exit 1)
  767. # Add more suites here
  768. fi
  769. echo -e "Test finish. Reports are under ${REPORT_DIR}"
  770. DEBUG set +xv pipefail
  771. echo "TEST SUCCESSFUL"
  772. exit 0