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

@ -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)