Skip to content

Commit 6d61e72

Browse files
authored
Update unit test cases (#4214)
* Update gc unit test cases * Update aot stack frame unit test cases
1 parent c883faf commit 6d61e72

21 files changed

+250
-290
lines changed

tests/unit/aot-stack-frame/CMakeLists.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set (WAMR_BUILD_LIBC_BUILTIN 0)
1717
set (WAMR_BUILD_MULTI_MODULE 0)
1818
set (WAMR_DISABLE_HW_BOUND_CHECK 1)
1919
set (WAMR_DISABLE_WRITE_GS_BASE 1)
20+
set (WAMR_BUILD_GC 1)
2021

2122
include (../unit_common.cmake)
2223

@@ -31,15 +32,21 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
3132
set (UNIT_SOURCE ${source_all})
3233

3334
set (unit_test_sources
34-
${UNIT_SOURCE}
35-
${PLATFORM_SHARED_SOURCE}
36-
${UTILS_SHARED_SOURCE}
37-
${MEM_ALLOC_SHARED_SOURCE}
38-
${NATIVE_INTERFACE_SOURCE}
39-
${IWASM_COMMON_SOURCE}
40-
${IWASM_INTERP_SOURCE}
41-
${IWASM_AOT_SOURCE}
42-
${WASM_APP_LIB_SOURCE_ALL}
35+
${UNIT_SOURCE}
36+
${WAMR_RUNTIME_LIB_SOURCE}
37+
${UNCOMMON_SHARED_SOURCE}
38+
${SRC_LIST}
39+
${PLATFORM_SHARED_SOURCE}
40+
${UTILS_SHARED_SOURCE}
41+
${MEM_ALLOC_SHARED_SOURCE}
42+
${LIB_HOST_AGENT_SOURCE}
43+
${NATIVE_INTERFACE_SOURCE}
44+
${LIBC_BUILTIN_SOURCE}
45+
${IWASM_COMMON_SOURCE}
46+
${IWASM_INTERP_SOURCE}
47+
${IWASM_AOT_SOURCE}
48+
${IWASM_COMPL_SOURCE}
49+
${WASM_APP_LIB_SOURCE_ALL}
4350
)
4451

4552
# Automatically build wasm-apps for this test

tests/unit/aot-stack-frame/aot_stack_frame_test.cc

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -162,57 +162,6 @@ TEST_F(AOTStackFrameTest, test1)
162162
exec_env = wasm_runtime_create_exec_env(module_inst, 8 * 1024);
163163
ASSERT_TRUE(exec_env != NULL);
164164

165-
func_inst = wasm_runtime_lookup_function(module_inst, "test1");
166-
ASSERT_TRUE(func_inst != NULL);
167-
168-
argv[0] = 33;
169-
argv[1] = 44;
170-
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
171-
ASSERT_TRUE(wasm_runtime_get_exception(module_inst));
172-
173-
frames = AOTStackFrameTest::my_frames;
174-
frame_num = AOTStackFrameTest::my_frame_num;
175-
176-
ASSERT_TRUE(frames != NULL);
177-
ASSERT_TRUE(frame_num == 1);
178-
179-
ASSERT_TRUE(frames[0]->lp[0] == 33);
180-
ASSERT_TRUE(frames[0]->lp[1] == 44);
181-
ASSERT_TRUE(frames[0]->lp[2] == 0x11223344);
182-
ASSERT_TRUE(*(uint64 *)(frames[0]->lp + 3) == 0x12345678ABCDEF99LL);
183-
ASSERT_TRUE(*(float *)(frames[0]->lp + 5) == 5566.7788f);
184-
ASSERT_TRUE(*(double *)(frames[0]->lp + 6) == 99887766.55443322);
185-
186-
wasm_runtime_destroy_exec_env(exec_env);
187-
exec_env = NULL;
188-
189-
wasm_runtime_deinstantiate(module_inst);
190-
module_inst = NULL;
191-
192-
wasm_runtime_unload(module);
193-
module = NULL;
194-
}
195-
196-
TEST_F(AOTStackFrameTest, test2)
197-
{
198-
MyAOTFrame *frame, **frames;
199-
uint32 frame_num;
200-
201-
aot_set_stack_frame_callback(aot_stack_frame_cb);
202-
203-
bh_memcpy_s(test_aot_buf, sizeof(test_aot_buf), test_aot, sizeof(test_aot));
204-
205-
module = wasm_runtime_load(test_aot_buf, sizeof(test_aot), error_buf,
206-
sizeof(error_buf));
207-
ASSERT_TRUE(module != NULL);
208-
209-
module_inst = wasm_runtime_instantiate(module, 16384, 0, error_buf,
210-
sizeof(error_buf));
211-
ASSERT_TRUE(module_inst != NULL);
212-
213-
exec_env = wasm_runtime_create_exec_env(module_inst, 8 * 1024);
214-
ASSERT_TRUE(exec_env != NULL);
215-
216165
func_inst = wasm_runtime_lookup_function(module_inst, "test2");
217166
ASSERT_TRUE(func_inst != NULL);
218167

@@ -233,11 +182,9 @@ TEST_F(AOTStackFrameTest, test2)
233182
ASSERT_TRUE(*(uint64 *)(frames[0]->lp + 3) == 0x12345678ABCDEF99LL);
234183
ASSERT_TRUE(*(float *)(frames[0]->lp + 5) == 5566.7788f);
235184
ASSERT_TRUE(*(double *)(frames[0]->lp + 6) == 99887766.55443322);
236-
ASSERT_TRUE(frames[0]->lp[8] == 0x1234);
237-
ASSERT_TRUE(frames[0]->lp[9] == 0x5678);
238185
}
239186

240-
TEST_F(AOTStackFrameTest, test3)
187+
TEST_F(AOTStackFrameTest, test2)
241188
{
242189
MyAOTFrame *frame, **frames;
243190
uint32 frame_num;
@@ -271,18 +218,14 @@ TEST_F(AOTStackFrameTest, test3)
271218
ASSERT_TRUE(frames != NULL);
272219
ASSERT_TRUE(frame_num == 2);
273220

274-
ASSERT_TRUE(frames[0]->sp - frames[0]->lp == 5);
275-
ASSERT_TRUE(frames[0]->ip_offset == 24);
221+
// 5(i32) + 1(i64) local variables, occupied 7 * 4 bytes
222+
ASSERT_TRUE(frames[0]->sp - frames[0]->lp == 7);
223+
224+
// offset of ip from module load address
225+
ASSERT_TRUE(frames[0]->ip_offset == 163);
276226

277227
ASSERT_TRUE(frames[0]->lp[0] == 1234);
278228
ASSERT_TRUE(frames[0]->lp[1] == 5678);
279229
ASSERT_TRUE(frames[0]->lp[2] == 0x11223344);
280230
ASSERT_TRUE(*(uint64 *)(frames[0]->lp + 3) == 0x12345678ABCDEF99LL);
281-
282-
ASSERT_TRUE(frames[1]->lp[0] == 0x1234);
283-
ASSERT_TRUE(frames[1]->lp[1] == 0x5678);
284-
ASSERT_TRUE(frames[1]->lp[2] == 0x11223344);
285-
ASSERT_TRUE(*(uint64 *)(frames[1]->lp + 3) == 0x12345678ABCDEF99LL);
286-
ASSERT_TRUE(*(float *)(frames[1]->lp + 5) == 5566.7788f);
287-
ASSERT_TRUE(*(double *)(frames[1]->lp + 6) == 99887766.55443322);
288231
}

tests/unit/aot-stack-frame/wasm-apps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_custom_target(aot-stack-frame-test-wasm ALL
1313
-o ${CMAKE_CURRENT_BINARY_DIR}/test.wasm
1414
${CMAKE_CURRENT_LIST_DIR}/test.wast
1515
&& ${CMAKE_CURRENT_BINARY_DIR}/build-wamrc/wamrc
16-
--enable-dump-call-stack --bounds-checks=1
16+
--enable-dump-call-stack --bounds-checks=1 --enable-gc
1717
-o ${CMAKE_CURRENT_BINARY_DIR}/test.aot
1818
${CMAKE_CURRENT_BINARY_DIR}/test.wasm
1919
&& cmake -B ${CMAKE_CURRENT_BINARY_DIR}/build-binarydump

tests/unit/gc/wasm-apps/func1.wasm

-35 Bytes
Binary file not shown.

tests/unit/gc/wasm-apps/func1.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
(local (ref null struct))
2727

2828
local.get 0
29-
ref.test null array
29+
ref.test (ref array)
3030
drop
3131
local.get 1
32-
ref.cast i31
32+
ref.cast (ref i31)
3333
drop
3434
)
3535
)

tests/unit/gc/wasm-apps/func2.wasm

-462 Bytes
Binary file not shown.

tests/unit/gc/wasm-apps/struct1.wasm

-77 Bytes
Binary file not shown.

tests/unit/gc/wasm-apps/struct2.wasm

68 Bytes
Binary file not shown.

tests/unit/gc/wasm-apps/struct2.wast

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
(module
22
(type $vec (struct (field f32) (field $y (mut f32)) (field $z f32)))
33

4-
;;(global (ref $vec) (struct.new_canon $vec (f32.const 1) (f32.const 2) (f32.const 3)))
5-
(global (ref $vec) (struct.new_canon_default $vec))
4+
(global (ref $vec) (struct.new $vec (f32.const 1) (f32.const 2) (f32.const 3)))
5+
(global (ref $vec) (struct.new_default $vec))
66

77
(func (export "new") (result anyref)
8-
(struct.new_canon_default $vec)
8+
(struct.new_default $vec)
99
)
1010

11-
(func $get_0 (param $v (ref $vec)) (result f32)
11+
(func $get_0_0 (param $v (ref $vec)) (result f32)
12+
(struct.get 0 0 (local.get $v))
13+
)
14+
(func (export "get_0_0") (result f32)
15+
(call $get_0_0 (struct.new_default $vec))
16+
)
17+
(func $get_vec_0 (param $v (ref $vec)) (result f32)
1218
(struct.get $vec 0 (local.get $v))
1319
)
14-
(func (export "get_0") (result f32)
15-
(call $get_0 (struct.new_canon_default $vec))
20+
(func (export "get_vec_0") (result f32)
21+
(call $get_vec_0 (struct.new_default $vec))
22+
)
23+
(func $get_0_y (param $v (ref $vec)) (result f32)
24+
(struct.get 0 $y (local.get $v))
25+
)
26+
(func (export "get_0_y") (result f32)
27+
(call $get_0_y (struct.new_default $vec))
28+
)
29+
(func $get_vec_y (param $v (ref $vec)) (result f32)
30+
(struct.get $vec $y (local.get $v))
31+
)
32+
(func (export "get_vec_y") (result f32)
33+
(call $get_vec_y (struct.new_default $vec))
1634
)
1735

1836
(func $set_get_y (param $v (ref $vec)) (param $y f32) (result f32)
1937
(struct.set $vec $y (local.get $v) (local.get $y))
2038
(struct.get $vec $y (local.get $v))
2139
)
2240
(func (export "set_get_y") (param $y f32) (result f32)
23-
(call $set_get_y (struct.new_canon_default $vec) (local.get $y))
41+
(call $set_get_y (struct.new_default $vec) (local.get $y))
2442
)
2543

2644
(func $set_get_1 (param $v (ref $vec)) (param $y f32) (result f32)
2745
(struct.set $vec 1 (local.get $v) (local.get $y))
2846
(struct.get $vec $y (local.get $v))
2947
)
3048
(func (export "set_get_1") (param $y f32) (result f32)
31-
(call $set_get_1 (struct.new_canon_default $vec) (local.get $y))
49+
(call $set_get_1 (struct.new_default $vec) (local.get $y))
3250
)
3351
)

tests/unit/gc/wasm-apps/struct3.wasm

-24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)