test_wamr.sh 40 KB

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