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

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <br_0_wasm>", "[br_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_1_wasm>", "[br_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_10_wasm>", "[br_10_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_11_wasm>", "[br_11_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_12_wasm>", "[br_12_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_13_wasm>", "[br_13_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_14_wasm>", "[br_14_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_15_wasm>", "[br_15_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_16_wasm>", "[br_16_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_17_wasm>", "[br_17_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_18_wasm>", "[br_18_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_19_wasm>", "[br_19_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_2_wasm>", "[br_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_20_wasm>", "[br_20_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_3_wasm>", "[br_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_4_wasm>", "[br_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_5_wasm>", "[br_5_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_6_wasm>", "[br_6_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_7_wasm>", "[br_7_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_8_wasm>", "[br_8_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <br_9_wasm>", "[br_9_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/21]

BACKEND_TEST_CASE ( "Testing wasm <br_0_wasm>" ,
"" [br_0_wasm_tests] )

Definition at line 18 of file br_tests.cpp.

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

BACKEND_TEST_CASE ( "Testing wasm <br_10_wasm>" ,
"" [br_10_wasm_tests] )

Definition at line 94 of file br_tests.cpp.

94 {
96 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_11_wasm>" ,
"" [br_11_wasm_tests] )

Definition at line 100 of file br_tests.cpp.

100 {
102 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_12_wasm>" ,
"" [br_12_wasm_tests] )

Definition at line 106 of file br_tests.cpp.

106 {
108 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_13_wasm>" ,
"" [br_13_wasm_tests] )

Definition at line 112 of file br_tests.cpp.

112 {
114 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_14_wasm>" ,
"" [br_14_wasm_tests] )

Definition at line 118 of file br_tests.cpp.

118 {
120 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_15_wasm>" ,
"" [br_15_wasm_tests] )

Definition at line 124 of file br_tests.cpp.

124 {
126 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_16_wasm>" ,
"" [br_16_wasm_tests] )

Definition at line 130 of file br_tests.cpp.

130 {
132 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_17_wasm>" ,
"" [br_17_wasm_tests] )

Definition at line 136 of file br_tests.cpp.

136 {
138 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_18_wasm>" ,
"" [br_18_wasm_tests] )

Definition at line 142 of file br_tests.cpp.

142 {
144 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_19_wasm>" ,
"" [br_19_wasm_tests] )

Definition at line 148 of file br_tests.cpp.

148 {
150 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_1_wasm>" ,
"" [br_1_wasm_tests] )

Definition at line 88 of file br_tests.cpp.

88 {
90 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_20_wasm>" ,
"" [br_20_wasm_tests] )

Definition at line 160 of file br_tests.cpp.

160 {
162 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_2_wasm>" ,
"" [br_2_wasm_tests] )

Definition at line 154 of file br_tests.cpp.

154 {
156 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_3_wasm>" ,
"" [br_3_wasm_tests] )

Definition at line 166 of file br_tests.cpp.

166 {
168 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_4_wasm>" ,
"" [br_4_wasm_tests] )

Definition at line 172 of file br_tests.cpp.

172 {
174 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_5_wasm>" ,
"" [br_5_wasm_tests] )

Definition at line 178 of file br_tests.cpp.

178 {
180 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_6_wasm>" ,
"" [br_6_wasm_tests] )

Definition at line 184 of file br_tests.cpp.

184 {
186 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_7_wasm>" ,
"" [br_7_wasm_tests] )

Definition at line 190 of file br_tests.cpp.

190 {
192 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_8_wasm>" ,
"" [br_8_wasm_tests] )

Definition at line 196 of file br_tests.cpp.

196 {
198 auto code = read_wasm( std::string(wasm_directory) + "br.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 <br_9_wasm>" ,
"" [br_9_wasm_tests] )

Definition at line 202 of file br_tests.cpp.

202 {
204 auto code = read_wasm( std::string(wasm_directory) + "br.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.