test_wamr.sh 40 KB

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