Add unit test suites (#3490)

This commit is contained in:
Zhang, Yi
2024-06-04 11:24:27 +08:00
committed by GitHub
parent 0a80cc4e94
commit 380cd7b0e7
194 changed files with 14104 additions and 34 deletions

View File

@ -0,0 +1,51 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 2.9)
project (test-wamr-gc)
add_definitions (-DRUN_ON_LINUX)
set (WAMR_BUILD_GC 1)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_APP_FRAMEWORK 0)
include (../unit_common.cmake)
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
set (UNIT_SOURCE ${source_all})
set (unit_test_sources
${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}
)
add_executable (gc_test ${unit_test_sources})
target_link_libraries (gc_test gtest_main)
add_custom_command(TARGET gc_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_LIST_DIR}/wasm-apps/*.was*
${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Copy wasm files to directory ${CMAKE_CURRENT_BINARY_DIR}"
)
#gtest_discover_tests(gc_test)

102
tests/unit/gc/gc_test.cc Normal file
View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "gtest/gtest.h"
#include "bh_platform.h"
#include "bh_read_file.h"
#include "wasm_export.h"
class WasmGCTest : public testing::Test
{
private:
std::string get_binary_path()
{
char cwd[1024] = { 0 };
if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
return NULL;
}
char *path_end = strrchr(cwd, '/');
if (path_end != NULL) {
*path_end = '\0';
}
return std::string(cwd);
}
protected:
void SetUp()
{
CWD = get_binary_path();
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
ASSERT_EQ(wasm_runtime_full_init(&init_args), true);
cleanup = true;
}
void TearDown()
{
if (cleanup) {
wasm_runtime_destroy();
}
}
public:
bool load_wasm_file(const char *wasm_file)
{
const char *file;
unsigned char *wasm_file_buf;
uint32 wasm_file_size;
file = strdup((CWD + "/" + wasm_file).c_str());
wasm_file_buf =
(unsigned char *)bh_read_file_to_buffer(file, &wasm_file_size);
if (!wasm_file_buf)
return false;
module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
sizeof(error_buf));
if (!module)
return false;
return true;
}
public:
std::string CWD;
RuntimeInitArgs init_args;
wasm_module_t module = NULL;
wasm_module_inst_t module_inst = NULL;
wasm_function_inst_t func_inst = NULL;
wasm_exec_env_t exec_env = NULL;
char error_buf[128];
char global_heap_buf[512 * 1024];
bool cleanup = true;
};
TEST_F(WasmGCTest, Test_app1)
{
ASSERT_TRUE(load_wasm_file("test1.wasm"));
ASSERT_TRUE(load_wasm_file("test2.wasm"));
ASSERT_TRUE(load_wasm_file("test3.wasm"));
ASSERT_TRUE(load_wasm_file("test4.wasm"));
ASSERT_TRUE(load_wasm_file("test5.wasm"));
ASSERT_TRUE(load_wasm_file("test6.wasm"));
ASSERT_TRUE(load_wasm_file("struct1.wasm"));
ASSERT_TRUE(load_wasm_file("struct2.wasm"));
ASSERT_TRUE(load_wasm_file("struct3.wasm"));
ASSERT_TRUE(load_wasm_file("func1.wasm"));
ASSERT_TRUE(load_wasm_file("func2.wasm"));
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
(module
(type $t (func))
(func (export "test") (param structref i31ref)
(local funcref)
(local funcref)
(local funcref)
(local externref)
(local externref)
(local externref)
(local anyref)
(local eqref)
(local structref)
(local arrayref)
(local i31ref)
(local (ref null 0))
(local (ref null 0))
(local (ref null 0))
(local (ref null 1))
(local (ref null func))
(local (ref null 0))
(local (ref null extern))
(local (ref null any))
(local (ref null eq))
(local (ref null i31))
(local (ref null struct))
local.get 0
ref.test null array
drop
local.get 1
ref.cast i31
drop
)
)

Binary file not shown.

View File

@ -0,0 +1,78 @@
(module
(type $t0 (func))
(type $t1 (func (param (ref null 1))))
(type $t2 (func (param funcref externref (ref func)(ref extern)
anyref eqref structref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 1) (ref $t0) (ref null func)
(ref null extern) (ref null 2) (ref null $t0))
(result (ref null func))))
(type $t3 (func (param i32 i32) (result (ref null 3))))
(type $t4 (func))
(type $t5 (func (param (ref null 3))))
(type $t6 (func (param funcref externref (ref func)(ref extern)
anyref eqref structref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))
(result (ref null func))))
(type $t7 (func (param i32 i32) (result (ref null 4))))
(type $t11 (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null struct)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type $t12 (struct))
(type $t13 (struct (field)))
(type $t14 (struct (field i8)))
(type $t15 (struct (field i8 i8 i8 i8)))
(type $t16 (struct (field $x1 i32) (field $y1 i32)))
(type $t17 (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type $t18 (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type $t19 (struct (field $x2 i32) (field f32 f64) (field $y2 i32)))
(type $t20 (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref structref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type $t21 (struct))
(type $t22 (struct (field)))
(type $t23 (struct (field i8)))
(type $t24 (struct (field i8 i8 i8 i8)))
(type $t25 (struct (field $x3 i32) (field $y3 i32)))
(type $t26 (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type $t27 (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type $t28 (struct (field $x4 i32) (field f32 f64) (field $y4 i32)))
(type $t31 (array i8))
(type $t32 (array i16))
(type $t33 (array i32))
(type $t34 (array i64))
(type $t35 (array f32))
(type $t36 (array f64))
(type $t37 (array anyref))
(type $t38 (array (ref i31)))
(type $t39 (array (ref 0)))
(type $t40 (array (ref null 1)))
(type $t43 (array (mut i8)))
(type $t44 (array (mut i16)))
(type $t45 (array (mut i32)))
(type $t46 (array (mut i64)))
(type $t47 (array (mut i32)))
(type $t48 (array (mut i64)))
(type $t49 (array (mut anyref)))
(type $t50 (array (mut (ref struct))))
(type $t51 (array (mut (ref 0))))
(type $t52 (array (mut (ref null i31))))
)

Binary file not shown.

View File

@ -0,0 +1,91 @@
(module
(type $ftype0 (func (param i32)))
(type $ftype1 (func (param i32 i64) (result i32)))
(type $ftype2 (func (param f32 f64) (result f64)))
(type $t0 (func (param (ref 1) (ref 2) (ref null 1) (ref null 2))))
(type $t1 (func (param funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 3) (ref null $t0))
(result (ref null func))))
(type $t2 (func (param i32 i32) (result (ref null 4))))
;; Duplicated types
(type $t3 (func))
(type $t4 (func (param (ref 1) (ref 2) (ref null 1) (ref null 2))))
(type $t5 (func (param funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 3) (ref null $t0))
(result (ref null func))))
(type $t6 (func (param i32 i32) (result (ref null 4))))
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x1 i32) (field $y1 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x2 i32) (field f32 f64) (field $y2 i32)))
;; Duplicated types
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x3 i32) (field $y3 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x4 i32) (field f32 f64) (field $y4 i32)))
(type (array i8))
(type (array i16))
(type (array i32))
(type (array i64))
(type (array f32))
(type (array f64))
(type (array anyref))
(type (array (ref array)))
(type (array (ref 0)))
(type (array (ref null 1)))
(type (array (mut i8)))
(type (array (mut i16)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut anyref)))
(type (array (mut (ref array))))
(type (array (mut (ref 0))))
(type (array (mut (ref null i31))))
(global $g0 funcref (ref.func $f0))
(global $g1 externref (ref.null extern))
(global $g2 anyref (ref.null any))
(global $g3 eqref (ref.null array))
(global $g4 arrayref (ref.null array))
(global $g5 i31ref (ref.null i31))
(func $f0)
)

Binary file not shown.

View File

@ -0,0 +1,10 @@
(module
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x1 i32) (field $y1 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x2 i32) (field f32 f64) (field $y2 i32)))
)

Binary file not shown.

View File

@ -0,0 +1,33 @@
(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))
(func (export "new") (result anyref)
(struct.new_canon_default $vec)
)
(func $get_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 $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))
)
(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))
)
)

Binary file not shown.

View File

@ -0,0 +1,9 @@
(module
(type $t (struct (field i32 (mut i32))))
(func (export "struct.get-null")
(local (ref null $t)) (drop (struct.get $t 1 (local.get 0)))
)
(func (export "struct.set-null")
(local (ref null $t)) (struct.set $t 1 (local.get 0) (i32.const 0))
)
)

Binary file not shown.

View File

@ -0,0 +1,108 @@
(module
(type $ftype0 (func (param i32)))
(type $ftype1 (func (param i32 i64) (result i32)))
(type $ftype2 (func (param f32 f64) (result f64)))
(type $t0 (func (param (ref 1) (ref 2) (ref null 1) (ref null 2))))
(type $t1 (func (param funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 3) (ref null $t0))
(result (ref null func))))
(type $t2 (func (param i32 i32) (result (ref null 4))))
;; Duplicated types
(type $t3 (func))
(type $t4 (func (param (ref 1) (ref 2) (ref null 1) (ref null 2))))
(type $t5 (func (param funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 3) (ref null $t0))
(result (ref null func))))
(type $t6 (func (param i32 i32) (result (ref null 4))))
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x1 i32) (field $y1 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x2 i32) (field f32 f64) (field $y2 i32)))
;; Duplicated types
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func)(ref extern)
anyref eqref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x3 i32) (field $y3 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x4 i32) (field f32 f64) (field $y4 i32)))
(type (array i8))
(type (array i16))
(type (array i32))
(type (array i64))
(type (array f32))
(type (array f64))
(type (array anyref))
(type (array (ref array)))
(type (array (ref 0)))
(type (array (ref null 1)))
(type (array (mut i8)))
(type (array (mut i16)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut anyref)))
(type (array (mut (ref array))))
(type (array (mut (ref 0))))
(type (array (mut (ref null i31))))
(table 10 funcref)
(table 20 externref)
;; non-defaultable element type
;; (table 30 (ref func))
;; (table 40 (ref extern))
(table 50 anyref)
(table 60 eqref)
(table 100 arrayref)
(table 100 i31ref)
(table 100 (ref null 0))
(table 100 (ref null 2))
(table 100 (ref null func))
(table 100 (ref null extern))
(table 100 (ref null any))
(table 100 (ref null eq))
(table 100 (ref null i31))
(table 100 (ref null array))
;; non-defaultable element type
;; (table 100 (ref 0))
;; (table 100 (ref $t0))
;; (table 100 (ref 3))
;; (table 100 (ref $t0))
(table 100 (ref null func))
(table 100 (ref null extern))
(table 100 (ref null 5))
(table 100 (ref null $t0))
)

Binary file not shown.

View File

@ -0,0 +1,117 @@
(module
(type $t (func))
(type $t0 (func (param (ref null $t) (ref $t) (ref null 0) (ref 0) (ref null 1) (ref 1))))
(type $t1 (func (param funcref externref anyref eqref
i31ref structref arrayref
nullref nullfuncref nullexternref
(ref null func) (ref null extern) (ref null any) (ref null eq)
(ref null i31) (ref null struct) (ref null array)
(ref null none) (ref null nofunc) (ref null noextern)
(ref func) (ref extern) (ref any) (ref eq)
(ref i31) (ref struct) (ref array)
(ref none) (ref nofunc) (ref noextern)
(ref null 0) (ref null $t0) (ref null $t1)
(ref null func) (ref null extern) (ref null any) (ref null eq)
(ref null i31) (ref null struct) (ref null array)
(ref $t) (ref $t0) (ref $t1)
(ref func) (ref extern) (ref any) (ref eq)
(ref i31) (ref struct) (ref array))
(result (ref null func) (ref null extern) (ref $t0))))
(type $t2 (func (param i32 i32) (result (ref null $t1))))
;; Duplicated types
(type $t3 (func))
(type $t4 (func (param (ref null $t) (ref $t) (ref null 0) (ref 0) (ref null 1) (ref 1))))
(type $t5 (func (param funcref externref anyref eqref
i31ref structref arrayref
nullref nullfuncref nullexternref
(ref null func) (ref null extern) (ref null any) (ref null eq)
(ref null i31) (ref null struct) (ref null array)
(ref null none) (ref null nofunc) (ref null noextern)
(ref func) (ref extern) (ref any) (ref eq)
(ref i31) (ref struct) (ref array)
(ref none) (ref nofunc) (ref noextern)
(ref null 0) (ref null $t0) (ref null $t1)
(ref null func) (ref null extern) (ref null any) (ref null eq)
(ref null i31) (ref null struct) (ref null array)
(ref $t) (ref $t0) (ref $t1)
(ref func) (ref extern) (ref any) (ref eq)
(ref i31) (ref struct) (ref array))
(result (ref null func) (ref null extern) (ref $t0))))
(type $t6 (func (param i32 i32) (result (ref null $t1))))
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func) (ref extern)
anyref eqref structref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null struct) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x1 i32) (field $y1 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x2 i32) (field f32 f64) (field $y2 i32)))
;; Duplicated types
(type (struct (field i8 (mut i16) (mut i32) i64 f32 f64
funcref externref (ref func) (ref extern)
anyref eqref structref arrayref i31ref
(ref null 0) (ref null 2) (ref null func) (ref null extern)
(ref null any) (ref null eq) (ref null i31) (ref null struct) (ref null array)
(ref 0) (ref $t0) (ref 3) (ref $t0) (ref null func)
(ref null extern) (ref null 5) (ref null $t0))))
(type (struct))
(type (struct (field)))
(type (struct (field i8)))
(type (struct (field i8 i8 i8 i8)))
(type (struct (field $x3 i32) (field $y3 i32)))
(type (struct (field i8 i16 i32 i64 f32 f64 anyref funcref (ref 0) (ref null 1))))
(type (struct (field i32 i64 i8) (field) (field) (field (ref null i31) anyref)))
(type (struct (field $x4 i32) (field f32 f64) (field $y4 i32)))
(type (array i8))
(type (array i16))
(type (array i32))
(type (array i64))
(type (array f32))
(type (array f64))
(type (array anyref))
(type (array (ref struct)))
(type (array (ref array)))
(type (array (ref null struct)))
(type (array (ref null array)))
(type (array (ref 0)))
(type (array (ref null 1)))
(type (array (mut i8)))
(type (array (mut i16)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut i32)))
(type (array (mut i64)))
(type (array (mut anyref)))
(type (array (mut (ref struct))))
(type (array (mut (ref array))))
(type (array (mut (ref null struct))))
(type (array (mut (ref null array))))
(type (array (mut (ref 0))))
(type (array (mut (ref null i31))))
;; sub types
(type $e0 (sub (array i32)))
(type $e1 (sub $e0 (array i32)))
(type $e2 (sub (array anyref)))
(type $e3 (sub (array (ref null $e0))))
(type $e4 (sub (array (ref $e1))))
(type $e5 (sub $e1 (array i32)))
(type $m1 (sub (array (mut i32))))
(type $m2 (sub $m1 (array (mut i32))))
)

Binary file not shown.

View File

@ -0,0 +1,104 @@
(module
(type $ft (func))
(type $st (struct))
(type $at (array i8))
(table $ta 10 anyref)
(table $tf 10 funcref)
(table $te 10 externref)
(elem declare func $f)
(func $f)
(func (export "init") (param $x externref)
(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 $tf (i32.const 0) (ref.null nofunc))
(table.set $tf (i32.const 1) (ref.null func))
(table.set $tf (i32.const 2) (ref.func $f))
(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)))
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
(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)))
)
)
)

Binary file not shown.

View File

@ -0,0 +1,146 @@
(module
(type $t0 (sub (struct)))
(type $t1 (sub $t0 (struct (field i32))))
(type $t1' (sub $t0 (struct (field i32))))
(type $t2 (sub $t1 (struct (field i32 i32))))
(type $t2' (sub $t1' (struct (field i32 i32))))
(type $t3 (sub $t0 (struct (field i32 i32))))
(type $t0' (sub $t0 (struct)))
(type $t4 (sub $t0' (struct (field i32 i32))))
(table 20 (ref null struct))
(func $init
(table.set (i32.const 0) (struct.new_canon_default $t0))
(table.set (i32.const 10) (struct.new_canon_default $t0))
(table.set (i32.const 1) (struct.new_canon_default $t1))
(table.set (i32.const 11) (struct.new_canon_default $t1'))
(table.set (i32.const 2) (struct.new_canon_default $t2))
(table.set (i32.const 12) (struct.new_canon_default $t2'))
(table.set (i32.const 3) (struct.new_canon_default $t3))
(table.set (i32.const 4) (struct.new_canon_default $t4))
)
(func (export "test-sub")
(call $init)
(block $l
;; must hold
(br_if $l (i32.eqz (ref.test null $t0 (ref.null struct))))
(br_if $l (i32.eqz (ref.test null $t0 (ref.null $t0))))
(br_if $l (i32.eqz (ref.test null $t0 (ref.null $t1))))
(br_if $l (i32.eqz (ref.test null $t0 (ref.null $t2))))
(br_if $l (i32.eqz (ref.test null $t0 (ref.null $t3))))
(br_if $l (i32.eqz (ref.test null $t0 (ref.null $t4))))
(br_if $l (i32.eqz (ref.test null $t0 (table.get (i32.const 0)))))
(br_if $l (i32.eqz (ref.test null $t0 (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test null $t0 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test null $t0 (table.get (i32.const 3)))))
(br_if $l (i32.eqz (ref.test null $t0 (table.get (i32.const 4)))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null struct))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null $t0))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null $t1))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null $t2))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null $t3))))
(br_if $l (i32.eqz (ref.test null $t1 (ref.null $t4))))
(br_if $l (i32.eqz (ref.test null $t1 (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test null $t1 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null struct))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null $t0))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null $t1))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null $t2))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null $t3))))
(br_if $l (i32.eqz (ref.test null $t2 (ref.null $t4))))
(br_if $l (i32.eqz (ref.test null $t2 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null struct))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null $t0))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null $t1))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null $t2))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null $t3))))
(br_if $l (i32.eqz (ref.test null $t3 (ref.null $t4))))
(br_if $l (i32.eqz (ref.test null $t3 (table.get (i32.const 3)))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null struct))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null $t0))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null $t1))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null $t2))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null $t3))))
(br_if $l (i32.eqz (ref.test null $t4 (ref.null $t4))))
(br_if $l (i32.eqz (ref.test null $t4 (table.get (i32.const 4)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 0)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 3)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 4)))))
(br_if $l (i32.eqz (ref.test $t1 (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test $t1 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t2 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t3 (table.get (i32.const 3)))))
(br_if $l (i32.eqz (ref.test $t4 (table.get (i32.const 4)))))
;; must not hold
(br_if $l (ref.test $t0 (ref.null struct)))
(br_if $l (ref.test $t1 (ref.null struct)))
(br_if $l (ref.test $t2 (ref.null struct)))
(br_if $l (ref.test $t3 (ref.null struct)))
(br_if $l (ref.test $t4 (ref.null struct)))
(br_if $l (ref.test $t1 (table.get (i32.const 0))))
(br_if $l (ref.test $t1 (table.get (i32.const 3))))
(br_if $l (ref.test $t1 (table.get (i32.const 4))))
(br_if $l (ref.test $t2 (table.get (i32.const 0))))
(br_if $l (ref.test $t2 (table.get (i32.const 1))))
(br_if $l (ref.test $t2 (table.get (i32.const 3))))
(br_if $l (ref.test $t2 (table.get (i32.const 4))))
(br_if $l (ref.test $t3 (table.get (i32.const 0))))
(br_if $l (ref.test $t3 (table.get (i32.const 1))))
(br_if $l (ref.test $t3 (table.get (i32.const 2))))
(br_if $l (ref.test $t3 (table.get (i32.const 4))))
(br_if $l (ref.test $t4 (table.get (i32.const 0))))
(br_if $l (ref.test $t4 (table.get (i32.const 1))))
(br_if $l (ref.test $t4 (table.get (i32.const 2))))
(br_if $l (ref.test $t4 (table.get (i32.const 3))))
(return)
)
(unreachable)
)
(func (export "test-canon")
(call $init)
(block $l
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 0)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 3)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 4)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 10)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 11)))))
(br_if $l (i32.eqz (ref.test $t0 (table.get (i32.const 12)))))
(br_if $l (i32.eqz (ref.test $t1' (table.get (i32.const 1)))))
(br_if $l (i32.eqz (ref.test $t1' (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t1 (table.get (i32.const 11)))))
(br_if $l (i32.eqz (ref.test $t1 (table.get (i32.const 12)))))
(br_if $l (i32.eqz (ref.test $t2' (table.get (i32.const 2)))))
(br_if $l (i32.eqz (ref.test $t2 (table.get (i32.const 12)))))
(return)
)
(unreachable)
)
)

Binary file not shown.

View File

@ -0,0 +1,46 @@
(module
(type $ft (func))
(type $st (struct))
(type $at (array i8))
(table 10 anyref)
(elem declare func $f)
(func $f)
(func (export "init") (param $x externref)
(table.set (i32.const 0) (ref.null any))
(table.set (i32.const 1) (i31.new (i32.const 7)))
(table.set (i32.const 2) (struct.new_canon_default $st))
(table.set (i32.const 3) (array.new_canon_default $at (i32.const 0)))
(table.set (i32.const 4) (extern.internalize (local.get $x)))
(table.set (i32.const 5) (ref.null i31))
(table.set (i32.const 6) (ref.null struct))
(table.set (i32.const 7) (ref.null none))
)
(func (export "ref_cast_non_null") (param $i i32)
(drop (ref.as_non_null (table.get (local.get $i))))
(drop (ref.cast null any (table.get (local.get $i))))
)
(func (export "ref_cast_null") (param $i i32)
(drop (ref.cast null any (table.get (local.get $i))))
(drop (ref.cast null struct (table.get (local.get $i))))
(drop (ref.cast null array (table.get (local.get $i))))
(drop (ref.cast null i31 (table.get (local.get $i))))
(drop (ref.cast null none (table.get (local.get $i))))
)
(func (export "ref_cast_i31") (param $i i32)
(drop (ref.cast i31 (table.get (local.get $i))))
(drop (ref.cast null i31 (table.get (local.get $i))))
)
(func (export "ref_cast_struct") (param $i i32)
(drop (ref.cast struct (table.get (local.get $i))))
(drop (ref.cast null struct (table.get (local.get $i))))
)
(func (export "ref_cast_array") (param $i i32)
(drop (ref.cast array (table.get (local.get $i))))
(drop (ref.cast null array (table.get (local.get $i))))
)
)

Binary file not shown.

View File

@ -0,0 +1,85 @@
(module
(type $t0 (sub (struct)))
(type $t1 (sub $t0 (struct (field i32))))
(type $t1' (sub $t0 (struct (field i32))))
(type $t2 (sub $t1 (struct (field i32 i32))))
(type $t2' (sub $t1' (struct (field i32 i32))))
(type $t3 (sub $t0 (struct (field i32 i32))))
(type $t0' (sub $t0 (struct)))
(type $t4 (sub $t0' (struct (field i32 i32))))
(table 20 (ref null struct))
(func $init
(table.set (i32.const 0) (struct.new_canon_default $t0))
(table.set (i32.const 10) (struct.new_canon_default $t0))
(table.set (i32.const 1) (struct.new_canon_default $t1))
(table.set (i32.const 11) (struct.new_canon_default $t1'))
(table.set (i32.const 2) (struct.new_canon_default $t2))
(table.set (i32.const 12) (struct.new_canon_default $t2'))
(table.set (i32.const 3) (struct.new_canon_default $t3))
(table.set (i32.const 4) (struct.new_canon_default $t4))
)
(func (export "test-sub")
(call $init)
(drop (ref.cast null $t0 (ref.null struct)))
(drop (ref.cast null $t0 (table.get (i32.const 0))))
(drop (ref.cast null $t0 (table.get (i32.const 1))))
(drop (ref.cast null $t0 (table.get (i32.const 2))))
(drop (ref.cast null $t0 (table.get (i32.const 3))))
(drop (ref.cast null $t0 (table.get (i32.const 4))))
(drop (ref.cast null $t0 (ref.null struct)))
(drop (ref.cast null $t1 (table.get (i32.const 1))))
(drop (ref.cast null $t1 (table.get (i32.const 2))))
(drop (ref.cast null $t0 (ref.null struct)))
(drop (ref.cast null $t2 (table.get (i32.const 2))))
(drop (ref.cast null $t0 (ref.null struct)))
(drop (ref.cast null $t3 (table.get (i32.const 3))))
(drop (ref.cast null $t4 (table.get (i32.const 4))))
(drop (ref.cast $t0 (table.get (i32.const 0))))
(drop (ref.cast $t0 (table.get (i32.const 1))))
(drop (ref.cast $t0 (table.get (i32.const 2))))
(drop (ref.cast $t0 (table.get (i32.const 3))))
(drop (ref.cast $t0 (table.get (i32.const 4))))
(drop (ref.cast $t1 (table.get (i32.const 1))))
(drop (ref.cast $t1 (table.get (i32.const 2))))
(drop (ref.cast $t2 (table.get (i32.const 2))))
(drop (ref.cast $t3 (table.get (i32.const 3))))
(drop (ref.cast $t4 (table.get (i32.const 4))))
)
(func (export "test-canon")
(call $init)
(drop (ref.cast $t0 (table.get (i32.const 0))))
(drop (ref.cast $t0 (table.get (i32.const 1))))
(drop (ref.cast $t0 (table.get (i32.const 2))))
(drop (ref.cast $t0 (table.get (i32.const 3))))
(drop (ref.cast $t0 (table.get (i32.const 4))))
(drop (ref.cast $t0 (table.get (i32.const 10))))
(drop (ref.cast $t0 (table.get (i32.const 11))))
(drop (ref.cast $t0 (table.get (i32.const 12))))
(drop (ref.cast $t1' (table.get (i32.const 1))))
(drop (ref.cast $t1' (table.get (i32.const 2))))
(drop (ref.cast $t1 (table.get (i32.const 11))))
(drop (ref.cast $t1 (table.get (i32.const 12))))
(drop (ref.cast $t2' (table.get (i32.const 2))))
(drop (ref.cast $t2 (table.get (i32.const 12))))
)
)

Binary file not shown.

View File

@ -0,0 +1,27 @@
(module
(type $st (sub (struct)))
(type $st' (sub (struct (field i32))))
(type $at (array i8))
(type $st-sub1 (sub $st (struct)))
(type $st-sub2 (sub $st (struct)))
(type $st'-sub1 (sub $st' (struct (field i32))))
(type $st'-sub2 (sub $st' (struct (field i32))))
(table 20 (ref null eq))
(func (export "init")
(table.set (i32.const 0) (ref.null eq))
(table.set (i32.const 1) (ref.null i31))
(table.set (i32.const 2) (i31.new (i32.const 7)))
(table.set (i32.const 3) (i31.new (i32.const 7)))
(table.set (i32.const 4) (i31.new (i32.const 8)))
(table.set (i32.const 5) (struct.new_canon_default $st))
(table.set (i32.const 6) (struct.new_canon_default $st))
(table.set (i32.const 7) (array.new_canon_default $at (i32.const 0)))
(table.set (i32.const 8) (array.new_canon_default $at (i32.const 0)))
)
(func (export "eq") (param $i i32) (param $j i32) (result i32)
(ref.eq (table.get (local.get $i)) (table.get (local.get $j)))
)
)