Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
call_tests.cpp File Reference
#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdlib>
#include <catch2/catch.hpp>
#include <utils.hpp>
#include <wasm_config.hpp>
#include <sysio/vm/backend.hpp>
Include dependency graph for call_tests.cpp:

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <call_0_wasm>", "[call_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_1_wasm>", "[call_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_10_wasm>", "[call_10_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_11_wasm>", "[call_11_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_12_wasm>", "[call_12_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_13_wasm>", "[call_13_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_14_wasm>", "[call_14_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_15_wasm>", "[call_15_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_16_wasm>", "[call_16_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_17_wasm>", "[call_17_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_18_wasm>", "[call_18_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_2_wasm>", "[call_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_3_wasm>", "[call_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_4_wasm>", "[call_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_5_wasm>", "[call_5_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_6_wasm>", "[call_6_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_7_wasm>", "[call_7_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_8_wasm>", "[call_8_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <call_9_wasm>", "[call_9_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/19]

BACKEND_TEST_CASE ( "Testing wasm <call_0_wasm>" ,
"" [call_0_wasm_tests] )

Definition at line 18 of file call_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "call.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "type-i32")->to_ui32() == UINT32_C(306));
24 CHECK(bkend.call_with_return("env", "type-i64")->to_ui64() == UINT32_C(356));
25 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "type-f32")->to_f32()) == UINT32_C(1165172736));
26 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "type-f64")->to_f64()) == UINT64_C(4660882566700597248));
27 CHECK(bkend.call_with_return("env", "type-first-i32")->to_ui32() == UINT32_C(32));
28 CHECK(bkend.call_with_return("env", "type-first-i64")->to_ui64() == UINT32_C(64));
29 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "type-first-f32")->to_f32()) == UINT32_C(1068037571));
30 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "type-first-f64")->to_f64()) == UINT64_C(4610064722561534525));
31 CHECK(bkend.call_with_return("env", "type-second-i32")->to_ui32() == UINT32_C(32));
32 CHECK(bkend.call_with_return("env", "type-second-i64")->to_ui64() == UINT32_C(64));
33 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "type-second-f32")->to_f32()) == UINT32_C(1107296256));
34 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "type-second-f64")->to_f64()) == UINT64_C(4634211053438658150));
35 CHECK(bkend.call_with_return("env", "fac", UINT64_C(0))->to_ui64() == UINT32_C(1));
36 CHECK(bkend.call_with_return("env", "fac", UINT64_C(1))->to_ui64() == UINT32_C(1));
37 CHECK(bkend.call_with_return("env", "fac", UINT64_C(5))->to_ui64() == UINT32_C(120));
38 CHECK(bkend.call_with_return("env", "fac", UINT64_C(25))->to_ui64() == UINT32_C(7034535277573963776));
39 CHECK(bkend.call_with_return("env", "fac-acc", UINT64_C(0), UINT64_C(1))->to_ui64() == UINT32_C(1));
40 CHECK(bkend.call_with_return("env", "fac-acc", UINT64_C(1), UINT64_C(1))->to_ui64() == UINT32_C(1));
41 CHECK(bkend.call_with_return("env", "fac-acc", UINT64_C(5), UINT64_C(1))->to_ui64() == UINT32_C(120));
42 CHECK(bkend.call_with_return("env", "fac-acc", UINT64_C(25), UINT64_C(1))->to_ui64() == UINT32_C(7034535277573963776));
43 CHECK(bkend.call_with_return("env", "fib", UINT64_C(0))->to_ui64() == UINT32_C(1));
44 CHECK(bkend.call_with_return("env", "fib", UINT64_C(1))->to_ui64() == UINT32_C(1));
45 CHECK(bkend.call_with_return("env", "fib", UINT64_C(2))->to_ui64() == UINT32_C(2));
46 CHECK(bkend.call_with_return("env", "fib", UINT64_C(5))->to_ui64() == UINT32_C(8));
47 CHECK(bkend.call_with_return("env", "fib", UINT64_C(20))->to_ui64() == UINT32_C(10946));
48 CHECK(bkend.call_with_return("env", "even", UINT64_C(0))->to_ui32() == UINT32_C(44));
49 CHECK(bkend.call_with_return("env", "even", UINT64_C(1))->to_ui32() == UINT32_C(99));
50 CHECK(bkend.call_with_return("env", "even", UINT64_C(100))->to_ui32() == UINT32_C(44));
51 CHECK(bkend.call_with_return("env", "even", UINT64_C(77))->to_ui32() == UINT32_C(99));
52 CHECK(bkend.call_with_return("env", "odd", UINT64_C(0))->to_ui32() == UINT32_C(99));
53 CHECK(bkend.call_with_return("env", "odd", UINT64_C(1))->to_ui32() == UINT32_C(44));
54 CHECK(bkend.call_with_return("env", "odd", UINT64_C(200))->to_ui32() == UINT32_C(99));
55 CHECK(bkend.call_with_return("env", "odd", UINT64_C(77))->to_ui32() == UINT32_C(44));
56 CHECK(bkend.call_with_return("env", "as-select-first")->to_ui32() == UINT32_C(306));
57 CHECK(bkend.call_with_return("env", "as-select-mid")->to_ui32() == UINT32_C(2));
58 CHECK(bkend.call_with_return("env", "as-select-last")->to_ui32() == UINT32_C(2));
59 CHECK(bkend.call_with_return("env", "as-if-condition")->to_ui32() == UINT32_C(1));
60 CHECK(bkend.call_with_return("env", "as-br_if-first")->to_ui32() == UINT32_C(306));
61 CHECK(bkend.call_with_return("env", "as-br_if-last")->to_ui32() == UINT32_C(2));
62 CHECK(bkend.call_with_return("env", "as-br_table-first")->to_ui32() == UINT32_C(306));
63 CHECK(bkend.call_with_return("env", "as-br_table-last")->to_ui32() == UINT32_C(2));
64 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(306));
65 CHECK(bkend.call_with_return("env", "as-call_indirect-mid")->to_ui32() == UINT32_C(2));
66 CHECK_THROWS_AS(bkend("env", "as-call_indirect-last"), std::exception);
67 CHECK(!bkend.call_with_return("env", "as-store-first"));
68 CHECK(!bkend.call_with_return("env", "as-store-last"));
69 CHECK(bkend.call_with_return("env", "as-memory.grow-value")->to_ui32() == UINT32_C(1));
70 CHECK(bkend.call_with_return("env", "as-return-value")->to_ui32() == UINT32_C(306));
71 CHECK(!bkend.call_with_return("env", "as-drop-operand"));
72 CHECK(bkend.call_with_return("env", "as-br-value")->to_ui32() == UINT32_C(306));
73 CHECK(bkend.call_with_return("env", "as-local.set-value")->to_ui32() == UINT32_C(306));
74 CHECK(bkend.call_with_return("env", "as-local.tee-value")->to_ui32() == UINT32_C(306));
75 CHECK(bkend.call_with_return("env", "as-global.set-value")->to_ui32() == UINT32_C(306));
76 CHECK(bkend.call_with_return("env", "as-load-operand")->to_ui32() == UINT32_C(1));
77 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "as-unary-operand")->to_f32()) == UINT32_C(0));
78 CHECK(bkend.call_with_return("env", "as-binary-left")->to_ui32() == UINT32_C(11));
79 CHECK(bkend.call_with_return("env", "as-binary-right")->to_ui32() == UINT32_C(9));
80 CHECK(bkend.call_with_return("env", "as-test-operand")->to_ui32() == UINT32_C(0));
81 CHECK(bkend.call_with_return("env", "as-compare-left")->to_ui32() == UINT32_C(1));
82 CHECK(bkend.call_with_return("env", "as-compare-right")->to_ui32() == UINT32_C(1));
83 CHECK(bkend.call_with_return("env", "as-convert-operand")->to_ui64() == UINT32_C(1));
84}
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)
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
std::vector< uint8_t > read_wasm(const std::string &fname)
Definition utils.hpp:30
#define UINT32_C(val)
Definition stdint.h:283
#define UINT64_C(val)
Definition stdint.h:284
T bit_cast(const U &u)
Definition utils.hpp:35
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/19]

BACKEND_TEST_CASE ( "Testing wasm <call_10_wasm>" ,
"" [call_10_wasm_tests] )

Definition at line 92 of file call_tests.cpp.

92 {
94 auto code = read_wasm( std::string(wasm_directory) + "call.10.wasm");
95 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
96}
sysio::vm::backend< rhf_t > backend_t
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/19]

BACKEND_TEST_CASE ( "Testing wasm <call_11_wasm>" ,
"" [call_11_wasm_tests] )

Definition at line 98 of file call_tests.cpp.

98 {
100 auto code = read_wasm( std::string(wasm_directory) + "call.11.wasm");
101 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
102}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/19]

BACKEND_TEST_CASE ( "Testing wasm <call_12_wasm>" ,
"" [call_12_wasm_tests] )

Definition at line 104 of file call_tests.cpp.

104 {
106 auto code = read_wasm( std::string(wasm_directory) + "call.12.wasm");
107 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
108}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [5/19]

BACKEND_TEST_CASE ( "Testing wasm <call_13_wasm>" ,
"" [call_13_wasm_tests] )

Definition at line 110 of file call_tests.cpp.

110 {
112 auto code = read_wasm( std::string(wasm_directory) + "call.13.wasm");
113 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
114}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [6/19]

BACKEND_TEST_CASE ( "Testing wasm <call_14_wasm>" ,
"" [call_14_wasm_tests] )

Definition at line 116 of file call_tests.cpp.

116 {
118 auto code = read_wasm( std::string(wasm_directory) + "call.14.wasm");
119 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
120}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [7/19]

BACKEND_TEST_CASE ( "Testing wasm <call_15_wasm>" ,
"" [call_15_wasm_tests] )

Definition at line 122 of file call_tests.cpp.

122 {
124 auto code = read_wasm( std::string(wasm_directory) + "call.15.wasm");
125 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
126}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [8/19]

BACKEND_TEST_CASE ( "Testing wasm <call_16_wasm>" ,
"" [call_16_wasm_tests] )

Definition at line 128 of file call_tests.cpp.

128 {
130 auto code = read_wasm( std::string(wasm_directory) + "call.16.wasm");
131 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
132}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [9/19]

BACKEND_TEST_CASE ( "Testing wasm <call_17_wasm>" ,
"" [call_17_wasm_tests] )

Definition at line 134 of file call_tests.cpp.

134 {
136 auto code = read_wasm( std::string(wasm_directory) + "call.17.wasm");
137 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
138}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [10/19]

BACKEND_TEST_CASE ( "Testing wasm <call_18_wasm>" ,
"" [call_18_wasm_tests] )

Definition at line 140 of file call_tests.cpp.

140 {
142 auto code = read_wasm( std::string(wasm_directory) + "call.18.wasm");
143 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
144}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [11/19]

BACKEND_TEST_CASE ( "Testing wasm <call_1_wasm>" ,
"" [call_1_wasm_tests] )

Definition at line 86 of file call_tests.cpp.

86 {
88 auto code = read_wasm( std::string(wasm_directory) + "call.1.wasm");
89 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
90}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [12/19]

BACKEND_TEST_CASE ( "Testing wasm <call_2_wasm>" ,
"" [call_2_wasm_tests] )

Definition at line 146 of file call_tests.cpp.

146 {
148 auto code = read_wasm( std::string(wasm_directory) + "call.2.wasm");
149 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
150}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [13/19]

BACKEND_TEST_CASE ( "Testing wasm <call_3_wasm>" ,
"" [call_3_wasm_tests] )

Definition at line 152 of file call_tests.cpp.

152 {
154 auto code = read_wasm( std::string(wasm_directory) + "call.3.wasm");
155 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
156}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [14/19]

BACKEND_TEST_CASE ( "Testing wasm <call_4_wasm>" ,
"" [call_4_wasm_tests] )

Definition at line 158 of file call_tests.cpp.

158 {
160 auto code = read_wasm( std::string(wasm_directory) + "call.4.wasm");
161 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
162}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [15/19]

BACKEND_TEST_CASE ( "Testing wasm <call_5_wasm>" ,
"" [call_5_wasm_tests] )

Definition at line 164 of file call_tests.cpp.

164 {
166 auto code = read_wasm( std::string(wasm_directory) + "call.5.wasm");
167 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
168}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [16/19]

BACKEND_TEST_CASE ( "Testing wasm <call_6_wasm>" ,
"" [call_6_wasm_tests] )

Definition at line 170 of file call_tests.cpp.

170 {
172 auto code = read_wasm( std::string(wasm_directory) + "call.6.wasm");
173 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
174}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [17/19]

BACKEND_TEST_CASE ( "Testing wasm <call_7_wasm>" ,
"" [call_7_wasm_tests] )

Definition at line 176 of file call_tests.cpp.

176 {
178 auto code = read_wasm( std::string(wasm_directory) + "call.7.wasm");
179 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
180}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [18/19]

BACKEND_TEST_CASE ( "Testing wasm <call_8_wasm>" ,
"" [call_8_wasm_tests] )

Definition at line 182 of file call_tests.cpp.

182 {
184 auto code = read_wasm( std::string(wasm_directory) + "call.8.wasm");
185 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
186}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [19/19]

BACKEND_TEST_CASE ( "Testing wasm <call_9_wasm>" ,
"" [call_9_wasm_tests] )

Definition at line 188 of file call_tests.cpp.

188 {
190 auto code = read_wasm( std::string(wasm_directory) + "call.9.wasm");
191 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
192}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.