test_wamr.sh 38 KB

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