Merge branch main into dev/wasi-libc-windows

This commit is contained in:
Wenyong Huang
2023-10-08 15:03:35 +08:00
151 changed files with 5909 additions and 2046 deletions

View File

@ -1,6 +1,18 @@
diff -urN tsf-src-org/gpc_code_gen_util.c tsf-src/gpc_code_gen_util.c
--- tsf-src-org/gpc_code_gen_util.c 2023-09-21 11:12:40.211166472 +0800
+++ tsf-src/gpc_code_gen_util.c 2023-09-21 11:09:13.643170967 +0800
@@ -34,6 +34,8 @@
#include <errno.h>
#include <dirent.h>
+int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
+
/* code generation debugging */
/* NOTE: It is now the case that the count may be incremented multiple times,
diff -urN tsf-src-org/tsf_internal.h tsf-src/tsf_internal.h
--- tsf-src-org/tsf_internal.h 2023-03-31 10:49:45.000000000 +0800
+++ tsf-src/tsf_internal.h 2023-05-11 08:18:35.000000000 +0800
--- tsf-src-org/tsf_internal.h 2023-09-21 11:11:50.843167546 +0800
+++ tsf-src/tsf_internal.h 2023-09-21 11:06:53.031174027 +0800
@@ -429,6 +429,7 @@
#endif
tsf_fsdb_connection_t *connection;
@ -10,15 +22,15 @@ diff -urN tsf-src-org/tsf_internal.h tsf-src/tsf_internal.h
} u;
tsf_limits_t *limits;
diff -urN tsf-src-org/tsf_ir_speed.c tsf-src/tsf_ir_speed.c
--- tsf-src-org/tsf_ir_speed.c 2023-03-31 10:49:45.000000000 +0800
+++ tsf-src/tsf_ir_speed.c 2023-05-11 08:18:35.000000000 +0800
--- tsf-src-org/tsf_ir_speed.c 2023-09-21 11:12:15.699167005 +0800
+++ tsf-src/tsf_ir_speed.c 2023-09-21 11:06:53.031174027 +0800
@@ -63,6 +63,9 @@
Program_t *program;
unsigned elementIndex;
+ if (!(programIndex % 100))
+ printf("##programIndex: %u\n", programIndex);
+
CS(program = tsf_region_create(sizeof(Program_t)));
program->globals.len = numDecls + numDefns;

51
tests/unit/CMakeLists.txt Normal file
View File

@ -0,0 +1,51 @@
# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.14)
project (wamr_unit_tests)
include (CTest)
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
if (NOT DEFINED WAMR_BUILD_PLATFORM)
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
include (FetchContent)
FetchContent_Declare (
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable (googletest)
include (GoogleTest)
add_library (wamr_gtest_main main.cpp)
target_link_libraries (wamr_gtest_main PUBLIC gtest vmlib)
function (create_wamr_unit_test test_name)
set (sources ${ARGN})
add_executable (${test_name} ${sources})
target_link_libraries (
${test_name}
wamr_gtest_main
vmlib
${LLVM_AVAILABLE_LIBS}
)
gtest_discover_tests (${test_name})
endfunction ()
if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1)
include (${IWASM_DIR}/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake)
endif ()

21
tests/unit/main.cpp Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <gtest/gtest.h>
#include "wasm_runtime_common.h"
int
main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
if (!wasm_runtime_init()) {
return -1;
}
int ret = RUN_ALL_TESTS();
wasm_runtime_destroy();
return ret;
}

2
tests/wamr-compiler/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.aot
*.wasm

View File

@ -0,0 +1,3 @@
# WAMR test benchmarks
This folder contains tests for WAMR AOT compiler and its generated code.

View File

@ -0,0 +1,43 @@
;; Copyright (C) 2023 Amazon Inc. All rights reserved.
;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
;;
;; Those tests verify if passing constant negative value
;; as a right parameter of the shift operator (along
;; with a constant value of the left operator) causes
;; any problems. See: https://github.com/bytecodealliance/wasm-micro-runtime/pull/2619
(module
(memory (export "memory") 1 1)
(func $assert_eq (param i32 i32)
(i32.ne (local.get 0) (local.get 1))
if
unreachable
end
)
(func $i32_shr_u
(call $assert_eq
(i32.shr_u (i32.const -1) (i32.const -5))
(i32.const 31)
)
)
(func $i32_shr_s
(call $assert_eq
(i32.shr_u (i32.const 32) (i32.const -30))
(i32.const 8)
)
)
(func $i32_shl
(call $assert_eq
(i32.shl (i32.const -1) (i32.const -30))
(i32.const -4)
)
)
(func (export "_start")
call $i32_shr_u
call $i32_shr_s
call $i32_shl
)
)

View File

@ -51,6 +51,7 @@ WAST2WASM_CMD = exe_file_path("./wabt/out/gcc/Release/wat2wasm")
SPEC_INTERPRETER_CMD = "spec/interpreter/wasm"
WAMRC_CMD = "../../../wamr-compiler/build/wamrc"
class TargetAction(argparse.Action):
TARGET_MAP = {
"ARMV7_VFP": "armv7",
@ -63,6 +64,7 @@ class TargetAction(argparse.Action):
"THUMBV7_VFP": "thumbv7",
"X86_32": "i386",
"X86_64": "x86_64",
"AARCH64": "arm64"
}
def __call__(self, parser, namespace, values, option_string=None):
@ -79,7 +81,7 @@ def ignore_the_case(
simd_flag=False,
gc_flag=False,
xip_flag=False,
qemu_flag=False
qemu_flag=False,
):
if case_name in ["comments", "inline-module", "names"]:
return True
@ -93,7 +95,7 @@ def ignore_the_case(
if gc_flag:
if case_name in ["type-canon", "type-equivalence", "type-rec"]:
return True;
return True
if sgx_flag:
if case_name in ["conversions", "f32_bitwise", "f64_bitwise"]:
@ -108,9 +110,20 @@ def ignore_the_case(
return True
if qemu_flag:
if case_name in ["f32_bitwise", "f64_bitwise", "loop", "f64", "f64_cmp",
"conversions", "f32", "f32_cmp", "float_exprs",
"float_misc", "select", "memory_grow"]:
if case_name in [
"f32_bitwise",
"f64_bitwise",
"loop",
"f64",
"f64_cmp",
"conversions",
"f32",
"f32_cmp",
"float_exprs",
"float_misc",
"select",
"memory_grow",
]:
return True
return False
@ -145,27 +158,10 @@ def test_case(
verbose_flag=True,
gc_flag=False,
qemu_flag=False,
qemu_firmware='',
log='',
qemu_firmware="",
log="",
no_pty=False
):
case_path = pathlib.Path(case_path).resolve()
case_name = case_path.stem
if ignore_the_case(
case_name,
target,
aot_flag,
sgx_flag,
multi_module_flag,
multi_thread_flag,
simd_flag,
gc_flag,
xip_flag,
qemu_flag
):
return True
CMD = [sys.executable, "runtest.py"]
CMD.append("--wast2wasm")
CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD)
@ -213,11 +209,15 @@ def test_case(
if gc_flag:
CMD.append("--gc")
if log != '':
if log != "":
CMD.append("--log-dir")
CMD.append(log)
CMD.append(case_path)
case_path = pathlib.Path(case_path).resolve()
case_name = case_path.stem
CMD.append(str(case_path))
# print(f"============> use {' '.join(CMD)}")
print(f"============> run {case_name} ", end="")
with subprocess.Popen(
CMD,
@ -276,9 +276,9 @@ def test_suite(
gc_flag=False,
parl_flag=False,
qemu_flag=False,
qemu_firmware='',
log='',
no_pty=False
qemu_firmware="",
log="",
no_pty=False,
):
suite_path = pathlib.Path(SPEC_TEST_DIR).resolve()
if not suite_path.exists():
@ -294,6 +294,26 @@ def test_suite(
gc_case_list = sorted(suite_path.glob("gc/*.wast"))
case_list.extend(gc_case_list)
# ignore based on command line options
filtered_case_list = []
for case_path in case_list:
case_name = case_path.stem
if not ignore_the_case(
case_name,
target,
aot_flag,
sgx_flag,
multi_module_flag,
multi_thread_flag,
simd_flag,
gc_flag,
xip_flag,
qemu_flag,
):
filtered_case_list.append(case_path)
print(f"---> {len(case_list)} --filter--> {len(filtered_case_list)}")
case_list = filtered_case_list
case_count = len(case_list)
failed_case = 0
successful_case = 0
@ -455,7 +475,7 @@ def main():
)
parser.add_argument(
"--log",
default='',
default="",
dest="log",
help="Log directory",
)
@ -484,7 +504,6 @@ def main():
help="Use direct pipes instead of pseudo-tty")
options = parser.parse_args()
print(options)
if not preflight_check(options.aot_flag):
return False
@ -536,7 +555,7 @@ def main():
options.qemu_flag,
options.qemu_firmware,
options.log,
options.no_pty
options.no_pty,
)
else:
ret = True

View File

@ -0,0 +1,174 @@
diff --git a/test/core/linking.wast b/test/core/linking.wast
index d0bfb5f..6617945 100644
--- a/test/core/linking.wast
+++ b/test/core/linking.wast
@@ -35,7 +35,7 @@
;; Globals
-
+(;
(module $Mg
(global $glob (export "glob") i32 (i32.const 42))
(func (export "get") (result i32) (global.get $glob))
@@ -63,7 +63,7 @@
(export "Mg.get_mut" (func $get_mut))
(export "Mg.set_mut" (func $set_mut))
)
-
+;)
(;
(assert_return (get $Mg "glob") (i32.const 42))
(assert_return (get $Ng "Mg.glob") (i32.const 42))
@@ -84,7 +84,7 @@
(assert_return (invoke $Ng "Mg.get_mut") (i32.const 241))
;)
-
+(;
(assert_unlinkable
(module (import "Mg" "mut_glob" (global i32)))
"incompatible import type"
@@ -166,7 +166,7 @@
(call_indirect (type 1) (local.get 0))
)
)
-
+;)
(;
(assert_return (invoke $Mt "call" (i32.const 2)) (i32.const 4))
(assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const 4))
@@ -191,7 +191,7 @@
(assert_return (invoke $Nt "call" (i32.const 3)) (i32.const -4))
(assert_trap (invoke $Nt "call" (i32.const 4)) "indirect call type mismatch")
;)
-
+(;
(module $Ot
(type (func (result i32)))
@@ -204,7 +204,7 @@
(call_indirect (type 0) (local.get 0))
)
)
-
+;)
(;
(assert_return (invoke $Mt "call" (i32.const 3)) (i32.const 4))
(assert_return (invoke $Nt "Mt.call" (i32.const 3)) (i32.const 4))
@@ -231,7 +231,7 @@
(assert_trap (invoke $Ot "call" (i32.const 20)) "undefined element")
;)
-
+(;
(module
(table (import "Mt" "tab") 0 funcref)
(elem (i32.const 9) $f)
@@ -266,7 +266,7 @@
"unknown import"
)
(assert_trap (invoke $Mt "call" (i32.const 7)) "uninitialized element")
-
+;)
;; Unlike in the v1 spec, active element segments stored before an
;; out-of-bounds access persist after the instantiation failure.
(;
@@ -297,7 +297,7 @@
(assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0))
;)
-
+(;
(module $Mtable_ex
(table $t1 (export "t-func") 1 funcref)
(table $t2 (export "t-extern") 1 externref)
@@ -308,7 +308,7 @@
(table (import "Mtable_ex" "t-func") 1 funcref)
(table (import "Mtable_ex" "t-extern") 1 externref)
)
-
+;)
(;
(assert_unlinkable
(module (table (import "Mtable_ex" "t-func") 1 externref))
@@ -322,7 +322,7 @@
;; Memories
-
+(;
(module $Mm
(memory (export "mem") 1 5)
(data (i32.const 10) "\00\01\02\03\04\05\06\07\08\09")
@@ -357,14 +357,14 @@
(i32.load8_u (local.get 0))
)
)
-
+;)
(;
(assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7))
(assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7))
(assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2))
(assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7))
;)
-
+(;
(module
(memory (import "Mm" "mem") 0)
(data (i32.const 0xffff) "a")
@@ -385,7 +385,7 @@
(memory.grow (local.get 0))
)
)
-
+;)
(;
(assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1))
(assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1))
@@ -396,7 +396,7 @@
(assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1))
(assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5))
;)
-
+(;
(assert_unlinkable
(module
(func $host (import "spectest" "print"))
@@ -419,11 +419,12 @@
)
"out of bounds memory access"
)
+;)
(;
(assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97))
(assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0))
;)
-
+(;
(assert_trap
(module
(memory (import "Mm" "mem") 1)
@@ -434,10 +435,11 @@
)
"out of bounds table access"
)
+;)
(;
(assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97))
;)
-
+(;
;; Store is modified if the start function traps.
(module $Ms
(type $t (func (result i32)))
@@ -451,7 +453,7 @@
)
)
(register "Ms" $Ms)
-
+;)
(;
(assert_trap
(module

View File

@ -456,7 +456,7 @@ def cast_v128_to_i64x2(numbers, type, lane_type):
assert(packed)
unpacked = struct.unpack("Q Q", packed)
return unpacked, "[{} {}]:{}:v128".format(unpacked[0], unpacked[1], lane_type)
return unpacked, f"[{unpacked[0]:#x} {unpacked[1]:#x}]:{lane_type}:v128"
def parse_simple_const_w_type(number, type):
number = number.replace('_', '')
@ -468,13 +468,7 @@ def parse_simple_const_w_type(number, type):
else "-0x{:x}:{}".format(0 - number, type)
elif type in ["f32", "f64"]:
if "nan:" in number:
# TODO: how to handle this correctly
if "nan:canonical" in number:
return float.fromhex("0x200000"), "nan:{}".format(type)
elif "nan:arithmetic" in number:
return float.fromhex("-0x200000"), "nan:{}".format(type)
else:
return float('nan'), "nan:{}".format(type)
return float('nan'), "nan:{}".format(type)
else:
number = float.fromhex(number) if '0x' in number else float(number)
return number, "{:.7g}:{}".format(number, type)
@ -598,9 +592,6 @@ def vector_value_comparison(out, expected):
if out_type != expected_type:
return False
if out_val == expected_val:
return True
out_val = out_val.split(" ")
expected_val = expected_val.split(" ")
@ -624,12 +615,14 @@ def vector_value_comparison(out, expected):
out_is_nan = [math.isnan(o) for o in out_unpacked]
expected_is_nan = [math.isnan(e) for e in expected_unpacked]
if out_is_nan and expected_is_nan:
return True;
if any(out_is_nan):
nan_comparision = [o == e for o, e in zip(out_is_nan, expected_is_nan)]
if all(nan_comparision):
print(f"Pass NaN comparision")
return True
# print("compare {} and {}".format(out_unpacked, expected_unpacked))
# print(f"compare {out_unpacked} and {expected_unpacked}")
result = [o == e for o, e in zip(out_unpacked, expected_unpacked)]
if not all(result):
result = [
"{:.7g}".format(o) == "{:.7g}".format(e)
@ -834,7 +827,7 @@ def test_assert_return(r, opts, form):
numbers, _ = cast_v128_to_i64x2(splitted[2:], 'v128', splitted[1])
assert(len(numbers) == 2), "has to reform arguments into i64x2"
args.append("{}\{}".format(numbers[0], numbers[1]))
args.append(f"{numbers[0]:#x}\{numbers[1]:#x}")
elif "ref.null" == splitted[0]:
args.append("null")
elif "ref.extern" == splitted[0]:
@ -1183,7 +1176,7 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile,
if __name__ == "__main__":
opts = parser.parse_args(sys.argv[1:])
print('Input param :',opts)
# print('Input param :',opts)
if opts.aot: test_aot = True
# default x86_64
@ -1206,7 +1199,7 @@ if __name__ == "__main__":
ret_code = 0
try:
log("################################################")
log("\n################################################")
log("### Testing %s" % opts.test_file.name)
log("################################################")
forms = read_forms(opts.test_file.read())
@ -1352,6 +1345,16 @@ if __name__ == "__main__":
# add new_module copied from the old into temp_file_repo[]
temp_file_repo.append(new_module)
if test_aot:
new_module_aot = os.path.join(tempfile.gettempdir(), name_new + ".aot")
r = compile_wasm_to_aot(new_module, new_module_aot, True, opts, r)
try:
assert_prompt(r, ['Compile success'], opts.start_timeout, True)
except:
raise Exception("compile wasm to aot failed")
# add aot module into temp_file_repo[]
temp_file_repo.append(new_module_aot)
else:
# there is no name defined in register cmd
raise Exception("can not find module name from the register")
@ -1394,3 +1397,4 @@ if __name__ == "__main__":
log("Leaving tempfiles: %s" % ([wast_tempfile, wasm_tempfile]))
sys.exit(ret_code)

View File

@ -14,8 +14,8 @@ function help()
{
echo "test_wamr.sh [options]"
echo "-c clean previous test results, not start test"
echo "-s {suite_name} test only one suite (spec|wasi_certification)"
echo "-m set compile target of iwasm(x86_64|x86_32|armv7_vfp|thumbv7_vfp|riscv64_lp64d|riscv64_lp64)"
echo "-s {suite_name} test only one suite (spec|wasi_certification|wamr_compiler)"
echo "-m set compile target of iwasm(x86_64|x86_32|armv7_vfp|thumbv7_vfp|riscv64_lp64d|riscv64_lp64|aarch64)"
echo "-t set compile type of iwasm(classic-interp|fast-interp|jit|aot|fast-jit|multi-tier-jit)"
echo "-M enable multi module feature"
echo "-p enable multi thread feature"
@ -31,6 +31,7 @@ function help()
echo "-Q enable qemu"
echo "-F set the firmware path used by qemu"
echo "-C enable code coverage collect"
echo "-j set the platform to test"
}
OPT_PARSED=""
@ -61,9 +62,10 @@ fi
PARALLELISM=0
ENABLE_QEMU=0
QEMU_FIRMWARE=""
WASI_TESTSUITE_COMMIT="aca78d919355ae00af141e6741a439039615b257"
# prod/testsuite-all branch
WASI_TESTSUITE_COMMIT="ee807fc551978490bf1c277059aabfa1e589a6c2"
while getopts ":s:cabgvt:m:MCpSXxwPGQF:" opt
while getopts ":s:cabgvt:m:MCpSXxwPGQF:j:" opt
do
OPT_PARSED="TRUE"
case $opt in
@ -165,6 +167,10 @@ do
echo "QEMU firmware" ${OPTARG}
QEMU_FIRMWARE=${OPTARG}
;;
j)
echo "test platform " ${OPTARG}
PLATFORM=${OPTARG}
;;
?)
help
exit 1;;
@ -309,6 +315,56 @@ function sightglass_test()
echo "Finish sightglass benchmark tests"
}
function setup_wabt()
{
if [ ${WABT_BINARY_RELEASE} == "YES" ]; then
echo "download a binary release and install"
local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
if [ ! -f ${WAT2WASM} ]; then
case ${PLATFORM} in
cosmopolitan)
;&
linux)
WABT_PLATFORM=ubuntu
;;
darwin)
WABT_PLATFORM=macos
;;
windows)
WABT_PLATFORM=windows
;;
*)
echo "wabt platform for ${PLATFORM} in unknown"
exit 1
;;
esac
if [ ! -f /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz ]; then
curl -L \
https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
-o /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz
fi
cd /tmp \
&& tar zxf wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
&& mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \
&& install wabt-1.0.31/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \
&& cd -
fi
else
echo "download source code and compile and install"
if [ ! -d "wabt" ];then
echo "wabt not exist, clone it from github"
git clone --recursive https://github.com/WebAssembly/wabt
fi
echo "upate wabt"
cd wabt
git pull
git reset --hard origin/main
cd ..
make -C wabt gcc-release -j 4
fi
}
# TODO: with iwasm only
function spec_test()
{
@ -338,6 +394,9 @@ function spec_test()
if [[ ${ENABLE_SIMD} == 1 ]]; then
git apply ../../spec-test-script/simd_ignore_cases.patch
fi
if [[ ${ENABLE_MULTI_MODULE} == 1 && $1 == 'aot' ]]; then
git apply ../../spec-test-script/muti_module_aot_ignore_cases.patch
fi
# udpate thread cases
if [ ${ENABLE_MULTI_THREAD} == 1 ]; then
@ -380,50 +439,7 @@ function spec_test()
popd
echo $(pwd)
if [ ${WABT_BINARY_RELEASE} == "YES" ]; then
echo "download a binary release and install"
local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
if [ ! -f ${WAT2WASM} ]; then
case ${PLATFORM} in
linux)
WABT_PLATFORM=ubuntu
;;
darwin)
WABT_PLATFORM=macos
;;
windows)
WABT_PLATFORM=windows
;;
*)
echo "wabt platform for ${PLATFORM} in unknown"
exit 1
;;
esac
if [ ! -f /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz ]; then
curl -L \
https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
-o /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz
fi
cd /tmp \
&& tar zxf wabt-1.0.31-${WABT_PLATFORM}.tar.gz \
&& mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \
&& install wabt-1.0.31/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \
&& cd -
fi
else
echo "download source code and compile and install"
if [ ! -d "wabt" ];then
echo "wabt not exist, clone it from github"
git clone --recursive https://github.com/WebAssembly/wabt
fi
echo "upate wabt"
cd wabt
git pull
git reset --hard origin/main
cd ..
make -C wabt gcc-release -j 4
fi
setup_wabt
ln -sf ${WORK_DIR}/../spec-test-script/all.py .
ln -sf ${WORK_DIR}/../spec-test-script/runtest.py .
@ -432,7 +448,7 @@ function spec_test()
# multi-module only enable in interp mode
if [[ 1 == ${ENABLE_MULTI_MODULE} ]]; then
if [[ $1 == 'classic-interp' || $1 == 'fast-interp' ]]; then
if [[ $1 == 'classic-interp' || $1 == 'fast-interp' || $1 == 'aot' ]]; then
ARGS_FOR_SPEC_TEST+="-M "
fi
fi
@ -515,13 +531,35 @@ function wasi_test()
echo "Finish wasi tests"
}
function wamr_compiler_test()
{
if [[ $1 != "aot" ]]; then
echo "WAMR compiler tests only support AOT mode"
exit 1
fi
echo "Now start WAMR compiler tests"
setup_wabt
cd ${WORK_DIR}/../wamr-compiler-test-script
./run_wamr_compiler_tests.sh ${WORK_DIR}/wabt/out/gcc/Release/wat2wasm $WAMRC_CMD $IWASM_CMD \
| tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
ret=${PIPESTATUS[0]}
if [[ ${ret} -ne 0 ]];then
echo -e "\nWAMR compiler tests FAILED" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
exit 1
fi
echo -e "\nFinish WAMR compiler tests" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
}
function wasi_certification_test()
{
echo "Now start wasi certification tests"
cd ${WORK_DIR}
if [ ! -d "wasi-testsuite" ]; then
echo "wasi not exist, clone it from github"
echo "wasi-testsuite not exist, clone it from github"
git clone -b prod/testsuite-all \
--single-branch https://github.com/WebAssembly/wasi-testsuite.git
fi
@ -665,6 +703,20 @@ function build_iwasm_with_cfg()
echo -e "build iwasm failed"
exit 1
fi
if [[ ${PLATFORM} == "cosmopolitan" ]]; then
# convert from APE to ELF so it can be ran easier
# HACK: link to linux so tests work when platform is detected by uname
cp iwasm.com iwasm \
&& ./iwasm --assimilate \
&& rm -rf ../../linux/build \
&& mkdir ../../linux/build \
&& ln -s ../../cosmopolitan/build/iwasm ../../linux/build/iwasm
if [ "$?" != 0 ];then
echo -e "build iwasm failed (cosmopolitan)"
exit 1
fi
fi
}
function build_wamrc()

View File

@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (C) 2023 Amazon Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set -e
WAT2WASM_CMD=$1
WAMRC_CMD=$2
IWASM_CMD=$3
for wat_file in ../../wamr-compiler/*.wat; do
wasm_file="${wat_file%.wat}.wasm"
aot_file="${wat_file%.wat}.aot"
echo "Compiling $wat_file to $wasm_file"
$WAT2WASM_CMD "$wat_file" -o "$wasm_file"
echo "Compiling $wasm_file to $aot_file"
$WAMRC_CMD -o $aot_file $wasm_file
echo "Testing $aot_file"
$IWASM_CMD "$aot_file"
done

View File

@ -0,0 +1,19 @@
#! /usr/bin/env python3
# Copyright (C) 2023 YAMAMOTO Takashi
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# This is a copy of https://github.com/yamt/toywasm/blob/master/test/pipe.py
# keep stdout open until the peer closes it
import sys
import select
p = select.poll()
p.register(sys.stdout, select.POLLHUP)
# http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57369
while True:
l = p.poll(1)
if l:
break

View File

@ -5,6 +5,8 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
THIS_DIR=$(cd $(dirname $0) && pwd -P)
readonly MODE=$1
readonly TARGET=$2
@ -28,25 +30,23 @@ readonly IWASM_CMD="${IWASM_EXE} \
--allow-resolve=google-public-dns-a.google.com \
--addr-pool=::1/128,127.0.0.1/32"
readonly IWASM_CMD_STRESS="${IWASM_CMD} --max-threads=8"
readonly IWASM_CMD_STRESS="${IWASM_CMD} --max-threads=12"
readonly WAMRC_CMD="${WORK_DIR}/../../../../wamr-compiler/build/wamrc"
readonly C_TESTS="tests/c/testsuite/"
readonly RUST_TESTS="tests/rust/testsuite/"
readonly ASSEMBLYSCRIPT_TESTS="tests/assemblyscript/testsuite/"
readonly THREAD_PROPOSAL_TESTS="tests/proposals/wasi-threads/"
readonly THREAD_INTERNAL_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/test/"
readonly THREAD_STRESS_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/stress-test/"
readonly LIB_SOCKET_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-socket/test/"
readonly STRESS_TESTS=("spawn_stress_test.wasm" "stress_test_threads_creation.wasm")
run_aot_tests () {
local tests=("$@")
local iwasm="${IWASM_CMD}"
for test_wasm in ${tests[@]}; do
local extra_stress_flags=""
for stress_test in "${STRESS_TESTS[@]}"; do
if [ "$test_wasm" == "$stress_test" ]; then
iwasm="${IWASM_CMD_STRESS}"
fi
done
local iwasm="${IWASM_CMD}"
if [[ $test_wasm =~ "stress" ]]; then
iwasm="${IWASM_CMD_STRESS}"
fi
test_aot="${test_wasm%.wasm}.aot"
test_json="${test_wasm%.wasm}.json"
@ -65,8 +65,8 @@ run_aot_tests () {
expected=$(jq .exit_code ${test_json})
fi
${IWASM_CMD} $extra_stress_flags $test_aot
ret=${PIPESTATUS[0]}
$PYTHON_EXE ${THIS_DIR}/pipe.py | ${iwasm} $test_aot
ret=${PIPESTATUS[1]}
echo "expected=$expected, actual=$ret"
if [[ $expected != "" ]] && [[ $expected != $ret ]];then
@ -79,33 +79,30 @@ if [[ $MODE != "aot" ]];then
$PYTHON_EXE -m venv wasi-env && source wasi-env/${VENV_BIN_DIR}/activate
$PYTHON_EXE -m pip install -r test-runner/requirements.txt
# Stress tests require max-threads=8 so they're executed separately
for stress_test in "${STRESS_TESTS[@]}"; do
if [[ -e "${THREAD_INTERNAL_TESTS}${stress_test}" ]]; then
echo "${stress_test}" is a stress test
${IWASM_CMD_STRESS} ${THREAD_INTERNAL_TESTS}${stress_test}
ret=${PIPESTATUS[0]}
if [ "${ret}" -ne 0 ]; then
echo "Stress test ${stress_test} FAILED with code " ${ret}
exit_code=${ret}
fi
fi
done
TEST_RUNTIME_EXE="${IWASM_CMD}" $PYTHON_EXE test-runner/wasi_test_runner.py \
export TEST_RUNTIME_EXE="${IWASM_CMD}"
$PYTHON_EXE ${THIS_DIR}/pipe.py | $PYTHON_EXE test-runner/wasi_test_runner.py \
-r adapters/wasm-micro-runtime.py \
-t \
${C_TESTS} \
${RUST_TESTS} \
${ASSEMBLYSCRIPT_TESTS} \
${THREAD_PROPOSAL_TESTS} \
${THREAD_INTERNAL_TESTS} \
${LIB_SOCKET_TESTS} \
--exclude-filter "${THREAD_INTERNAL_TESTS}skip.json"
ret=${PIPESTATUS[0]}
if [ "${ret}" -ne 0 ]; then
exit_code=${ret}
ret=${PIPESTATUS[1]}
TEST_RUNTIME_EXE="${IWASM_CMD_STRESS}" $PYTHON_EXE test-runner/wasi_test_runner.py \
-r adapters/wasm-micro-runtime.py \
-t \
${THREAD_STRESS_TESTS}
if [ "${ret}" -eq 0 ]; then
ret=${PIPESTATUS[0]}
fi
exit_code=${ret}
deactivate
else
target_option=""
@ -114,7 +111,7 @@ else
fi
exit_code=0
for testsuite in ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do
for testsuite in ${THREAD_STRESS_TESTS} ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do
tests=$(ls ${testsuite}*.wasm)
tests_array=($tests)
run_aot_tests "${tests_array[@]}"