Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
return_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 return_tests.cpp:

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <return_0_wasm>", "[return_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_1_wasm>", "[return_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_10_wasm>", "[return_10_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_11_wasm>", "[return_11_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_12_wasm>", "[return_12_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_13_wasm>", "[return_13_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_14_wasm>", "[return_14_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_15_wasm>", "[return_15_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_16_wasm>", "[return_16_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_17_wasm>", "[return_17_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_18_wasm>", "[return_18_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_19_wasm>", "[return_19_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_2_wasm>", "[return_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_20_wasm>", "[return_20_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_3_wasm>", "[return_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_4_wasm>", "[return_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_5_wasm>", "[return_5_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_6_wasm>", "[return_6_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_7_wasm>", "[return_7_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_8_wasm>", "[return_8_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <return_9_wasm>", "[return_9_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/21]

BACKEND_TEST_CASE ( "Testing wasm <return_0_wasm>" ,
"" [return_0_wasm_tests] )

Definition at line 18 of file return_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "return.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(!bkend.call_with_return("env", "type-i32"));
24 CHECK(!bkend.call_with_return("env", "type-i64"));
25 CHECK(!bkend.call_with_return("env", "type-f32"));
26 CHECK(!bkend.call_with_return("env", "type-f64"));
27 CHECK(bkend.call_with_return("env", "type-i32-value")->to_ui32() == UINT32_C(1));
28 CHECK(bkend.call_with_return("env", "type-i64-value")->to_ui64() == UINT32_C(2));
29 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "type-f32-value")->to_f32()) == UINT32_C(1077936128));
30 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "type-f64-value")->to_f64()) == UINT64_C(4616189618054758400));
31 CHECK(!bkend.call_with_return("env", "nullary"));
32 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "unary")->to_f64()) == UINT64_C(4613937818241073152));
33 CHECK(bkend.call_with_return("env", "as-func-first")->to_ui32() == UINT32_C(1));
34 CHECK(bkend.call_with_return("env", "as-func-mid")->to_ui32() == UINT32_C(2));
35 CHECK(!bkend.call_with_return("env", "as-func-last"));
36 CHECK(bkend.call_with_return("env", "as-func-value")->to_ui32() == UINT32_C(3));
37 CHECK(!bkend.call_with_return("env", "as-block-first"));
38 CHECK(!bkend.call_with_return("env", "as-block-mid"));
39 CHECK(!bkend.call_with_return("env", "as-block-last"));
40 CHECK(bkend.call_with_return("env", "as-block-value")->to_ui32() == UINT32_C(2));
41 CHECK(bkend.call_with_return("env", "as-loop-first")->to_ui32() == UINT32_C(3));
42 CHECK(bkend.call_with_return("env", "as-loop-mid")->to_ui32() == UINT32_C(4));
43 CHECK(bkend.call_with_return("env", "as-loop-last")->to_ui32() == UINT32_C(5));
44 CHECK(bkend.call_with_return("env", "as-br-value")->to_ui32() == UINT32_C(9));
45 CHECK(!bkend.call_with_return("env", "as-br_if-cond"));
46 CHECK(bkend.call_with_return("env", "as-br_if-value")->to_ui32() == UINT32_C(8));
47 CHECK(bkend.call_with_return("env", "as-br_if-value-cond")->to_ui32() == UINT32_C(9));
48 CHECK(bkend.call_with_return("env", "as-br_table-index")->to_ui64() == UINT32_C(9));
49 CHECK(bkend.call_with_return("env", "as-br_table-value")->to_ui32() == UINT32_C(10));
50 CHECK(bkend.call_with_return("env", "as-br_table-value-index")->to_ui32() == UINT32_C(11));
51 CHECK(bkend.call_with_return("env", "as-return-value")->to_ui64() == UINT32_C(7));
52 CHECK(bkend.call_with_return("env", "as-if-cond")->to_ui32() == UINT32_C(2));
53 CHECK(bkend.call_with_return("env", "as-if-then", UINT32_C(1), UINT32_C(6))->to_ui32() == UINT32_C(3));
54 CHECK(bkend.call_with_return("env", "as-if-then", UINT32_C(0), UINT32_C(6))->to_ui32() == UINT32_C(6));
55 CHECK(bkend.call_with_return("env", "as-if-else", UINT32_C(0), UINT32_C(6))->to_ui32() == UINT32_C(4));
56 CHECK(bkend.call_with_return("env", "as-if-else", UINT32_C(1), UINT32_C(6))->to_ui32() == UINT32_C(6));
57 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(0), UINT32_C(6))->to_ui32() == UINT32_C(5));
58 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(1), UINT32_C(6))->to_ui32() == UINT32_C(5));
59 CHECK(bkend.call_with_return("env", "as-select-second", UINT32_C(0), UINT32_C(6))->to_ui32() == UINT32_C(6));
60 CHECK(bkend.call_with_return("env", "as-select-second", UINT32_C(1), UINT32_C(6))->to_ui32() == UINT32_C(6));
61 CHECK(bkend.call_with_return("env", "as-select-cond")->to_ui32() == UINT32_C(7));
62 CHECK(bkend.call_with_return("env", "as-call-first")->to_ui32() == UINT32_C(12));
63 CHECK(bkend.call_with_return("env", "as-call-mid")->to_ui32() == UINT32_C(13));
64 CHECK(bkend.call_with_return("env", "as-call-last")->to_ui32() == UINT32_C(14));
65 CHECK(bkend.call_with_return("env", "as-call_indirect-func")->to_ui32() == UINT32_C(20));
66 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(21));
67 CHECK(bkend.call_with_return("env", "as-call_indirect-mid")->to_ui32() == UINT32_C(22));
68 CHECK(bkend.call_with_return("env", "as-call_indirect-last")->to_ui32() == UINT32_C(23));
69 CHECK(bkend.call_with_return("env", "as-local.set-value")->to_ui32() == UINT32_C(17));
70 CHECK(bkend.call_with_return("env", "as-local.tee-value")->to_ui32() == UINT32_C(1));
71 CHECK(bkend.call_with_return("env", "as-global.set-value")->to_ui32() == UINT32_C(1));
72 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "as-load-address")->to_f32()) == UINT32_C(1071225242));
73 CHECK(bkend.call_with_return("env", "as-loadN-address")->to_ui64() == UINT32_C(30));
74 CHECK(bkend.call_with_return("env", "as-store-address")->to_ui32() == UINT32_C(30));
75 CHECK(bkend.call_with_return("env", "as-store-value")->to_ui32() == UINT32_C(31));
76 CHECK(bkend.call_with_return("env", "as-storeN-address")->to_ui32() == UINT32_C(32));
77 CHECK(bkend.call_with_return("env", "as-storeN-value")->to_ui32() == UINT32_C(33));
78 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "as-unary-operand")->to_f32()) == UINT32_C(1079613850));
79 CHECK(bkend.call_with_return("env", "as-binary-left")->to_ui32() == UINT32_C(3));
80 CHECK(bkend.call_with_return("env", "as-binary-right")->to_ui64() == UINT32_C(45));
81 CHECK(bkend.call_with_return("env", "as-test-operand")->to_ui32() == UINT32_C(44));
82 CHECK(bkend.call_with_return("env", "as-compare-left")->to_ui32() == UINT32_C(43));
83 CHECK(bkend.call_with_return("env", "as-compare-right")->to_ui32() == UINT32_C(42));
84 CHECK(bkend.call_with_return("env", "as-convert-operand")->to_ui32() == UINT32_C(41));
85 CHECK(bkend.call_with_return("env", "as-memory.grow-size")->to_ui32() == UINT32_C(40));
86}
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 > read_wasm(const std::string &fname)
Definition utils.hpp:30
wasm_allocator wa
Definition main.cpp:10
#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/21]

BACKEND_TEST_CASE ( "Testing wasm <return_10_wasm>" ,
"" [return_10_wasm_tests] )

Definition at line 94 of file return_tests.cpp.

94 {
96 auto code = read_wasm( std::string(wasm_directory) + "return.10.wasm");
97 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
98}
sysio::vm::backend< rhf_t > backend_t
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/21]

BACKEND_TEST_CASE ( "Testing wasm <return_11_wasm>" ,
"" [return_11_wasm_tests] )

Definition at line 100 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [4/21]

BACKEND_TEST_CASE ( "Testing wasm <return_12_wasm>" ,
"" [return_12_wasm_tests] )

Definition at line 106 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [5/21]

BACKEND_TEST_CASE ( "Testing wasm <return_13_wasm>" ,
"" [return_13_wasm_tests] )

Definition at line 112 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [6/21]

BACKEND_TEST_CASE ( "Testing wasm <return_14_wasm>" ,
"" [return_14_wasm_tests] )

Definition at line 118 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [7/21]

BACKEND_TEST_CASE ( "Testing wasm <return_15_wasm>" ,
"" [return_15_wasm_tests] )

Definition at line 124 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [8/21]

BACKEND_TEST_CASE ( "Testing wasm <return_16_wasm>" ,
"" [return_16_wasm_tests] )

Definition at line 130 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [9/21]

BACKEND_TEST_CASE ( "Testing wasm <return_17_wasm>" ,
"" [return_17_wasm_tests] )

Definition at line 136 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [10/21]

BACKEND_TEST_CASE ( "Testing wasm <return_18_wasm>" ,
"" [return_18_wasm_tests] )

Definition at line 142 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [11/21]

BACKEND_TEST_CASE ( "Testing wasm <return_19_wasm>" ,
"" [return_19_wasm_tests] )

Definition at line 148 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [12/21]

BACKEND_TEST_CASE ( "Testing wasm <return_1_wasm>" ,
"" [return_1_wasm_tests] )

Definition at line 88 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [13/21]

BACKEND_TEST_CASE ( "Testing wasm <return_20_wasm>" ,
"" [return_20_wasm_tests] )

Definition at line 160 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [14/21]

BACKEND_TEST_CASE ( "Testing wasm <return_2_wasm>" ,
"" [return_2_wasm_tests] )

Definition at line 154 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [15/21]

BACKEND_TEST_CASE ( "Testing wasm <return_3_wasm>" ,
"" [return_3_wasm_tests] )

Definition at line 166 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [16/21]

BACKEND_TEST_CASE ( "Testing wasm <return_4_wasm>" ,
"" [return_4_wasm_tests] )

Definition at line 172 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [17/21]

BACKEND_TEST_CASE ( "Testing wasm <return_5_wasm>" ,
"" [return_5_wasm_tests] )

Definition at line 178 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [18/21]

BACKEND_TEST_CASE ( "Testing wasm <return_6_wasm>" ,
"" [return_6_wasm_tests] )

Definition at line 184 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [19/21]

BACKEND_TEST_CASE ( "Testing wasm <return_7_wasm>" ,
"" [return_7_wasm_tests] )

Definition at line 190 of file return_tests.cpp.

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

◆ BACKEND_TEST_CASE() [20/21]

BACKEND_TEST_CASE ( "Testing wasm <return_8_wasm>" ,
"" [return_8_wasm_tests] )

Definition at line 196 of file return_tests.cpp.

196 {
198 auto code = read_wasm( std::string(wasm_directory) + "return.8.wasm");
199 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
200}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [21/21]

BACKEND_TEST_CASE ( "Testing wasm <return_9_wasm>" ,
"" [return_9_wasm_tests] )

Definition at line 202 of file return_tests.cpp.

202 {
204 auto code = read_wasm( std::string(wasm_directory) + "return.9.wasm");
205 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
206}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.