Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions tests/unit/aot-stack-frame/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 2.9)
cmake_minimum_required(VERSION 3.14)

project (test-aot-stack-frame)

Expand All @@ -17,6 +17,7 @@ set (WAMR_BUILD_LIBC_BUILTIN 0)
set (WAMR_BUILD_MULTI_MODULE 0)
set (WAMR_DISABLE_HW_BOUND_CHECK 1)
set (WAMR_DISABLE_WRITE_GS_BASE 1)
set (WAMR_BUILD_GC 1)

include (../unit_common.cmake)

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

set (unit_test_sources
${UNIT_SOURCE}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${NATIVE_INTERFACE_SOURCE}
${IWASM_COMMON_SOURCE}
${IWASM_INTERP_SOURCE}
${IWASM_AOT_SOURCE}
${WASM_APP_LIB_SOURCE_ALL}
${UNIT_SOURCE}
${WAMR_RUNTIME_LIB_SOURCE}
${UNCOMMON_SHARED_SOURCE}
${SRC_LIST}
${PLATFORM_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE}
${LIB_HOST_AGENT_SOURCE}
${NATIVE_INTERFACE_SOURCE}
${LIBC_BUILTIN_SOURCE}
${IWASM_COMMON_SOURCE}
${IWASM_INTERP_SOURCE}
${IWASM_AOT_SOURCE}
${IWASM_COMPL_SOURCE}
${WASM_APP_LIB_SOURCE_ALL}
)

# Automatically build wasm-apps for this test
Expand Down
69 changes: 6 additions & 63 deletions tests/unit/aot-stack-frame/aot_stack_frame_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,57 +162,6 @@ TEST_F(AOTStackFrameTest, test1)
exec_env = wasm_runtime_create_exec_env(module_inst, 8 * 1024);
ASSERT_TRUE(exec_env != NULL);

func_inst = wasm_runtime_lookup_function(module_inst, "test1");
ASSERT_TRUE(func_inst != NULL);

argv[0] = 33;
argv[1] = 44;
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
ASSERT_TRUE(wasm_runtime_get_exception(module_inst));

frames = AOTStackFrameTest::my_frames;
frame_num = AOTStackFrameTest::my_frame_num;

ASSERT_TRUE(frames != NULL);
ASSERT_TRUE(frame_num == 1);

ASSERT_TRUE(frames[0]->lp[0] == 33);
ASSERT_TRUE(frames[0]->lp[1] == 44);
ASSERT_TRUE(frames[0]->lp[2] == 0x11223344);
ASSERT_TRUE(*(uint64 *)(frames[0]->lp + 3) == 0x12345678ABCDEF99LL);
ASSERT_TRUE(*(float *)(frames[0]->lp + 5) == 5566.7788f);
ASSERT_TRUE(*(double *)(frames[0]->lp + 6) == 99887766.55443322);

wasm_runtime_destroy_exec_env(exec_env);
exec_env = NULL;

wasm_runtime_deinstantiate(module_inst);
module_inst = NULL;

wasm_runtime_unload(module);
module = NULL;
}

TEST_F(AOTStackFrameTest, test2)
{
MyAOTFrame *frame, **frames;
uint32 frame_num;

aot_set_stack_frame_callback(aot_stack_frame_cb);

bh_memcpy_s(test_aot_buf, sizeof(test_aot_buf), test_aot, sizeof(test_aot));

module = wasm_runtime_load(test_aot_buf, sizeof(test_aot), error_buf,
sizeof(error_buf));
ASSERT_TRUE(module != NULL);

module_inst = wasm_runtime_instantiate(module, 16384, 0, error_buf,
sizeof(error_buf));
ASSERT_TRUE(module_inst != NULL);

exec_env = wasm_runtime_create_exec_env(module_inst, 8 * 1024);
ASSERT_TRUE(exec_env != NULL);

func_inst = wasm_runtime_lookup_function(module_inst, "test2");
ASSERT_TRUE(func_inst != NULL);

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

TEST_F(AOTStackFrameTest, test3)
TEST_F(AOTStackFrameTest, test2)
{
MyAOTFrame *frame, **frames;
uint32 frame_num;
Expand Down Expand Up @@ -271,18 +218,14 @@ TEST_F(AOTStackFrameTest, test3)
ASSERT_TRUE(frames != NULL);
ASSERT_TRUE(frame_num == 2);

ASSERT_TRUE(frames[0]->sp - frames[0]->lp == 5);
ASSERT_TRUE(frames[0]->ip_offset == 24);
// 5(i32) + 1(i64) local variables, occupied 7 * 4 bytes
ASSERT_TRUE(frames[0]->sp - frames[0]->lp == 7);

// offset of ip from module load address
ASSERT_TRUE(frames[0]->ip_offset == 163);

ASSERT_TRUE(frames[0]->lp[0] == 1234);
ASSERT_TRUE(frames[0]->lp[1] == 5678);
ASSERT_TRUE(frames[0]->lp[2] == 0x11223344);
ASSERT_TRUE(*(uint64 *)(frames[0]->lp + 3) == 0x12345678ABCDEF99LL);

ASSERT_TRUE(frames[1]->lp[0] == 0x1234);
ASSERT_TRUE(frames[1]->lp[1] == 0x5678);
ASSERT_TRUE(frames[1]->lp[2] == 0x11223344);
ASSERT_TRUE(*(uint64 *)(frames[1]->lp + 3) == 0x12345678ABCDEF99LL);
ASSERT_TRUE(*(float *)(frames[1]->lp + 5) == 5566.7788f);
ASSERT_TRUE(*(double *)(frames[1]->lp + 6) == 99887766.55443322);
}
4 changes: 2 additions & 2 deletions tests/unit/aot-stack-frame/wasm-apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 2.9)
cmake_minimum_required(VERSION 3.14)

project(wasm-apps-aot-stack-frame)

Expand All @@ -13,7 +13,7 @@ add_custom_target(aot-stack-frame-test-wasm ALL
-o ${CMAKE_CURRENT_BINARY_DIR}/test.wasm
${CMAKE_CURRENT_LIST_DIR}/test.wast
&& ${CMAKE_CURRENT_BINARY_DIR}/build-wamrc/wamrc
--enable-dump-call-stack --bounds-checks=1
--enable-dump-call-stack --bounds-checks=1 --enable-gc
-o ${CMAKE_CURRENT_BINARY_DIR}/test.aot
${CMAKE_CURRENT_BINARY_DIR}/test.wasm
&& cmake -B ${CMAKE_CURRENT_BINARY_DIR}/build-binarydump
Expand Down
Binary file modified tests/unit/gc/wasm-apps/func1.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/unit/gc/wasm-apps/func1.wast
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
(local (ref null struct))

local.get 0
ref.test null array
ref.test (ref array)
drop
local.get 1
ref.cast i31
ref.cast (ref i31)
drop
)
)
Binary file modified tests/unit/gc/wasm-apps/func2.wasm
Binary file not shown.
Binary file modified tests/unit/gc/wasm-apps/struct1.wasm
Binary file not shown.
Binary file modified tests/unit/gc/wasm-apps/struct2.wasm
Binary file not shown.
34 changes: 26 additions & 8 deletions tests/unit/gc/wasm-apps/struct2.wast
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
(module
(type $vec (struct (field f32) (field $y (mut f32)) (field $z f32)))

;;(global (ref $vec) (struct.new_canon $vec (f32.const 1) (f32.const 2) (f32.const 3)))
(global (ref $vec) (struct.new_canon_default $vec))
(global (ref $vec) (struct.new $vec (f32.const 1) (f32.const 2) (f32.const 3)))
(global (ref $vec) (struct.new_default $vec))

(func (export "new") (result anyref)
(struct.new_canon_default $vec)
(struct.new_default $vec)
)

(func $get_0 (param $v (ref $vec)) (result f32)
(func $get_0_0 (param $v (ref $vec)) (result f32)
(struct.get 0 0 (local.get $v))
)
(func (export "get_0_0") (result f32)
(call $get_0_0 (struct.new_default $vec))
)
(func $get_vec_0 (param $v (ref $vec)) (result f32)
(struct.get $vec 0 (local.get $v))
)
(func (export "get_0") (result f32)
(call $get_0 (struct.new_canon_default $vec))
(func (export "get_vec_0") (result f32)
(call $get_vec_0 (struct.new_default $vec))
)
(func $get_0_y (param $v (ref $vec)) (result f32)
(struct.get 0 $y (local.get $v))
)
(func (export "get_0_y") (result f32)
(call $get_0_y (struct.new_default $vec))
)
(func $get_vec_y (param $v (ref $vec)) (result f32)
(struct.get $vec $y (local.get $v))
)
(func (export "get_vec_y") (result f32)
(call $get_vec_y (struct.new_default $vec))
)

(func $set_get_y (param $v (ref $vec)) (param $y f32) (result f32)
(struct.set $vec $y (local.get $v) (local.get $y))
(struct.get $vec $y (local.get $v))
)
(func (export "set_get_y") (param $y f32) (result f32)
(call $set_get_y (struct.new_canon_default $vec) (local.get $y))
(call $set_get_y (struct.new_default $vec) (local.get $y))
)

(func $set_get_1 (param $v (ref $vec)) (param $y f32) (result f32)
(struct.set $vec 1 (local.get $v) (local.get $y))
(struct.get $vec $y (local.get $v))
)
(func (export "set_get_1") (param $y f32) (result f32)
(call $set_get_1 (struct.new_canon_default $vec) (local.get $y))
(call $set_get_1 (struct.new_default $vec) (local.get $y))
)
)
Binary file modified tests/unit/gc/wasm-apps/struct3.wasm
Binary file not shown.
Binary file modified tests/unit/gc/wasm-apps/test1.wasm
Binary file not shown.
Binary file modified tests/unit/gc/wasm-apps/test2.wasm
Binary file not shown.
57 changes: 25 additions & 32 deletions tests/unit/gc/wasm-apps/test2.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
(table.set $ta (i32.const 0) (ref.null any))
(table.set $ta (i32.const 1) (ref.null struct))
(table.set $ta (i32.const 2) (ref.null none))
(table.set $ta (i32.const 3) (i31.new (i32.const 7)))
(table.set $ta (i32.const 4) (struct.new_canon_default $st))
(table.set $ta (i32.const 5) (array.new_canon_default $at (i32.const 0)))
(table.set $ta (i32.const 6) (extern.internalize (local.get $x)))
(table.set $ta (i32.const 7) (extern.internalize (ref.null extern)))
(table.set $ta (i32.const 3) (ref.i31 (i32.const 7)))
(table.set $ta (i32.const 4) (struct.new_default $st))
(table.set $ta (i32.const 5) (array.new_default $at (i32.const 0)))
(table.set $ta (i32.const 6) (any.convert_extern (local.get $x)))
(table.set $ta (i32.const 7) (any.convert_extern (ref.null extern)))

(table.set $tf (i32.const 0) (ref.null nofunc))
(table.set $tf (i32.const 1) (ref.null func))
Expand All @@ -27,78 +27,71 @@
(table.set $te (i32.const 0) (ref.null noextern))
(table.set $te (i32.const 1) (ref.null extern))
(table.set $te (i32.const 2) (local.get $x))
(table.set $te (i32.const 3) (extern.externalize (i31.new (i32.const 8))))
(table.set $te (i32.const 4) (extern.externalize (struct.new_canon_default $st)))
(table.set $te (i32.const 5) (extern.externalize (ref.null any)))
(table.set $te (i32.const 3) (extern.convert_any (ref.i31 (i32.const 8))))
(table.set $te (i32.const 4) (extern.convert_any (struct.new_default $st)))
(table.set $te (i32.const 5) (extern.convert_any (ref.null any)))
)

(func (export "ref_test_null_data") (param $i i32) (result i32)
(i32.add
(ref.is_null (table.get $ta (local.get $i)))
(ref.test null none (table.get $ta (local.get $i)))
(ref.test nullref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_any") (param $i i32) (result i32)
(i32.add
(ref.test any (table.get $ta (local.get $i)))
(ref.test null any (table.get $ta (local.get $i)))
(ref.test (ref any) (table.get $ta (local.get $i)))
(ref.test anyref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_eq") (param $i i32) (result i32)
(i32.add
(ref.test eq (table.get $ta (local.get $i)))
(ref.test null eq (table.get $ta (local.get $i)))
(ref.test (ref eq) (table.get $ta (local.get $i)))
(ref.test eqref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_i31") (param $i i32) (result i32)
(i32.add
(ref.test i31 (table.get $ta (local.get $i)))
(ref.test null i31 (table.get $ta (local.get $i)))
(ref.test (ref i31) (table.get $ta (local.get $i)))
(ref.test i31ref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_struct") (param $i i32) (result i32)
(i32.add
(ref.test struct (table.get $ta (local.get $i)))
(ref.test null struct (table.get $ta (local.get $i)))
(ref.test (ref struct) (table.get $ta (local.get $i)))
(ref.test structref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_array") (param $i i32) (result i32)
(i32.add
(ref.test array (table.get $ta (local.get $i)))
(ref.test null array (table.get $ta (local.get $i)))
(ref.test (ref array) (table.get $ta (local.get $i)))
(ref.test arrayref (table.get $ta (local.get $i)))
)
)

(func (export "ref_test_null_func") (param $i i32) (result i32)
(i32.add
(ref.is_null (table.get $tf (local.get $i)))
(ref.test null nofunc (table.get $tf (local.get $i)))
(ref.test (ref null nofunc) (table.get $tf (local.get $i)))
)
)

(func (export "ref_test_func") (param $i i32) (result i32)
(i32.add
(ref.test func (table.get $tf (local.get $i)))
(ref.test null func (table.get $tf (local.get $i)))
(ref.test (ref func) (table.get $tf (local.get $i)))
(ref.test funcref (table.get $tf (local.get $i)))
)
)

(func (export "ref_test_null_extern") (param $i i32) (result i32)
(i32.add
(ref.is_null (table.get $te (local.get $i)))
(ref.test null noextern (table.get $te (local.get $i)))
(ref.test (ref null noextern) (table.get $te (local.get $i)))
)
)

(func (export "ref_test_extern") (param $i i32) (result i32)
(i32.add
(ref.test extern (table.get $te (local.get $i)))
(ref.test null extern (table.get $te (local.get $i)))
(ref.test (ref extern) (table.get $te (local.get $i)))
(ref.test externref (table.get $te (local.get $i)))
)
)
)
Binary file modified tests/unit/gc/wasm-apps/test3.wasm
Binary file not shown.
Loading
Loading