Add unit test suites (#3490)
This commit is contained in:
2
tests/unit/wasm-vm/.gitignore
vendored
Normal file
2
tests/unit/wasm-vm/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
wasm-apps/app[123]/*.wat
|
||||
wasm-apps/app[123]/*.wasm
|
||||
53
tests/unit/wasm-vm/CMakeLists.txt
Normal file
53
tests/unit/wasm-vm/CMakeLists.txt
Normal file
@ -0,0 +1,53 @@
|
||||
# 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-wasm-vm)
|
||||
|
||||
add_definitions (-DRUN_ON_LINUX)
|
||||
|
||||
add_definitions (-Dattr_container_malloc=malloc)
|
||||
add_definitions (-Dattr_container_free=free)
|
||||
|
||||
set (WAMR_BUILD_APP_FRAMEWORK 1)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
|
||||
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}
|
||||
${PLATFORM_SHARED_SOURCE}
|
||||
${UTILS_SHARED_SOURCE}
|
||||
${MEM_ALLOC_SHARED_SOURCE}
|
||||
${LIB_HOST_AGENT_SOURCE}
|
||||
${NATIVE_INTERFACE_SOURCE}
|
||||
${LIBC_BUILTIN_SOURCE}
|
||||
${LIBC_WASI_SOURCE}
|
||||
${IWASM_COMMON_SOURCE}
|
||||
${IWASM_INTERP_SOURCE}
|
||||
${IWASM_AOT_SOURCE}
|
||||
${IWASM_COMPL_SOURCE}
|
||||
${WASM_APP_LIB_SOURCE_ALL}
|
||||
${UNCOMMON_SHARED_SOURCE}
|
||||
)
|
||||
|
||||
# Now simply link against gtest or gtest_main as needed. Eg
|
||||
add_executable(wasm_vm_test ${unit_test_sources})
|
||||
|
||||
target_link_libraries(wasm_vm_test ${LLVM_AVAILABLE_LIBS} gtest_main)
|
||||
|
||||
add_custom_command(TARGET wasm_vm_test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/app4/*.wasm
|
||||
${PROJECT_BINARY_DIR}/
|
||||
COMMENT "Copy wasm files to the output directory"
|
||||
)
|
||||
|
||||
gtest_discover_tests(wasm_vm_test)
|
||||
106
tests/unit/wasm-vm/wasm-apps/app1.wast
Normal file
106
tests/unit/wasm-vm/wasm-apps/app1.wast
Normal file
@ -0,0 +1,106 @@
|
||||
(module
|
||||
(type $0 (func (param i32) (result i32)))
|
||||
(type $1 (func (param i32 i32) (result i32)))
|
||||
(type $2 (func (param i32)))
|
||||
(type $3 (func (param i32 i32 i32) (result i32)))
|
||||
(type $4 (func))
|
||||
(type $5 (func (result i32)))
|
||||
(import "env" "malloc" (func $13 (param i32) (result i32)))
|
||||
(import "env" "calloc" (func $14 (param i32 i32) (result i32)))
|
||||
(import "env" "free" (func $15 (param i32)))
|
||||
(import "env" "memcpy" (func $16 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "strdup" (func $17 (param i32) (result i32)))
|
||||
(memory $6 1)
|
||||
(global $7 i32 (i32.const 1024))
|
||||
(global $8 i32 (i32.const 1024))
|
||||
(global $9 i32 (i32.const 1024))
|
||||
(global $10 i32 (i32.const 5120))
|
||||
(global $11 i32 (i32.const 0))
|
||||
(global $12 i32 (i32.const 1))
|
||||
(export "memory" (memory $6))
|
||||
(export "__wasm_call_ctors" (func $18))
|
||||
(export "on_init" (func $18))
|
||||
(export "my_sqrt" (func $19))
|
||||
(export "null_pointer" (func $20))
|
||||
(export "my_malloc" (func $21))
|
||||
(export "my_calloc" (func $22))
|
||||
(export "my_free" (func $23))
|
||||
(export "my_memcpy" (func $24))
|
||||
(export "my_strdup" (func $25))
|
||||
(export "__dso_handle" (global $7))
|
||||
(export "__data_end" (global $8))
|
||||
(export "__global_base" (global $9))
|
||||
(export "__heap_base" (global $10))
|
||||
(export "__memory_base" (global $11))
|
||||
(export "__table_base" (global $12))
|
||||
|
||||
(func $18 (type $4)
|
||||
nop
|
||||
)
|
||||
|
||||
(func $19 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $1
|
||||
local.get $1
|
||||
i32.mul
|
||||
local.get $0
|
||||
local.get $0
|
||||
i32.mul
|
||||
i32.add
|
||||
)
|
||||
|
||||
(func $20 (type $5)
|
||||
(result i32)
|
||||
i32.const 0
|
||||
)
|
||||
|
||||
(func $21 (type $0)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $13
|
||||
)
|
||||
|
||||
(func $22 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
call $14
|
||||
)
|
||||
|
||||
(func $23 (type $2)
|
||||
(param $0 i32)
|
||||
local.get $0
|
||||
call $15
|
||||
)
|
||||
|
||||
(func $24 (type $3)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $16
|
||||
)
|
||||
|
||||
(func $25 (type $0)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $17
|
||||
)
|
||||
|
||||
;;(custom_section "producers"
|
||||
;; (after code)
|
||||
;; "\01\0cprocessed-by\01\05clangV11.0.0 (ht"
|
||||
;; "tps://github.com/llvm/llvm-proje"
|
||||
;; "ct 176249bd6732a8044d457092ed932"
|
||||
;; "768724a6f06)")
|
||||
|
||||
)
|
||||
56
tests/unit/wasm-vm/wasm-apps/app1/main.c
Normal file
56
tests/unit/wasm-vm/wasm-apps/app1/main.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
on_init()
|
||||
{}
|
||||
|
||||
int
|
||||
my_sqrt(int x, int y)
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
void *
|
||||
null_pointer()
|
||||
{
|
||||
void *ptr = NULL;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
my_malloc(int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *
|
||||
my_calloc(int nmemb, int size)
|
||||
{
|
||||
return calloc(nmemb, size);
|
||||
}
|
||||
|
||||
void
|
||||
my_free(void *ptr)
|
||||
{
|
||||
return free(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
my_memcpy(void *dst, void *src, int size)
|
||||
{
|
||||
return memcpy(dst, src, size);
|
||||
}
|
||||
|
||||
char *
|
||||
my_strdup(const char *s)
|
||||
{
|
||||
return strdup(s);
|
||||
}
|
||||
54
tests/unit/wasm-vm/wasm-apps/app1_wasm.h
Normal file
54
tests/unit/wasm-vm/wasm-apps/app1_wasm.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
unsigned char app1_wasm[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x1E, 0x06, 0x60,
|
||||
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||
0x7F, 0x00, 0x60, 0x03, 0x7F, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x00, 0x00,
|
||||
0x60, 0x00, 0x01, 0x7F, 0x02, 0x40, 0x05, 0x03, 0x65, 0x6E, 0x76, 0x06,
|
||||
0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76,
|
||||
0x06, 0x63, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x01, 0x03, 0x65, 0x6E,
|
||||
0x76, 0x04, 0x66, 0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76,
|
||||
0x06, 0x6D, 0x65, 0x6D, 0x63, 0x70, 0x79, 0x00, 0x03, 0x03, 0x65, 0x6E,
|
||||
0x76, 0x06, 0x73, 0x74, 0x72, 0x64, 0x75, 0x70, 0x00, 0x00, 0x03, 0x09,
|
||||
0x08, 0x04, 0x01, 0x05, 0x00, 0x01, 0x02, 0x03, 0x00, 0x05, 0x03, 0x01,
|
||||
0x00, 0x01, 0x06, 0x23, 0x06, 0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0x80, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0x00, 0x0B, 0x7F, 0x00,
|
||||
0x41, 0x01, 0x0B, 0x07, 0xD4, 0x01, 0x10, 0x06, 0x6D, 0x65, 0x6D, 0x6F,
|
||||
0x72, 0x79, 0x02, 0x00, 0x11, 0x5F, 0x5F, 0x77, 0x61, 0x73, 0x6D, 0x5F,
|
||||
0x63, 0x61, 0x6C, 0x6C, 0x5F, 0x63, 0x74, 0x6F, 0x72, 0x73, 0x00, 0x05,
|
||||
0x07, 0x6F, 0x6E, 0x5F, 0x69, 0x6E, 0x69, 0x74, 0x00, 0x05, 0x07, 0x6D,
|
||||
0x79, 0x5F, 0x73, 0x71, 0x72, 0x74, 0x00, 0x06, 0x0C, 0x6E, 0x75, 0x6C,
|
||||
0x6C, 0x5F, 0x70, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x00, 0x07, 0x09,
|
||||
0x6D, 0x79, 0x5F, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x08, 0x09,
|
||||
0x6D, 0x79, 0x5F, 0x63, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x09, 0x07,
|
||||
0x6D, 0x79, 0x5F, 0x66, 0x72, 0x65, 0x65, 0x00, 0x0A, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x6D, 0x65, 0x6D, 0x63, 0x70, 0x79, 0x00, 0x0B, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x73, 0x74, 0x72, 0x64, 0x75, 0x70, 0x00, 0x0C, 0x0C, 0x5F, 0x5F,
|
||||
0x64, 0x73, 0x6F, 0x5F, 0x68, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x03, 0x00,
|
||||
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
|
||||
0x01, 0x0D, 0x5F, 0x5F, 0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x5F, 0x62,
|
||||
0x61, 0x73, 0x65, 0x03, 0x02, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70,
|
||||
0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x03, 0x0D, 0x5F, 0x5F, 0x6D, 0x65,
|
||||
0x6D, 0x6F, 0x72, 0x79, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x04, 0x0C,
|
||||
0x5F, 0x5F, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x5F, 0x62, 0x61, 0x73, 0x65,
|
||||
0x03, 0x05, 0x0A, 0x41, 0x08, 0x03, 0x00, 0x01, 0x0B, 0x0D, 0x00, 0x20,
|
||||
0x01, 0x20, 0x01, 0x6C, 0x20, 0x00, 0x20, 0x00, 0x6C, 0x6A, 0x0B, 0x04,
|
||||
0x00, 0x41, 0x00, 0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x00, 0x0B, 0x08,
|
||||
0x00, 0x20, 0x00, 0x20, 0x01, 0x10, 0x01, 0x0B, 0x06, 0x00, 0x20, 0x00,
|
||||
0x10, 0x02, 0x0B, 0x0A, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10,
|
||||
0x03, 0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x04, 0x0B, 0x00, 0x76, 0x09,
|
||||
0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x73, 0x01, 0x0C, 0x70,
|
||||
0x72, 0x6F, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2D, 0x62, 0x79, 0x01,
|
||||
0x05, 0x63, 0x6C, 0x61, 0x6E, 0x67, 0x56, 0x31, 0x31, 0x2E, 0x30, 0x2E,
|
||||
0x30, 0x20, 0x28, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F, 0x67,
|
||||
0x69, 0x74, 0x68, 0x75, 0x62, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x6C, 0x6C,
|
||||
0x76, 0x6D, 0x2F, 0x6C, 0x6C, 0x76, 0x6D, 0x2D, 0x70, 0x72, 0x6F, 0x6A,
|
||||
0x65, 0x63, 0x74, 0x20, 0x31, 0x37, 0x36, 0x32, 0x34, 0x39, 0x62, 0x64,
|
||||
0x36, 0x37, 0x33, 0x32, 0x61, 0x38, 0x30, 0x34, 0x34, 0x64, 0x34, 0x35,
|
||||
0x37, 0x30, 0x39, 0x32, 0x65, 0x64, 0x39, 0x33, 0x32, 0x37, 0x36, 0x38,
|
||||
0x37, 0x32, 0x34, 0x61, 0x36, 0x66, 0x30, 0x36, 0x29
|
||||
};
|
||||
311
tests/unit/wasm-vm/wasm-apps/app2.wast
Normal file
311
tests/unit/wasm-vm/wasm-apps/app2.wast
Normal file
@ -0,0 +1,311 @@
|
||||
(module
|
||||
(type $0 (func (param i32 i32 i32) (result i32)))
|
||||
(type $1 (func (param i32 i32) (result i32)))
|
||||
(type $2 (func (param i32) (result i32)))
|
||||
(type $3 (func (param i32)))
|
||||
(type $4 (func (param i32 i32 i32 i32) (result i32)))
|
||||
(type $5 (func))
|
||||
(type $6 (func (result i32)))
|
||||
(import "env" "malloc" (func $15 (param i32) (result i32)))
|
||||
(import "env" "calloc" (func $16 (param i32 i32) (result i32)))
|
||||
(import "env" "free" (func $17 (param i32)))
|
||||
(import "env" "memcpy" (func $18 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "strdup" (func $19 (param i32) (result i32)))
|
||||
(import "env" "memcmp" (func $20 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "printf" (func $21 (param i32 i32) (result i32)))
|
||||
(import "env" "sprintf" (func $22 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "snprintf" (func $23 (param i32 i32 i32 i32) (result i32)))
|
||||
(import "env" "puts" (func $24 (param i32) (result i32)))
|
||||
(import "env" "putchar" (func $25 (param i32) (result i32)))
|
||||
(import "env" "memmove" (func $26 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "memset" (func $27 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "strchr" (func $28 (param i32 i32) (result i32)))
|
||||
(import "env" "strcmp" (func $29 (param i32 i32) (result i32)))
|
||||
(import "env" "strcpy" (func $30 (param i32 i32) (result i32)))
|
||||
(import "env" "strlen" (func $31 (param i32) (result i32)))
|
||||
(import "env" "strncmp" (func $32 (param i32 i32 i32) (result i32)))
|
||||
(import "env" "strncpy" (func $33 (param i32 i32 i32) (result i32)))
|
||||
(memory $7 1)
|
||||
(global $8 (mut i32) (i32.const 5120))
|
||||
(global $9 i32 (i32.const 1024))
|
||||
(global $10 i32 (i32.const 1024))
|
||||
(global $11 i32 (i32.const 1024))
|
||||
(global $12 i32 (i32.const 5120))
|
||||
(global $13 i32 (i32.const 0))
|
||||
(global $14 i32 (i32.const 1))
|
||||
(export "memory" (memory $7))
|
||||
(export "__wasm_call_ctors" (func $34))
|
||||
(export "on_init" (func $34))
|
||||
(export "my_sqrt" (func $35))
|
||||
(export "null_pointer" (func $36))
|
||||
(export "my_malloc" (func $37))
|
||||
(export "my_calloc" (func $38))
|
||||
(export "my_free" (func $39))
|
||||
(export "my_memcpy" (func $40))
|
||||
(export "my_strdup" (func $41))
|
||||
(export "my_memcmp" (func $42))
|
||||
(export "my_printf" (func $43))
|
||||
(export "my_sprintf" (func $44))
|
||||
(export "my_snprintf" (func $45))
|
||||
(export "my_puts" (func $46))
|
||||
(export "my_putchar" (func $47))
|
||||
(export "my_memmove" (func $48))
|
||||
(export "my_memset" (func $49))
|
||||
(export "my_strchr" (func $50))
|
||||
(export "my_strcmp" (func $51))
|
||||
(export "my_strcpy" (func $52))
|
||||
(export "my_strlen" (func $53))
|
||||
(export "my_strncmp" (func $54))
|
||||
(export "my_strncpy" (func $55))
|
||||
(export "__dso_handle" (global $9))
|
||||
(export "__data_end" (global $10))
|
||||
(export "__global_base" (global $11))
|
||||
(export "__heap_base" (global $12))
|
||||
(export "__memory_base" (global $13))
|
||||
(export "__table_base" (global $14))
|
||||
|
||||
(func $34 (type $5)
|
||||
nop
|
||||
)
|
||||
|
||||
(func $35 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $1
|
||||
local.get $1
|
||||
i32.mul
|
||||
local.get $0
|
||||
local.get $0
|
||||
i32.mul
|
||||
i32.add
|
||||
)
|
||||
|
||||
(func $36 (type $6)
|
||||
(result i32)
|
||||
i32.const 0
|
||||
)
|
||||
|
||||
(func $37 (type $2)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $15
|
||||
)
|
||||
|
||||
(func $38 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
call $16
|
||||
)
|
||||
|
||||
(func $39 (type $3)
|
||||
(param $0 i32)
|
||||
local.get $0
|
||||
call $17
|
||||
)
|
||||
|
||||
(func $40 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $18
|
||||
)
|
||||
|
||||
(func $41 (type $2)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $19
|
||||
)
|
||||
|
||||
(func $42 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $20
|
||||
)
|
||||
|
||||
(func $43 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
(local $2 i32)
|
||||
global.get $8
|
||||
i32.const 16
|
||||
i32.sub
|
||||
local.tee $2
|
||||
global.set $8
|
||||
local.get $2
|
||||
local.get $1
|
||||
i32.store
|
||||
local.get $0
|
||||
local.get $2
|
||||
call $21
|
||||
local.get $2
|
||||
i32.const 16
|
||||
i32.add
|
||||
global.set $8
|
||||
)
|
||||
|
||||
(func $44 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
(local $3 i32)
|
||||
global.get $8
|
||||
i32.const 16
|
||||
i32.sub
|
||||
local.tee $3
|
||||
global.set $8
|
||||
local.get $3
|
||||
local.get $2
|
||||
i32.store
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $3
|
||||
call $22
|
||||
local.get $3
|
||||
i32.const 16
|
||||
i32.add
|
||||
global.set $8
|
||||
)
|
||||
|
||||
(func $45 (type $4)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(param $3 i32)
|
||||
(result i32)
|
||||
(local $4 i32)
|
||||
global.get $8
|
||||
i32.const 16
|
||||
i32.sub
|
||||
local.tee $4
|
||||
global.set $8
|
||||
local.get $4
|
||||
local.get $3
|
||||
i32.store
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
local.get $4
|
||||
call $23
|
||||
local.get $4
|
||||
i32.const 16
|
||||
i32.add
|
||||
global.set $8
|
||||
)
|
||||
|
||||
(func $46 (type $2)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $24
|
||||
)
|
||||
|
||||
(func $47 (type $2)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $25
|
||||
)
|
||||
|
||||
(func $48 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $26
|
||||
)
|
||||
|
||||
(func $49 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $27
|
||||
)
|
||||
|
||||
(func $50 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
call $28
|
||||
)
|
||||
|
||||
(func $51 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
call $29
|
||||
)
|
||||
|
||||
(func $52 (type $1)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
call $30
|
||||
)
|
||||
|
||||
(func $53 (type $2)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $31
|
||||
)
|
||||
|
||||
(func $54 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $32
|
||||
)
|
||||
|
||||
(func $55 (type $0)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(param $2 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
local.get $1
|
||||
local.get $2
|
||||
call $33
|
||||
)
|
||||
|
||||
;;(custom_section "producers"
|
||||
;; (after code)
|
||||
;; "\01\0cprocessed-by\01\05clangV11.0.0 (ht"
|
||||
;; "tps://github.com/llvm/llvm-proje"
|
||||
;; "ct 176249bd6732a8044d457092ed932"
|
||||
;; "768724a6f06)")
|
||||
|
||||
)
|
||||
140
tests/unit/wasm-vm/wasm-apps/app2/main.c
Normal file
140
tests/unit/wasm-vm/wasm-apps/app2/main.c
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
on_init()
|
||||
{}
|
||||
|
||||
int
|
||||
my_sqrt(int x, int y)
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
void *
|
||||
null_pointer()
|
||||
{
|
||||
void *ptr = NULL;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
my_malloc(int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *
|
||||
my_calloc(int nmemb, int size)
|
||||
{
|
||||
return calloc(nmemb, size);
|
||||
}
|
||||
|
||||
void
|
||||
my_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
my_memcpy(void *dst, void *src, int size)
|
||||
{
|
||||
return memcpy(dst, src, size);
|
||||
}
|
||||
|
||||
char *
|
||||
my_strdup(const char *s)
|
||||
{
|
||||
return strdup(s);
|
||||
}
|
||||
|
||||
int
|
||||
my_memcmp(const void *buf1, const void *buf2, int size)
|
||||
{
|
||||
return memcmp(buf1, buf2, size);
|
||||
}
|
||||
|
||||
int
|
||||
my_printf(const char *format, char *s)
|
||||
{
|
||||
return printf(format, s);
|
||||
}
|
||||
|
||||
int
|
||||
my_sprintf(char *buf1, const char *format, char *buf2)
|
||||
{
|
||||
return sprintf(buf1, format, buf2);
|
||||
}
|
||||
|
||||
int
|
||||
my_snprintf(char *buf1, int size, const char *format, char *buf2)
|
||||
{
|
||||
return snprintf(buf1, size, format, buf2);
|
||||
}
|
||||
|
||||
int
|
||||
my_puts(const char *s)
|
||||
{
|
||||
return puts(s);
|
||||
}
|
||||
|
||||
int
|
||||
my_putchar(int s)
|
||||
{
|
||||
return putchar(s);
|
||||
}
|
||||
|
||||
void *
|
||||
my_memmove(void *buf1, const void *buf2, int size)
|
||||
{
|
||||
return memmove(buf1, buf2, size);
|
||||
}
|
||||
|
||||
void *
|
||||
my_memset(void *buf, int c, int size)
|
||||
{
|
||||
return memset(buf, c, size);
|
||||
}
|
||||
|
||||
char *
|
||||
my_strchr(const char *s, int c)
|
||||
{
|
||||
return strchr(s, c);
|
||||
}
|
||||
|
||||
int
|
||||
my_strcmp(const char *buf1, const char *buf2)
|
||||
{
|
||||
return strcmp(buf1, buf2);
|
||||
}
|
||||
|
||||
char *
|
||||
my_strcpy(char *buf1, const char *buf2)
|
||||
{
|
||||
return strcpy(buf1, buf2);
|
||||
}
|
||||
|
||||
int
|
||||
my_strlen(const char *s)
|
||||
{
|
||||
return (int)strlen(s);
|
||||
}
|
||||
|
||||
int
|
||||
my_strncmp(const char *buf1, const char *buf2, int n)
|
||||
{
|
||||
return strncmp(buf1, buf2, n);
|
||||
}
|
||||
|
||||
char *
|
||||
my_strncpy(char *buf1, const char *buf2, int n)
|
||||
{
|
||||
return strncpy(buf1, buf2, n);
|
||||
}
|
||||
104
tests/unit/wasm-vm/wasm-apps/app2_wasm.h
Normal file
104
tests/unit/wasm-vm/wasm-apps/app2_wasm.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
unsigned char app2_wasm[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x26, 0x07, 0x60,
|
||||
0x03, 0x7F, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F,
|
||||
0x60, 0x01, 0x7F, 0x01, 0x7F, 0x60, 0x01, 0x7F, 0x00, 0x60, 0x04, 0x7F,
|
||||
0x7F, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x00, 0x01, 0x7F,
|
||||
0x02, 0xFB, 0x01, 0x13, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||
0x6C, 0x6F, 0x63, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x63, 0x61,
|
||||
0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||
0x72, 0x65, 0x65, 0x00, 0x03, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x65,
|
||||
0x6D, 0x63, 0x70, 0x79, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x73,
|
||||
0x74, 0x72, 0x64, 0x75, 0x70, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76, 0x06,
|
||||
0x6D, 0x65, 0x6D, 0x63, 0x6D, 0x70, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76,
|
||||
0x06, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E,
|
||||
0x76, 0x07, 0x73, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x00, 0x03,
|
||||
0x65, 0x6E, 0x76, 0x08, 0x73, 0x6E, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66,
|
||||
0x00, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75, 0x74, 0x73, 0x00,
|
||||
0x02, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x70, 0x75, 0x74, 0x63, 0x68, 0x61,
|
||||
0x72, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x6D, 0x65, 0x6D, 0x6D,
|
||||
0x6F, 0x76, 0x65, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x65,
|
||||
0x6D, 0x73, 0x65, 0x74, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x73,
|
||||
0x74, 0x72, 0x63, 0x68, 0x72, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x06,
|
||||
0x73, 0x74, 0x72, 0x63, 0x6D, 0x70, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76,
|
||||
0x06, 0x73, 0x74, 0x72, 0x63, 0x70, 0x79, 0x00, 0x01, 0x03, 0x65, 0x6E,
|
||||
0x76, 0x06, 0x73, 0x74, 0x72, 0x6C, 0x65, 0x6E, 0x00, 0x02, 0x03, 0x65,
|
||||
0x6E, 0x76, 0x07, 0x73, 0x74, 0x72, 0x6E, 0x63, 0x6D, 0x70, 0x00, 0x00,
|
||||
0x03, 0x65, 0x6E, 0x76, 0x07, 0x73, 0x74, 0x72, 0x6E, 0x63, 0x70, 0x79,
|
||||
0x00, 0x00, 0x03, 0x17, 0x16, 0x05, 0x01, 0x06, 0x02, 0x01, 0x03, 0x00,
|
||||
0x02, 0x00, 0x01, 0x00, 0x04, 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x01,
|
||||
0x02, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x29, 0x07, 0x7F,
|
||||
0x01, 0x41, 0x80, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0x80, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0x00, 0x0B, 0x7F, 0x00,
|
||||
0x41, 0x01, 0x0B, 0x07, 0x81, 0x03, 0x1E, 0x06, 0x6D, 0x65, 0x6D, 0x6F,
|
||||
0x72, 0x79, 0x02, 0x00, 0x11, 0x5F, 0x5F, 0x77, 0x61, 0x73, 0x6D, 0x5F,
|
||||
0x63, 0x61, 0x6C, 0x6C, 0x5F, 0x63, 0x74, 0x6F, 0x72, 0x73, 0x00, 0x13,
|
||||
0x07, 0x6F, 0x6E, 0x5F, 0x69, 0x6E, 0x69, 0x74, 0x00, 0x13, 0x07, 0x6D,
|
||||
0x79, 0x5F, 0x73, 0x71, 0x72, 0x74, 0x00, 0x14, 0x0C, 0x6E, 0x75, 0x6C,
|
||||
0x6C, 0x5F, 0x70, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x00, 0x15, 0x09,
|
||||
0x6D, 0x79, 0x5F, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x16, 0x09,
|
||||
0x6D, 0x79, 0x5F, 0x63, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x17, 0x07,
|
||||
0x6D, 0x79, 0x5F, 0x66, 0x72, 0x65, 0x65, 0x00, 0x18, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x6D, 0x65, 0x6D, 0x63, 0x70, 0x79, 0x00, 0x19, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x73, 0x74, 0x72, 0x64, 0x75, 0x70, 0x00, 0x1A, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x6D, 0x65, 0x6D, 0x63, 0x6D, 0x70, 0x00, 0x1B, 0x09, 0x6D, 0x79,
|
||||
0x5F, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x1C, 0x0A, 0x6D, 0x79,
|
||||
0x5F, 0x73, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x1D, 0x0B, 0x6D,
|
||||
0x79, 0x5F, 0x73, 0x6E, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x1E,
|
||||
0x07, 0x6D, 0x79, 0x5F, 0x70, 0x75, 0x74, 0x73, 0x00, 0x1F, 0x0A, 0x6D,
|
||||
0x79, 0x5F, 0x70, 0x75, 0x74, 0x63, 0x68, 0x61, 0x72, 0x00, 0x20, 0x0A,
|
||||
0x6D, 0x79, 0x5F, 0x6D, 0x65, 0x6D, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x21,
|
||||
0x09, 0x6D, 0x79, 0x5F, 0x6D, 0x65, 0x6D, 0x73, 0x65, 0x74, 0x00, 0x22,
|
||||
0x09, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x63, 0x68, 0x72, 0x00, 0x23,
|
||||
0x09, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x63, 0x6D, 0x70, 0x00, 0x24,
|
||||
0x09, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x63, 0x70, 0x79, 0x00, 0x25,
|
||||
0x09, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x6C, 0x65, 0x6E, 0x00, 0x26,
|
||||
0x0A, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x6E, 0x63, 0x6D, 0x70, 0x00,
|
||||
0x27, 0x0A, 0x6D, 0x79, 0x5F, 0x73, 0x74, 0x72, 0x6E, 0x63, 0x70, 0x79,
|
||||
0x00, 0x28, 0x0C, 0x5F, 0x5F, 0x64, 0x73, 0x6F, 0x5F, 0x68, 0x61, 0x6E,
|
||||
0x64, 0x6C, 0x65, 0x03, 0x01, 0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61,
|
||||
0x5F, 0x65, 0x6E, 0x64, 0x03, 0x02, 0x0D, 0x5F, 0x5F, 0x67, 0x6C, 0x6F,
|
||||
0x62, 0x61, 0x6C, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x03, 0x0B, 0x5F,
|
||||
0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x04,
|
||||
0x0D, 0x5F, 0x5F, 0x6D, 0x65, 0x6D, 0x6F, 0x72, 0x79, 0x5F, 0x62, 0x61,
|
||||
0x73, 0x65, 0x03, 0x05, 0x0C, 0x5F, 0x5F, 0x74, 0x61, 0x62, 0x6C, 0x65,
|
||||
0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x06, 0x0A, 0x94, 0x02, 0x16, 0x03,
|
||||
0x00, 0x01, 0x0B, 0x0D, 0x00, 0x20, 0x01, 0x20, 0x01, 0x6C, 0x20, 0x00,
|
||||
0x20, 0x00, 0x6C, 0x6A, 0x0B, 0x04, 0x00, 0x41, 0x00, 0x0B, 0x06, 0x00,
|
||||
0x20, 0x00, 0x10, 0x00, 0x0B, 0x08, 0x00, 0x20, 0x00, 0x20, 0x01, 0x10,
|
||||
0x01, 0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x02, 0x0B, 0x0A, 0x00, 0x20,
|
||||
0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x03, 0x0B, 0x06, 0x00, 0x20, 0x00,
|
||||
0x10, 0x04, 0x0B, 0x0A, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10,
|
||||
0x05, 0x0B, 0x21, 0x01, 0x01, 0x7F, 0x23, 0x00, 0x41, 0x10, 0x6B, 0x22,
|
||||
0x02, 0x24, 0x00, 0x20, 0x02, 0x20, 0x01, 0x36, 0x02, 0x00, 0x20, 0x00,
|
||||
0x20, 0x02, 0x10, 0x06, 0x20, 0x02, 0x41, 0x10, 0x6A, 0x24, 0x00, 0x0B,
|
||||
0x23, 0x01, 0x01, 0x7F, 0x23, 0x00, 0x41, 0x10, 0x6B, 0x22, 0x03, 0x24,
|
||||
0x00, 0x20, 0x03, 0x20, 0x02, 0x36, 0x02, 0x00, 0x20, 0x00, 0x20, 0x01,
|
||||
0x20, 0x03, 0x10, 0x07, 0x20, 0x03, 0x41, 0x10, 0x6A, 0x24, 0x00, 0x0B,
|
||||
0x25, 0x01, 0x01, 0x7F, 0x23, 0x00, 0x41, 0x10, 0x6B, 0x22, 0x04, 0x24,
|
||||
0x00, 0x20, 0x04, 0x20, 0x03, 0x36, 0x02, 0x00, 0x20, 0x00, 0x20, 0x01,
|
||||
0x20, 0x02, 0x20, 0x04, 0x10, 0x08, 0x20, 0x04, 0x41, 0x10, 0x6A, 0x24,
|
||||
0x00, 0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x09, 0x0B, 0x06, 0x00, 0x20,
|
||||
0x00, 0x10, 0x0A, 0x0B, 0x0A, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02,
|
||||
0x10, 0x0B, 0x0B, 0x0A, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10,
|
||||
0x0C, 0x0B, 0x08, 0x00, 0x20, 0x00, 0x20, 0x01, 0x10, 0x0D, 0x0B, 0x08,
|
||||
0x00, 0x20, 0x00, 0x20, 0x01, 0x10, 0x0E, 0x0B, 0x08, 0x00, 0x20, 0x00,
|
||||
0x20, 0x01, 0x10, 0x0F, 0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x10, 0x0B,
|
||||
0x0A, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x11, 0x0B, 0x0A,
|
||||
0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x12, 0x0B, 0x00, 0x76,
|
||||
0x09, 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x73, 0x01, 0x0C,
|
||||
0x70, 0x72, 0x6F, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2D, 0x62, 0x79,
|
||||
0x01, 0x05, 0x63, 0x6C, 0x61, 0x6E, 0x67, 0x56, 0x31, 0x31, 0x2E, 0x30,
|
||||
0x2E, 0x30, 0x20, 0x28, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F,
|
||||
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x6C,
|
||||
0x6C, 0x76, 0x6D, 0x2F, 0x6C, 0x6C, 0x76, 0x6D, 0x2D, 0x70, 0x72, 0x6F,
|
||||
0x6A, 0x65, 0x63, 0x74, 0x20, 0x31, 0x37, 0x36, 0x32, 0x34, 0x39, 0x62,
|
||||
0x64, 0x36, 0x37, 0x33, 0x32, 0x61, 0x38, 0x30, 0x34, 0x34, 0x64, 0x34,
|
||||
0x35, 0x37, 0x30, 0x39, 0x32, 0x65, 0x64, 0x39, 0x33, 0x32, 0x37, 0x36,
|
||||
0x38, 0x37, 0x32, 0x34, 0x61, 0x36, 0x66, 0x30, 0x36, 0x29
|
||||
};
|
||||
63
tests/unit/wasm-vm/wasm-apps/app3.wast
Normal file
63
tests/unit/wasm-vm/wasm-apps/app3.wast
Normal file
@ -0,0 +1,63 @@
|
||||
(module
|
||||
(type $0 (func (param i32) (result i32)))
|
||||
(type $1 (func))
|
||||
(type $2 (func (result i32)))
|
||||
(type $3 (func (param i32 i32) (result i32)))
|
||||
(import "env" "malloc" (func $11 (param i32) (result i32)))
|
||||
(memory $4 1)
|
||||
(global $5 i32 (i32.const 1024))
|
||||
(global $6 i32 (i32.const 1024))
|
||||
(global $7 i32 (i32.const 1024))
|
||||
(global $8 i32 (i32.const 5120))
|
||||
(global $9 i32 (i32.const 0))
|
||||
(global $10 i32 (i32.const 1))
|
||||
(export "memory" (memory $4))
|
||||
(export "__wasm_call_ctors" (func $12))
|
||||
(export "on_init" (func $12))
|
||||
(export "my_sqrt" (func $13))
|
||||
(export "null_pointer" (func $14))
|
||||
(export "my_malloc" (func $15))
|
||||
(export "__dso_handle" (global $5))
|
||||
(export "__data_end" (global $6))
|
||||
(export "__global_base" (global $7))
|
||||
(export "__heap_base" (global $8))
|
||||
(export "__memory_base" (global $9))
|
||||
(export "__table_base" (global $10))
|
||||
|
||||
(func $12 (type $1)
|
||||
nop
|
||||
)
|
||||
|
||||
(func $13 (type $3)
|
||||
(param $0 i32)
|
||||
(param $1 i32)
|
||||
(result i32)
|
||||
local.get $1
|
||||
local.get $1
|
||||
i32.mul
|
||||
local.get $0
|
||||
local.get $0
|
||||
i32.mul
|
||||
i32.add
|
||||
)
|
||||
|
||||
(func $14 (type $2)
|
||||
(result i32)
|
||||
i32.const 0
|
||||
)
|
||||
|
||||
(func $15 (type $0)
|
||||
(param $0 i32)
|
||||
(result i32)
|
||||
local.get $0
|
||||
call $11
|
||||
)
|
||||
|
||||
;;(custom_section "producers"
|
||||
;; (after code)
|
||||
;; "\01\0cprocessed-by\01\05clangV11.0.0 (ht"
|
||||
;; "tps://github.com/llvm/llvm-proje"
|
||||
;; "ct 176249bd6732a8044d457092ed932"
|
||||
;; "768724a6f06)")
|
||||
|
||||
)
|
||||
32
tests/unit/wasm-vm/wasm-apps/app3/main.c
Normal file
32
tests/unit/wasm-vm/wasm-apps/app3/main.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
on_init()
|
||||
{}
|
||||
|
||||
int
|
||||
my_sqrt(int x, int y)
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
void *
|
||||
null_pointer()
|
||||
{
|
||||
void *ptr = NULL;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
my_malloc(int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
42
tests/unit/wasm-vm/wasm-apps/app3_wasm.h
Normal file
42
tests/unit/wasm-vm/wasm-apps/app3_wasm.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
unsigned char app3_wasm[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x13, 0x04, 0x60,
|
||||
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x00, 0x00, 0x60, 0x00, 0x01, 0x7F, 0x60,
|
||||
0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x02, 0x0E, 0x01, 0x03, 0x65, 0x6E, 0x76,
|
||||
0x06, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x05, 0x04,
|
||||
0x01, 0x03, 0x02, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x23, 0x06,
|
||||
0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B,
|
||||
0x7F, 0x00, 0x41, 0x80, 0x08, 0x0B, 0x7F, 0x00, 0x41, 0x80, 0x28, 0x0B,
|
||||
0x7F, 0x00, 0x41, 0x00, 0x0B, 0x7F, 0x00, 0x41, 0x01, 0x0B, 0x07, 0xA6,
|
||||
0x01, 0x0C, 0x06, 0x6D, 0x65, 0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x11,
|
||||
0x5F, 0x5F, 0x77, 0x61, 0x73, 0x6D, 0x5F, 0x63, 0x61, 0x6C, 0x6C, 0x5F,
|
||||
0x63, 0x74, 0x6F, 0x72, 0x73, 0x00, 0x01, 0x07, 0x6F, 0x6E, 0x5F, 0x69,
|
||||
0x6E, 0x69, 0x74, 0x00, 0x01, 0x07, 0x6D, 0x79, 0x5F, 0x73, 0x71, 0x72,
|
||||
0x74, 0x00, 0x02, 0x0C, 0x6E, 0x75, 0x6C, 0x6C, 0x5F, 0x70, 0x6F, 0x69,
|
||||
0x6E, 0x74, 0x65, 0x72, 0x00, 0x03, 0x09, 0x6D, 0x79, 0x5F, 0x6D, 0x61,
|
||||
0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x04, 0x0C, 0x5F, 0x5F, 0x64, 0x73, 0x6F,
|
||||
0x5F, 0x68, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x03, 0x00, 0x0A, 0x5F, 0x5F,
|
||||
0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03, 0x01, 0x0D, 0x5F,
|
||||
0x5F, 0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x5F, 0x62, 0x61, 0x73, 0x65,
|
||||
0x03, 0x02, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61,
|
||||
0x73, 0x65, 0x03, 0x03, 0x0D, 0x5F, 0x5F, 0x6D, 0x65, 0x6D, 0x6F, 0x72,
|
||||
0x79, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x04, 0x0C, 0x5F, 0x5F, 0x74,
|
||||
0x61, 0x62, 0x6C, 0x65, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x05, 0x0A,
|
||||
0x1F, 0x04, 0x03, 0x00, 0x01, 0x0B, 0x0D, 0x00, 0x20, 0x01, 0x20, 0x01,
|
||||
0x6C, 0x20, 0x00, 0x20, 0x00, 0x6C, 0x6A, 0x0B, 0x04, 0x00, 0x41, 0x00,
|
||||
0x0B, 0x06, 0x00, 0x20, 0x00, 0x10, 0x00, 0x0B, 0x00, 0x76, 0x09, 0x70,
|
||||
0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x73, 0x01, 0x0C, 0x70, 0x72,
|
||||
0x6F, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2D, 0x62, 0x79, 0x01, 0x05,
|
||||
0x63, 0x6C, 0x61, 0x6E, 0x67, 0x56, 0x31, 0x31, 0x2E, 0x30, 0x2E, 0x30,
|
||||
0x20, 0x28, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F, 0x67, 0x69,
|
||||
0x74, 0x68, 0x75, 0x62, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x6C, 0x6C, 0x76,
|
||||
0x6D, 0x2F, 0x6C, 0x6C, 0x76, 0x6D, 0x2D, 0x70, 0x72, 0x6F, 0x6A, 0x65,
|
||||
0x63, 0x74, 0x20, 0x31, 0x37, 0x36, 0x32, 0x34, 0x39, 0x62, 0x64, 0x36,
|
||||
0x37, 0x33, 0x32, 0x61, 0x38, 0x30, 0x34, 0x34, 0x64, 0x34, 0x35, 0x37,
|
||||
0x30, 0x39, 0x32, 0x65, 0x64, 0x39, 0x33, 0x32, 0x37, 0x36, 0x38, 0x37,
|
||||
0x32, 0x34, 0x61, 0x36, 0x66, 0x30, 0x36, 0x29
|
||||
};
|
||||
BIN
tests/unit/wasm-vm/wasm-apps/app4/m1.wasm
Normal file
BIN
tests/unit/wasm-vm/wasm-apps/app4/m1.wasm
Normal file
Binary file not shown.
14
tests/unit/wasm-vm/wasm-apps/app4/m1.wat
Normal file
14
tests/unit/wasm-vm/wasm-apps/app4/m1.wat
Normal file
@ -0,0 +1,14 @@
|
||||
(module
|
||||
(func $f1 (export "f1") (result i32) (i32.const 1))
|
||||
|
||||
(memory $m1 1 2)
|
||||
(table $t1 0 funcref)
|
||||
(global $g1 i32 (i32.const 1))
|
||||
|
||||
(export "m1" (memory $m1))
|
||||
(export "m1_alias" (memory $m1))
|
||||
(export "t1" (table $t1))
|
||||
(export "t1_alias" (table $t1))
|
||||
(export "g1" (global $g1))
|
||||
(export "g1_alias" (global $g1))
|
||||
)
|
||||
BIN
tests/unit/wasm-vm/wasm-apps/app4/m2.wasm
Normal file
BIN
tests/unit/wasm-vm/wasm-apps/app4/m2.wasm
Normal file
Binary file not shown.
24
tests/unit/wasm-vm/wasm-apps/app4/m2.wat
Normal file
24
tests/unit/wasm-vm/wasm-apps/app4/m2.wat
Normal file
@ -0,0 +1,24 @@
|
||||
(module
|
||||
(import "m1" "f1" (func $m1-f1 (result i32)))
|
||||
(export "m1-f1" (func $m1-f1))
|
||||
|
||||
(import "m1" "m1" (memory $m1-m1 1 2))
|
||||
(import "m1" "t1" (table $m1-t1 0 funcref))
|
||||
(import "m1" "g1" (global $m1-g1 i32))
|
||||
|
||||
(func $f2 (export "f2") (param i32) (result i32)
|
||||
(i32.add (call $m1-f1) (local.get 0))
|
||||
)
|
||||
|
||||
(func $f4 (result i32) (i32.const 3))
|
||||
|
||||
(func $f3 (export "f3") (param i32 i32) (result i32)
|
||||
(i32.add
|
||||
(call $m1-f1)
|
||||
(i32.add
|
||||
(call $f4)
|
||||
(call $f2 (local.get 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
BIN
tests/unit/wasm-vm/wasm-apps/app4/m3.wasm
Normal file
BIN
tests/unit/wasm-vm/wasm-apps/app4/m3.wasm
Normal file
Binary file not shown.
7
tests/unit/wasm-vm/wasm-apps/app4/m3.wat
Normal file
7
tests/unit/wasm-vm/wasm-apps/app4/m3.wat
Normal file
@ -0,0 +1,7 @@
|
||||
(module
|
||||
(import "m1" "f1" (func $m1-f1 (result i32)))
|
||||
(import "m1" "m1_alias" (memory $m1-m1 1 2))
|
||||
(import "m1" "t1_alias" (table $m1-t1 0 funcref))
|
||||
(import "m1" "g1_alias" (global $m1-g1 i32))
|
||||
(import "m2" "f2" (func $m2-f2 (param i32) (result i32)))
|
||||
)
|
||||
BIN
tests/unit/wasm-vm/wasm-apps/binarydump
Executable file
BIN
tests/unit/wasm-vm/wasm-apps/binarydump
Executable file
Binary file not shown.
32
tests/unit/wasm-vm/wasm-apps/build.sh
Executable file
32
tests/unit/wasm-vm/wasm-apps/build.sh
Executable file
@ -0,0 +1,32 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
## build app1
|
||||
/opt/wasi-sdk/bin/clang -O3 \
|
||||
-z stack-size=4096 -Wl,--initial-memory=65536 \
|
||||
-o app1/app1.wasm app1/main.c -Wl,--export-all \
|
||||
-Wl,--export=__heap_base,--export=__data_end \
|
||||
-Wl,--no-entry -nostdlib -Wl,--allow-undefined
|
||||
./binarydump -o app1_wasm.h -n app1_wasm app1/app1.wasm
|
||||
wavm disassemble app1/app1.wasm app1.wast
|
||||
rm -f app1/app1.wasm
|
||||
|
||||
## build app2
|
||||
/opt/wasi-sdk/bin/clang -O3 \
|
||||
-z stack-size=4096 -Wl,--initial-memory=65536 \
|
||||
-o app2/app2.wasm app2/main.c -Wl,--export-all \
|
||||
-Wl,--export=__heap_base,--export=__data_end \
|
||||
-Wl,--no-entry -nostdlib -Wl,--allow-undefined
|
||||
./binarydump -o app2_wasm.h -n app2_wasm app2/app2.wasm
|
||||
wavm disassemble app2/app2.wasm app2.wast
|
||||
rm -f app2/app2.wasm
|
||||
|
||||
## build app3
|
||||
/opt/wasi-sdk/bin/clang -O3 \
|
||||
-z stack-size=4096 -Wl,--initial-memory=65536 \
|
||||
-o app3/app3.wasm app3/main.c -Wl,--export-all \
|
||||
-Wl,--export=__heap_base,--export=__data_end \
|
||||
-Wl,--no-entry -nostdlib -Wl,--allow-undefined
|
||||
./binarydump -o app3_wasm.h -n app3_wasm app3/app3.wasm
|
||||
wavm disassemble app3/app3.wasm app3.wast
|
||||
rm -f app3/app3.wasm
|
||||
716
tests/unit/wasm-vm/wasm_vm.cc
Normal file
716
tests/unit/wasm-vm/wasm_vm.cc
Normal file
@ -0,0 +1,716 @@
|
||||
/*
|
||||
* 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"
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
#include "wasm.h"
|
||||
#include "wasm_runtime.h"
|
||||
#endif
|
||||
#include "wasm-apps/app1_wasm.h"
|
||||
#include "wasm-apps/app2_wasm.h"
|
||||
#include "wasm-apps/app3_wasm.h"
|
||||
|
||||
#define EightK (8 * 1024)
|
||||
// To use a test fixture, derive a class from testing::Test.
|
||||
class WasmVMTest : public testing::Test
|
||||
{
|
||||
protected:
|
||||
// You should make the members protected s.t. they can be
|
||||
// accessed from sub-classes.
|
||||
|
||||
// virtual void SetUp() will be called before each test is run. You
|
||||
// should define it if you need to initialize the varaibles.
|
||||
// Otherwise, this can be skipped.
|
||||
void SetUp()
|
||||
{
|
||||
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);
|
||||
|
||||
// bh_log_set_verbose_level(5);
|
||||
|
||||
clean = true;
|
||||
}
|
||||
|
||||
// virtual void TearDown() will be called after each test is run.
|
||||
// You should define it if there is cleanup work to do. Otherwise,
|
||||
// you don't have to provide it.
|
||||
//
|
||||
void TearDown()
|
||||
{
|
||||
if (clean) {
|
||||
wasm_runtime_destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
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];
|
||||
RuntimeInitArgs init_args;
|
||||
bool clean = true;
|
||||
};
|
||||
|
||||
TEST_F(WasmVMTest, Test_app1)
|
||||
{
|
||||
unsigned argv[10];
|
||||
|
||||
ASSERT_TRUE(app1_wasm != NULL);
|
||||
|
||||
/* Load module */
|
||||
module = wasm_runtime_load(app1_wasm, sizeof(app1_wasm), error_buf,
|
||||
sizeof(error_buf));
|
||||
if (module == nullptr) {
|
||||
printf("error: %s\n", error_buf);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
/* Initiate module */
|
||||
module_inst = wasm_runtime_instantiate(module, 8 * 1024, 8 * 1024,
|
||||
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);
|
||||
|
||||
/* _on_init() function doesn't exist */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "_on_init");
|
||||
ASSERT_TRUE(func_inst == NULL);
|
||||
|
||||
/* on_init() function exists */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "on_init");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_call_wasm(exec_env, func_inst, 0, NULL) == true);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* call my_malloc */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_malloc");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
/* malloc with very large size */
|
||||
argv[0] = 10 * 1024;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
wasm_runtime_clear_exception(module_inst);
|
||||
ASSERT_EQ(argv[0], 0);
|
||||
|
||||
/* malloc 1K, should success */
|
||||
argv[0] = 1024;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* convert to native address */
|
||||
ASSERT_TRUE(wasm_runtime_validate_app_addr(module_inst, argv[0], 1));
|
||||
char *buf = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf != NULL);
|
||||
|
||||
ASSERT_EQ(wasm_runtime_addr_native_to_app(module_inst, buf), argv[0]);
|
||||
int32 buf_offset = argv[0];
|
||||
|
||||
/* call memcpy */
|
||||
char *buf1 = buf + 100;
|
||||
memcpy(buf1, "123456", 7);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memcpy");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 100;
|
||||
argv[2] = 7;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
ASSERT_TRUE(strcmp(buf, buf1) == 0);
|
||||
|
||||
/* call strdup */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strdup");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
|
||||
int32 buf_offset1 = argv[0];
|
||||
ASSERT_NE(buf_offset, buf_offset1);
|
||||
|
||||
buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, buf_offset1);
|
||||
ASSERT_TRUE(strcmp(buf, buf1) == 0);
|
||||
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app2)
|
||||
{
|
||||
unsigned argv[10];
|
||||
|
||||
/* Load module */
|
||||
module = wasm_runtime_load(app2_wasm, sizeof(app2_wasm), error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
/* Initiate module */
|
||||
module_inst = wasm_runtime_instantiate(module, 8 * 1024, 8 * 1024,
|
||||
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);
|
||||
|
||||
/* _on_init() function doesn't exist */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "_on_init");
|
||||
ASSERT_TRUE(func_inst == NULL);
|
||||
|
||||
/* on_init() function exists */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "on_init");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_call_wasm(exec_env, func_inst, 0, NULL) == true);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* call my_malloc */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_malloc");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
/* malloc 1K, should success */
|
||||
argv[0] = 1024;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* convert to native address */
|
||||
ASSERT_TRUE(wasm_runtime_validate_app_addr(module_inst, argv[0], 1));
|
||||
char *buf = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf != NULL);
|
||||
|
||||
ASSERT_EQ(wasm_runtime_addr_native_to_app(module_inst, buf), argv[0]);
|
||||
int32 buf_offset = argv[0];
|
||||
|
||||
/* call memcpy */
|
||||
char *buf1 = buf + 100;
|
||||
memcpy(buf1, "123456", 7);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memcpy");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 100;
|
||||
argv[2] = 7;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
ASSERT_TRUE(strcmp(buf, buf1) == 0);
|
||||
|
||||
/* call memcmp */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memcmp");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 100;
|
||||
argv[2] = 7;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] == 0);
|
||||
|
||||
/* call printf */
|
||||
char *format = buf + 200;
|
||||
memcpy(format, "string0 is %s", 13);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_printf");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = wasm_runtime_addr_native_to_app(module_inst, format);
|
||||
argv[1] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
ASSERT_TRUE(argv[0] == 17);
|
||||
|
||||
/* call sprintf */
|
||||
memcpy(format, "string1 is %s", 13);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_sprintf");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 300;
|
||||
int32 argv0_tmp = argv[0];
|
||||
argv[1] = wasm_runtime_addr_native_to_app(module_inst, format);
|
||||
argv[2] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
ASSERT_TRUE(
|
||||
memcmp((char *)wasm_runtime_addr_app_to_native(module_inst, argv0_tmp),
|
||||
"string1 is 123456", 17)
|
||||
== 0);
|
||||
ASSERT_TRUE(argv[0] == 17);
|
||||
|
||||
/* call snprintf */
|
||||
memcpy(format, "string2 is %s", 13);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_snprintf");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 400;
|
||||
argv0_tmp = argv[0];
|
||||
argv[1] = 3;
|
||||
argv[2] = wasm_runtime_addr_native_to_app(module_inst, format);
|
||||
argv[3] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 4, argv);
|
||||
|
||||
ASSERT_TRUE(
|
||||
memcmp((char *)wasm_runtime_addr_app_to_native(module_inst, argv0_tmp),
|
||||
"st\0", 3)
|
||||
== 0);
|
||||
ASSERT_TRUE(argv[0] == 17);
|
||||
|
||||
/* call puts */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_puts");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] != EOF);
|
||||
|
||||
/* call putchar */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_putchar");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] != EOF);
|
||||
|
||||
/* call memmove without memory coverage*/
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memmove");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 10;
|
||||
argv[1] = buf_offset + 100;
|
||||
argv[2] = 6;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(strcmp(buf + 100, buf1) == 0);
|
||||
ASSERT_TRUE(memcmp(buf1, "123456", 6) == 0);
|
||||
|
||||
/* call memmove with memory coverage*/
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memmove");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 95;
|
||||
argv[1] = buf_offset + 100;
|
||||
argv[2] = 6;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(strcmp(buf + 100, buf1) != 0);
|
||||
ASSERT_TRUE(memcmp(buf1, "123456", 6) == 0);
|
||||
ASSERT_TRUE(memcmp(buf + 100, "623456", 6) == 0);
|
||||
|
||||
/* call memset*/
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_memset");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 100;
|
||||
argv[1] = 48;
|
||||
argv[2] = 4;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
ASSERT_TRUE(memcmp(buf + 100, "000056", 6) == 0);
|
||||
|
||||
/* call strchr*/
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strchr");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = 49; // asc2 for char "1"
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
|
||||
buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf1 - buf == 0);
|
||||
|
||||
/* call strcmp */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strcmp");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] == 0);
|
||||
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 1;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] != 0);
|
||||
|
||||
/* call strcpy */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strcpy");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 110;
|
||||
argv[1] = buf_offset;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
ASSERT_TRUE(memcmp(buf + 110, "123456", 6) == 0);
|
||||
|
||||
/* call strlen */
|
||||
buf1 = buf + 110;
|
||||
memcpy(buf1, "123456\0", 7);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strlen");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 110;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] == 6);
|
||||
|
||||
/* call strncmp */
|
||||
buf1 = buf + 110;
|
||||
memcpy(buf1, "123457", 6);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strncmp");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 110;
|
||||
argv[2] = 5;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] == 0);
|
||||
|
||||
argv[0] = buf_offset;
|
||||
argv[1] = buf_offset + 110;
|
||||
argv[2] = 6;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
ASSERT_TRUE(argv[0] != 0);
|
||||
|
||||
/* call strncpy */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_strncpy");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset + 130;
|
||||
argv[1] = buf_offset;
|
||||
argv[2] = 5;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 3, argv);
|
||||
|
||||
buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(memcmp(buf, buf1, 5) == 0);
|
||||
ASSERT_TRUE(memcmp(buf, buf1, 6) != 0);
|
||||
|
||||
/* call _my_calloc */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_calloc");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
/* calloc, should success */
|
||||
argv[0] = 10;
|
||||
argv[1] = 4;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* convert to native address */
|
||||
ASSERT_TRUE(wasm_runtime_validate_app_addr(module_inst, argv[0], 40));
|
||||
char *buf2 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf2 != NULL);
|
||||
|
||||
ASSERT_EQ(wasm_runtime_addr_native_to_app(module_inst, buf2), argv[0]);
|
||||
int32 buf_offset1 = argv[0];
|
||||
|
||||
/* call _my_free */
|
||||
memcpy(buf2, "123456", 6);
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_free");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
argv[0] = buf_offset1;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
|
||||
ASSERT_TRUE(memcmp(buf2, "123456", 6) != 0);
|
||||
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app3)
|
||||
{
|
||||
unsigned argv[10];
|
||||
|
||||
/* Load module */
|
||||
module = wasm_runtime_load(app3_wasm, sizeof(app3_wasm), error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
/* Initiate module */
|
||||
module_inst = wasm_runtime_instantiate(module, 8 * 1024, 8 * 1024,
|
||||
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);
|
||||
|
||||
/* _on_init() function doesn't exist */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "_on_init");
|
||||
ASSERT_TRUE(func_inst == NULL);
|
||||
|
||||
/* on_init() function exists */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "on_init");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_call_wasm(exec_env, func_inst, 0, NULL) == true);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* call my_malloc */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_malloc");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
/* malloc with very large size */
|
||||
argv[0] = 10 * 1024;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
wasm_runtime_clear_exception(module_inst);
|
||||
ASSERT_EQ(argv[0], 0);
|
||||
|
||||
/* malloc 1K, should success */
|
||||
argv[0] = 1024;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* convert to native address */
|
||||
ASSERT_TRUE(wasm_runtime_validate_app_addr(module_inst, argv[0], 1));
|
||||
char *buf = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf != NULL);
|
||||
|
||||
ASSERT_EQ(wasm_runtime_addr_native_to_app(module_inst, buf), argv[0]);
|
||||
int32 buf_offset = argv[0];
|
||||
|
||||
/* call my_malloc */
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "my_malloc");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
|
||||
/* malloc, should success */
|
||||
argv[0] = 10;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
|
||||
/* convert to native address */
|
||||
ASSERT_TRUE(wasm_runtime_validate_app_addr(module_inst, argv[0], 1));
|
||||
char *buf1 = (char *)wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
ASSERT_TRUE(buf1 != NULL);
|
||||
|
||||
ASSERT_EQ(wasm_runtime_addr_native_to_app(module_inst, buf1), argv[0]);
|
||||
int32 buf_offset1 = argv[0];
|
||||
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
static const char *module_search_path = ".";
|
||||
static bool call_destroyer = false;
|
||||
static bool
|
||||
module_reader_callback(package_type_t module_type, const char *module_name,
|
||||
uint8 **p_buffer, uint32 *p_size)
|
||||
{
|
||||
const char *format = "%s/%s.wasm";
|
||||
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
|
||||
+ strlen(".wasm") + 1;
|
||||
char *wasm_file_name = (char *)BH_MALLOC(sz);
|
||||
if (!wasm_file_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
snprintf(wasm_file_name, sz, format, module_search_path, module_name);
|
||||
printf("going to open %s\n", wasm_file_name);
|
||||
|
||||
call_destroyer = false;
|
||||
*p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_name, p_size);
|
||||
|
||||
BH_FREE(wasm_file_name);
|
||||
return *p_buffer != NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
module_destroyer_callback(uint8 *buffer, uint32 size)
|
||||
{
|
||||
wasm_runtime_free(buffer);
|
||||
call_destroyer = true;
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app4_single)
|
||||
{
|
||||
uint8 *buffer = NULL;
|
||||
uint32 buffer_size = 0;
|
||||
bool ret = false;
|
||||
unsigned argv[10];
|
||||
|
||||
wasm_runtime_set_module_reader(&module_reader_callback,
|
||||
&module_destroyer_callback);
|
||||
|
||||
/* m1 only */
|
||||
ret = module_reader_callback(Wasm_Module_Bytecode, "m1", &buffer,
|
||||
&buffer_size);
|
||||
ASSERT_TRUE(ret);
|
||||
ASSERT_TRUE(buffer_size > 0);
|
||||
ASSERT_TRUE(buffer != NULL);
|
||||
|
||||
module =
|
||||
wasm_runtime_load(buffer, buffer_size, error_buf, sizeof(error_buf));
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
ASSERT_FALSE(wasm_runtime_find_module_registered("m1"));
|
||||
|
||||
wasm_runtime_register_module("m1", module, error_buf, sizeof(error_buf));
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_find_module_registered("m1"));
|
||||
|
||||
module_inst = wasm_runtime_instantiate(module, EightK, EightK, error_buf,
|
||||
sizeof(error_buf));
|
||||
ASSERT_TRUE(module_inst != NULL);
|
||||
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, EightK);
|
||||
ASSERT_TRUE(exec_env != NULL);
|
||||
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "f1");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
ASSERT_FALSE(((WASMFunctionInstance *)func_inst)->is_import_func);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->param_cell_num == 0);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->ret_cell_num == 1);
|
||||
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 0, argv);
|
||||
printf("exception is %s", wasm_runtime_get_exception(module_inst));
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
ASSERT_TRUE(argv[0] == 1);
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
|
||||
// call destroyer and without exception
|
||||
ASSERT_FALSE(call_destroyer);
|
||||
module_destroyer_callback(buffer, buffer_size);
|
||||
|
||||
clean = false;
|
||||
wasm_runtime_destroy();
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app4_plus_one)
|
||||
{
|
||||
uint8 *buffer = NULL;
|
||||
uint32 buffer_size = 0;
|
||||
bool ret = false;
|
||||
uint32_t argv[10] = { 0 };
|
||||
|
||||
wasm_runtime_set_module_reader(&module_reader_callback,
|
||||
&module_destroyer_callback);
|
||||
|
||||
/* m2 -> m1 */
|
||||
ret = module_reader_callback(Wasm_Module_Bytecode, "m2", &buffer,
|
||||
&buffer_size);
|
||||
ASSERT_TRUE(ret);
|
||||
ASSERT_TRUE(buffer_size > 0);
|
||||
ASSERT_TRUE(buffer != NULL);
|
||||
|
||||
module =
|
||||
wasm_runtime_load(buffer, buffer_size, error_buf, sizeof(error_buf));
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
module_inst = wasm_runtime_instantiate(module, EightK, EightK, error_buf,
|
||||
sizeof(error_buf));
|
||||
ASSERT_TRUE(module_inst != NULL);
|
||||
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, EightK);
|
||||
ASSERT_TRUE(exec_env != NULL);
|
||||
|
||||
printf("------------------- m1-f1 ---------------------\n");
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "m1-f1");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->is_import_func);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->param_cell_num == 0);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->ret_cell_num == 1);
|
||||
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 0, argv);
|
||||
printf("exception is %s\n", wasm_runtime_get_exception(module_inst));
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
ASSERT_TRUE(argv[0] == 1);
|
||||
|
||||
printf("------------------- f2 ---------------------\n");
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "f2");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
ASSERT_FALSE(((WASMFunctionInstance *)func_inst)->is_import_func);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->param_cell_num == 1);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->ret_cell_num == 1);
|
||||
|
||||
argv[0] = 2;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 1, argv);
|
||||
printf("exception is %s\n", wasm_runtime_get_exception(module_inst));
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
ASSERT_TRUE(argv[0] == 3);
|
||||
|
||||
printf("------------------- f3 ---------------------\n");
|
||||
func_inst = wasm_runtime_lookup_function(module_inst, "f3");
|
||||
ASSERT_TRUE(func_inst != NULL);
|
||||
ASSERT_FALSE(((WASMFunctionInstance *)func_inst)->is_import_func);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->param_cell_num == 2);
|
||||
ASSERT_TRUE(((WASMFunctionInstance *)func_inst)->ret_cell_num == 1);
|
||||
|
||||
argv[0] = 4;
|
||||
argv[1] = 9;
|
||||
wasm_runtime_call_wasm(exec_env, func_inst, 2, argv);
|
||||
printf("exception is %s\n", wasm_runtime_get_exception(module_inst));
|
||||
|
||||
ASSERT_TRUE(wasm_runtime_get_exception(module_inst) == NULL);
|
||||
ASSERT_TRUE(argv[0] == 9);
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
|
||||
wasm_runtime_unload(module);
|
||||
ASSERT_FALSE(call_destroyer);
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app4_family)
|
||||
{
|
||||
uint8 *buffer = NULL;
|
||||
uint32 buffer_size = 0;
|
||||
bool ret = false;
|
||||
|
||||
wasm_runtime_set_module_reader(&module_reader_callback,
|
||||
&module_destroyer_callback);
|
||||
|
||||
/* m3 -> m2[->m1], m1 */
|
||||
ret = module_reader_callback(Wasm_Module_Bytecode, "m3", &buffer,
|
||||
&buffer_size);
|
||||
ASSERT_TRUE(ret);
|
||||
ASSERT_TRUE(buffer_size > 0);
|
||||
ASSERT_TRUE(buffer != NULL);
|
||||
module =
|
||||
wasm_runtime_load(buffer, buffer_size, error_buf, sizeof(error_buf));
|
||||
ASSERT_TRUE(module != NULL);
|
||||
|
||||
wasm_runtime_unload(module);
|
||||
ASSERT_FALSE(call_destroyer);
|
||||
}
|
||||
|
||||
static const WASMModule *
|
||||
search_sub_module(const WASMModule *parent_module, const char *sub_module_name)
|
||||
{
|
||||
WASMRegisteredModule *node = (WASMRegisteredModule *)bh_list_first_elem(
|
||||
parent_module->import_module_list);
|
||||
while (node && strcmp(node->module_name, sub_module_name)) {
|
||||
node = (WASMRegisteredModule *)bh_list_elem_next(node);
|
||||
}
|
||||
return node ? (WASMModule *)node->module : NULL;
|
||||
}
|
||||
|
||||
TEST_F(WasmVMTest, Test_app4_reuse)
|
||||
{
|
||||
uint8 *buffer = NULL;
|
||||
uint32 buffer_size = 0;
|
||||
bool ret = false;
|
||||
|
||||
wasm_runtime_set_module_reader(&module_reader_callback,
|
||||
&module_destroyer_callback);
|
||||
|
||||
/* m3 -> m2[->m1], m1 */
|
||||
ret = module_reader_callback(Wasm_Module_Bytecode, "m3", &buffer,
|
||||
&buffer_size);
|
||||
ASSERT_TRUE(buffer != NULL);
|
||||
|
||||
WASMModule *m3 = (WASMModule *)wasm_runtime_load(
|
||||
buffer, buffer_size, error_buf, sizeof(error_buf));
|
||||
ASSERT_TRUE(m3 != NULL);
|
||||
|
||||
const WASMModule *m2 = search_sub_module(m3, "m2");
|
||||
const WASMModule *m1_in_m2 = search_sub_module(m2, "m1");
|
||||
const WASMModule *m1_in_m3 = search_sub_module(m3, "m1");
|
||||
ASSERT_EQ(m1_in_m2, m1_in_m3);
|
||||
}
|
||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||
Reference in New Issue
Block a user