test_wamr.sh 33 KB

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