Skip to content

Commit 494d7e7

Browse files
committed
Update spec test to latest commit
- update spec test to commit bc76fd79cfe61033d7f4ad4a7e8fc4f996dc5ba8 on Apr. 3 - upddate wabt binary to 1.0.34 to support newer spec cases - Add comparision between table declared elem type and elem segment value type - Add a function to decide whether to execute test cases in a running mode - keep using interpreter in GC spec because wat2wasm in wabt can't compile if.wast w/o errors - re-factoring threads spec test case processing - since wabt 1.0.34 release isn't compatible with ubuntu 20.04, compile from source code
1 parent 0f17a14 commit 494d7e7

File tree

15 files changed

+1833
-689
lines changed

15 files changed

+1833
-689
lines changed

.github/workflows/compilation_on_sgx.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,23 +269,24 @@ jobs:
269269
strategy:
270270
matrix:
271271
running_mode: ["classic-interp", "fast-interp", "aot", "fast-jit"]
272-
test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P", "-x -p -s spec -X -b -P"]
272+
# FIXME: use binary release(adding -b) instead of building from source after upgrading to 22.04
273+
test_option: ["-x -p -s spec -P", "-x -p -s spec -S -P", "-x -p -s spec -X -P"]
273274
llvm_cache_key: ["${{ needs.build_llvm_libraries.outputs.cache_key }}"]
274275
exclude:
275276
# classic-interp, fast-interp and fast-jit don't support simd
276277
- running_mode: "classic-interp"
277-
test_option: "-x -p -s spec -S -b -P"
278+
test_option: "-x -p -s spec -S -P"
278279
- running_mode: "fast-interp"
279-
test_option: "-x -p -s spec -S -b -P"
280+
test_option: "-x -p -s spec -S -P"
280281
- running_mode: "fast-jit"
281-
test_option: "-x -p -s spec -S -b -P"
282+
test_option: "-x -p -s spec -S -P"
282283
# classic-interp, fast-interp and fast jit don't support XIP
283284
- running_mode: "classic-interp"
284-
test_option: "-x -p -s spec -X -b -P"
285+
test_option: "-x -p -s spec -X -P"
285286
- running_mode: "fast-interp"
286-
test_option: "-x -p -s spec -X -b -P"
287+
test_option: "-x -p -s spec -X -P"
287288
- running_mode: "fast-jit"
288-
test_option: "-x -p -s spec -X -b -P"
289+
test_option: "-x -p -s spec -X -P"
289290

290291
steps:
291292
- name: checkout
@@ -320,6 +321,9 @@ jobs:
320321
sudo apt update
321322
sudo apt install -y libsgx-launch libsgx-urts
322323
324+
- name: install for wabt compilation
325+
run: sudo apt update && sudo apt install -y ninja-build
326+
323327
- name: run spec tests
324328
run: |
325329
source /opt/intel/sgxsdk/environment

.github/workflows/nightly_run.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ env:
3636
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
3737
MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
3838
# For Spec Test
39-
DEFAULT_TEST_OPTIONS: "-s spec -b -P"
40-
MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M -P"
41-
SIMD_TEST_OPTIONS: "-s spec -b -S -P"
42-
THREADS_TEST_OPTIONS: "-s spec -b -p -P"
39+
# FIXME: use binary release(adding -b) instead of building from source after upgrading to 22.04
40+
DEFAULT_TEST_OPTIONS: "-s spec -P"
41+
MULTI_MODULES_TEST_OPTIONS: "-s spec -M -P"
42+
SIMD_TEST_OPTIONS: "-s spec -S -P"
43+
THREADS_TEST_OPTIONS: "-s spec -p -P"
4344
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
4445
WASI_TEST_OPTIONS: "-s wasi_certification -w"
4546

@@ -719,6 +720,9 @@ jobs:
719720
if: matrix.running_mode == 'aot' && matrix.test_option == '$WASI_TEST_OPTIONS'
720721
run: sudo apt-get update && sudo apt install -y jq
721722

723+
- name: install for wabt compilation
724+
run: sudo apt update && sudo apt install -y ninja-build
725+
722726
- name: Build WASI thread tests
723727
if: matrix.test_option == '$WASI_TEST_OPTIONS'
724728
run: bash build.sh --sysroot "$SYSROOT_PATH"

core/iwasm/aot/aot_runtime.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ check_global_init_expr(const AOTModule *module, uint32 global_index,
120120
return false;
121121
}
122122

123-
#if WASM_ENABLE_GC == 0
124123
/**
125124
* Currently, constant expressions occurring as initializers of
126125
* globals are further constrained in that contained global.get
@@ -129,24 +128,26 @@ check_global_init_expr(const AOTModule *module, uint32 global_index,
129128
* And initializer expression cannot reference a mutable global.
130129
*/
131130
if (global_index >= module->import_global_count
132-
|| module->import_globals->type.is_mutable) {
133-
set_error_buf(error_buf, error_buf_size,
134-
"constant expression required");
135-
return false;
136-
}
137-
#else
138-
if (global_index >= module->import_global_count + module->global_count) {
131+
/* make spec test happy */
132+
#if WASM_ENABLE_GC != 0
133+
+ module->global_count
134+
#endif
135+
) {
139136
set_error_buf_v(error_buf, error_buf_size, "unknown global %u",
140137
global_index);
141138
return false;
142139
}
143-
if (global_index < module->import_global_count
144-
&& module->import_globals[global_index].type.is_mutable) {
140+
141+
if (
142+
/* make spec test happy */
143+
#if WASM_ENABLE_GC != 0
144+
global_index < module->import_global_count &&
145+
#endif
146+
module->import_globals[global_index].type.is_mutable) {
145147
set_error_buf(error_buf, error_buf_size,
146148
"constant expression required");
147149
return false;
148150
}
149-
#endif
150151

151152
return true;
152153
}

core/iwasm/interpreter/wasm_loader.c

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -830,39 +830,35 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
830830
read_leb_uint32(p, p_end, cur_value.global_index);
831831
global_idx = cur_value.global_index;
832832

833-
#if WASM_ENABLE_GC == 0
834-
if (global_idx >= module->import_global_count) {
835-
/**
836-
* Currently, constant expressions occurring as initializers
837-
* of globals are further constrained in that contained
838-
* global.get instructions are
839-
* only allowed to refer to imported globals.
840-
*/
833+
/*
834+
* Currently, constant expressions occurring as initializers
835+
* of globals are further constrained in that contained
836+
* global.get instructions are
837+
* only allowed to refer to imported globals.
838+
*
839+
* https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions
840+
*/
841+
if (global_idx >= module->import_global_count
842+
/* make spec test happy */
843+
#if WASM_ENABLE_GC != 0
844+
+ module->global_count
845+
#endif
846+
) {
841847
set_error_buf_v(error_buf, error_buf_size,
842848
"unknown global %u", global_idx);
843849
goto fail;
844850
}
845-
if (module->import_globals[global_idx]
851+
if (
852+
/* make spec test happy */
853+
#if WASM_ENABLE_GC != 0
854+
global_idx < module->import_global_count &&
855+
#endif
856+
module->import_globals[global_idx]
846857
.u.global.type.is_mutable) {
847858
set_error_buf_v(error_buf, error_buf_size,
848859
"constant expression required");
849860
goto fail;
850861
}
851-
#else
852-
if (global_idx
853-
>= module->import_global_count + module->global_count) {
854-
set_error_buf_v(error_buf, error_buf_size,
855-
"unknown global %u", global_idx);
856-
goto fail;
857-
}
858-
if (global_idx < module->import_global_count
859-
&& module->import_globals[global_idx]
860-
.u.global.type.is_mutable) {
861-
set_error_buf_v(error_buf, error_buf_size,
862-
"constant expression required");
863-
goto fail;
864-
}
865-
#endif
866862

867863
if (global_idx < module->import_global_count) {
868864
global_type = module->import_globals[global_idx]
@@ -4244,6 +4240,43 @@ load_table_index(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
42444240
return false;
42454241
}
42464242

4243+
/* Element segments must match element type of table */
4244+
static bool
4245+
check_table_elem_type(WASMModule *module, uint32 table_index,
4246+
uint32 type_from_elem_seg, char *error_buf,
4247+
uint32 error_buf_size)
4248+
{
4249+
uint32 table_declared_elem_type;
4250+
4251+
if (table_index < module->import_table_count)
4252+
table_declared_elem_type =
4253+
module->import_tables[table_index].u.table.elem_type;
4254+
else
4255+
table_declared_elem_type = (module->tables + table_index)->elem_type;
4256+
4257+
if (table_declared_elem_type == type_from_elem_seg)
4258+
return true;
4259+
4260+
#if WASM_ENABLE_GC != 0
4261+
/*
4262+
* balance in: anyref, funcref, (ref.null func) and (ref.func)
4263+
*/
4264+
if (table_declared_elem_type == REF_TYPE_ANYREF)
4265+
return true;
4266+
4267+
if (table_declared_elem_type == VALUE_TYPE_FUNCREF
4268+
&& type_from_elem_seg == REF_TYPE_HT_NON_NULLABLE)
4269+
return true;
4270+
4271+
if (table_declared_elem_type == REF_TYPE_HT_NULLABLE
4272+
&& type_from_elem_seg == REF_TYPE_HT_NON_NULLABLE)
4273+
return true;
4274+
#endif
4275+
4276+
set_error_buf(error_buf, error_buf_size, "type mismatch");
4277+
return false;
4278+
}
4279+
42474280
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
42484281
static bool
42494282
load_elem_type(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
@@ -4479,6 +4512,12 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
44794512
return false;
44804513
}
44814514

4515+
if (!check_table_elem_type(module,
4516+
table_segment->table_index,
4517+
table_segment->elem_type,
4518+
error_buf, error_buf_size))
4519+
return false;
4520+
44824521
break;
44834522
}
44844523
/* elemkind + passive/declarative */
@@ -4530,6 +4569,13 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
45304569
error_buf_size))
45314570
return false;
45324571
}
4572+
4573+
if (!check_table_elem_type(module,
4574+
table_segment->table_index,
4575+
table_segment->elem_type,
4576+
error_buf, error_buf_size))
4577+
return false;
4578+
45334579
break;
45344580
case 5:
45354581
case 7:
@@ -4566,6 +4612,13 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
45664612
if (!load_func_index_vec(&p, p_end, module, table_segment,
45674613
error_buf, error_buf_size))
45684614
return false;
4615+
4616+
table_segment->elem_type = VALUE_TYPE_FUNCREF;
4617+
4618+
if (!check_table_elem_type(module, table_segment->table_index,
4619+
table_segment->elem_type, error_buf,
4620+
error_buf_size))
4621+
return false;
45694622
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
45704623

45714624
#if WASM_ENABLE_WAMR_COMPILER != 0

core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,12 @@ print_i32_wrapper(wasm_exec_env_t exec_env, int32 i32)
10011001
os_printf("in specttest.print_i32(%" PRId32 ")\n", i32);
10021002
}
10031003

1004+
static void
1005+
print_i64_wrapper(wasm_exec_env_t exec_env, int64 i64)
1006+
{
1007+
os_printf("in specttest.print_i64(%" PRId32 ")\n", i64);
1008+
}
1009+
10041010
static void
10051011
print_i32_f32_wrapper(wasm_exec_env_t exec_env, int32 i32, float f32)
10061012
{
@@ -1091,6 +1097,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
10911097
static NativeSymbol native_symbols_spectest[] = {
10921098
REG_NATIVE_FUNC(print, "()"),
10931099
REG_NATIVE_FUNC(print_i32, "(i)"),
1100+
REG_NATIVE_FUNC(print_i64, "(I)"),
10941101
REG_NATIVE_FUNC(print_i32_f32, "(if)"),
10951102
REG_NATIVE_FUNC(print_f64_f64, "(FF)"),
10961103
REG_NATIVE_FUNC(print_f32, "(f)"),
@@ -1136,6 +1143,7 @@ static WASMNativeGlobalDef native_global_defs[] = {
11361143
{ "test", "global-f32", VALUE_TYPE_F32, false, .value.f32 = 0 },
11371144
{ "test", "global-mut-i32", VALUE_TYPE_I32, true, .value.i32 = 0 },
11381145
{ "test", "global-mut-i64", VALUE_TYPE_I64, true, .value.i64 = 0 },
1146+
{ "test", "g", VALUE_TYPE_I32, true, .value.i32 = 0 },
11391147
#if WASM_ENABLE_GC != 0
11401148
{ "G", "g", VALUE_TYPE_I32, false, .value.i32 = 4 },
11411149
{ "M", "g", REF_TYPE_HT_NON_NULLABLE, false, .value.gc_obj = 0 },

tests/wamr-test-suites/spec-test-script/all.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def get_iwasm_cmd(platform: str) -> str:
4747
IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm"
4848
IWASM_QEMU_CMD = "iwasm"
4949
SPEC_TEST_DIR = "spec/test/core"
50-
EXCE_HANDLING_DIR = "exception-handling/test/core"
5150
WAST2WASM_CMD = exe_file_path("./wabt/out/gcc/Release/wat2wasm")
5251
SPEC_INTERPRETER_CMD = "spec/interpreter/wasm"
5352
WAMRC_CMD = "../../../wamr-compiler/build/wamrc"
@@ -87,7 +86,7 @@ def ignore_the_case(
8786
if case_name in ["comments", "inline-module", "names"]:
8887
return True
8988

90-
if not multi_module_flag and case_name in ["imports", "linking"]:
89+
if not multi_module_flag and case_name in ["imports", "linking", "simd_linking"]:
9190
return True
9291

9392
# Note: x87 doesn't preserve sNaN and makes some relevant tests fail.
@@ -143,10 +142,6 @@ def preflight_check(aot_flag, eh_flag):
143142
print(f"Can not find {WAMRC_CMD}")
144143
return False
145144

146-
if eh_flag and not pathlib.Path(EXCE_HANDLING_DIR).resolve().exists():
147-
print(f"Can not find {EXCE_HANDLING_DIR}")
148-
return False
149-
150145
return True
151146

152147

@@ -171,7 +166,7 @@ def test_case(
171166
):
172167
CMD = [sys.executable, "runtest.py"]
173168
CMD.append("--wast2wasm")
174-
CMD.append(WAST2WASM_CMD if not gc_flag and not memory64_flag else SPEC_INTERPRETER_CMD)
169+
CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD)
175170
CMD.append("--interpreter")
176171
if sgx_flag:
177172
CMD.append(IWASM_SGX_CMD)
@@ -310,11 +305,7 @@ def test_suite(
310305
case_list.extend(gc_case_list)
311306

312307
if eh_flag:
313-
eh_path = pathlib.Path(EXCE_HANDLING_DIR).resolve()
314-
if not eh_path.exists():
315-
print(f"can not find spec test cases at {eh_path}")
316-
return False
317-
eh_case_list = sorted(eh_path.glob("*.wast"))
308+
eh_case_list = sorted(suite_path.glob("*.wast"))
318309
eh_case_list_include = [test for test in eh_case_list if test.stem in ["throw", "tag", "try_catch", "rethrow", "try_delegate"]]
319310
case_list.extend(eh_case_list_include)
320311

@@ -337,7 +328,9 @@ def test_suite(
337328
qemu_flag,
338329
):
339330
filtered_case_list.append(case_path)
340-
print(f"---> {len(case_list)} --filter--> {len(filtered_case_list)}")
331+
else:
332+
print(f"---> skip {case_name}")
333+
print(f"---> {len(case_list)} ---filter--> {len(filtered_case_list)}")
341334
case_list = filtered_case_list
342335

343336
case_count = len(case_list)

0 commit comments

Comments
 (0)