Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
reentry_tests.cpp
Go to the documentation of this file.
1#include <sysio/vm/backend.hpp>
2
3#include <catch2/catch.hpp>
4
5using namespace sysio::vm;
6
7#include "utils.hpp"
8
9/*
10(module
11 (type (;0;) (func (param i32) (result i32)))
12 (import "env" "test_func_0" (func (;0;) (type 0)))
13 (import "env" "test_func_1" (func (;1;) (type 0)))
14 (func (;2;) (type 0) (param i32) (result i32)
15 get_local 0
16 i32.const 42
17 i32.add)
18 (func (;3;) (type 0) (param i32) (result i32)
19 get_local 0
20 call 0)
21 (func (;4;) (type 0) (param i32) (result i32)
22 get_local 0
23 i32.const 50
24 i32.add)
25 (func (;5;) (type 0) (param i32) (result i32)
26 get_local 0
27 call 1)
28 (memory (;0;) 1)
29 (export "foo" (func 2))
30 (export "testbar" (func 3))
31 (export "bar" (func 4))
32 (export "testbaz" (func 5)))
33*/
34static wasm_code reentry_wasm = {
35 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
36 0x01, 0x7f, 0x01, 0x7f, 0x02, 0x25, 0x02, 0x03, 0x65, 0x6e, 0x76, 0x0b,
37 0x74, 0x65, 0x73, 0x74, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x5f, 0x30, 0x00,
38 0x00, 0x03, 0x65, 0x6e, 0x76, 0x0b, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x66,
39 0x75, 0x6e, 0x63, 0x5f, 0x31, 0x00, 0x00, 0x03, 0x05, 0x04, 0x00, 0x00,
40 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x07, 0x21, 0x04, 0x03, 0x66,
41 0x6f, 0x6f, 0x00, 0x02, 0x07, 0x74, 0x65, 0x73, 0x74, 0x62, 0x61, 0x72,
42 0x00, 0x03, 0x03, 0x62, 0x61, 0x72, 0x00, 0x04, 0x07, 0x74, 0x65, 0x73,
43 0x74, 0x62, 0x61, 0x7a, 0x00, 0x05, 0x0a, 0x1f, 0x04, 0x07, 0x00, 0x20,
44 0x00, 0x41, 0x2a, 0x6a, 0x0b, 0x06, 0x00, 0x20, 0x00, 0x10, 0x00, 0x0b,
45 0x07, 0x00, 0x20, 0x00, 0x41, 0x32, 0x6a, 0x0b, 0x06, 0x00, 0x20, 0x00,
46 0x10, 0x01, 0x0b
47};
48
49BACKEND_TEST_CASE("test reentry", "[reentry]") {
50 struct test_runner;
53 struct test_runner {
55 uint32_t test_func_0(uint32_t val) {
56 return bkend->call_with_return(*this, "env", "bar", val)->to_ui32() + 50;
57 }
58 uint32_t test_func_1(uint32_t val) {
59 return bkend->call_with_return(*this, "env", "testbar", val)->to_ui32() + 50;
60 }
61 };
62
64 rhf_t::template add<&test_runner::test_func_0>("env", "test_func_0");
65 rhf_t::template add<&test_runner::test_func_1>("env", "test_func_1");
66
67 test_runner tr;
69
70 tr.bkend = &bkend;
71
72 CHECK(bkend.call_with_return(tr, "env", "foo", (uint32_t)10)->to_ui32() == 52);
73 CHECK(bkend.call_with_return(tr, "env", "testbar", (uint32_t)10)->to_ui32() == 110);
74 CHECK(bkend.call_with_return(tr, "env", "testbaz", (uint32_t)10)->to_ui32() == 160);
75}
wasm_allocator wa
Definition main.cpp:10
auto call_with_return(host_t &host, const std::string_view &mod, const std::string_view &func, Args... args)
Definition backend.hpp:178
#define CHECK(cond)
Definition util.h:80
backend_t bkend(hello_wasm, ehm, &wa)
std::vector< uint8_t > wasm_code
Definition types.hpp:147
std::vector< unsigned char > reentry_wasm
int add(int a, int b)
unsigned int uint32_t
Definition stdint.h:126
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59