Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
br_if_tests.cpp
Go to the documentation of this file.
1// Generated by spec_test_generator. DO NOT MODIFY THIS FILE.
2
3#include <algorithm>
4#include <vector>
5#include <iostream>
6#include <iterator>
7#include <cmath>
8#include <cstdlib>
9#include <catch2/catch.hpp>
10#include <utils.hpp>
11#include <wasm_config.hpp>
12#include <sysio/vm/backend.hpp>
13
14using namespace sysio;
15using namespace sysio::vm;
16extern wasm_allocator wa;
17
18BACKEND_TEST_CASE( "Testing wasm <br_if_0_wasm>", "[br_if_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "br_if.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", UINT32_C(0))->to_ui32() == UINT32_C(2));
32 CHECK(bkend.call_with_return("env", "as-block-first", UINT32_C(1))->to_ui32() == UINT32_C(3));
33 CHECK(bkend.call_with_return("env", "as-block-mid", UINT32_C(0))->to_ui32() == UINT32_C(2));
34 CHECK(bkend.call_with_return("env", "as-block-mid", UINT32_C(1))->to_ui32() == UINT32_C(3));
35 CHECK(!bkend.call_with_return("env", "as-block-last", UINT32_C(0)));
36 CHECK(!bkend.call_with_return("env", "as-block-last", UINT32_C(1)));
37 CHECK(bkend.call_with_return("env", "as-block-first-value", UINT32_C(0))->to_ui32() == UINT32_C(11));
38 CHECK(bkend.call_with_return("env", "as-block-first-value", UINT32_C(1))->to_ui32() == UINT32_C(10));
39 CHECK(bkend.call_with_return("env", "as-block-mid-value", UINT32_C(0))->to_ui32() == UINT32_C(21));
40 CHECK(bkend.call_with_return("env", "as-block-mid-value", UINT32_C(1))->to_ui32() == UINT32_C(20));
41 CHECK(bkend.call_with_return("env", "as-block-last-value", UINT32_C(0))->to_ui32() == UINT32_C(11));
42 CHECK(bkend.call_with_return("env", "as-block-last-value", UINT32_C(1))->to_ui32() == UINT32_C(11));
43 CHECK(bkend.call_with_return("env", "as-loop-first", UINT32_C(0))->to_ui32() == UINT32_C(2));
44 CHECK(bkend.call_with_return("env", "as-loop-first", UINT32_C(1))->to_ui32() == UINT32_C(3));
45 CHECK(bkend.call_with_return("env", "as-loop-mid", UINT32_C(0))->to_ui32() == UINT32_C(2));
46 CHECK(bkend.call_with_return("env", "as-loop-mid", UINT32_C(1))->to_ui32() == UINT32_C(4));
47 CHECK(!bkend.call_with_return("env", "as-loop-last", UINT32_C(0)));
48 CHECK(!bkend.call_with_return("env", "as-loop-last", UINT32_C(1)));
49 CHECK(bkend.call_with_return("env", "as-br-value")->to_ui32() == UINT32_C(1));
50 CHECK(!bkend.call_with_return("env", "as-br_if-cond"));
51 CHECK(bkend.call_with_return("env", "as-br_if-value")->to_ui32() == UINT32_C(1));
52 CHECK(bkend.call_with_return("env", "as-br_if-value-cond", UINT32_C(0))->to_ui32() == UINT32_C(2));
53 CHECK(bkend.call_with_return("env", "as-br_if-value-cond", UINT32_C(1))->to_ui32() == UINT32_C(1));
54 CHECK(!bkend.call_with_return("env", "as-br_table-index"));
55 CHECK(bkend.call_with_return("env", "as-br_table-value")->to_ui32() == UINT32_C(1));
56 CHECK(bkend.call_with_return("env", "as-br_table-value-index")->to_ui32() == UINT32_C(1));
57 CHECK(bkend.call_with_return("env", "as-return-value")->to_ui64() == UINT32_C(1));
58 CHECK(bkend.call_with_return("env", "as-if-cond", UINT32_C(0))->to_ui32() == UINT32_C(2));
59 CHECK(bkend.call_with_return("env", "as-if-cond", UINT32_C(1))->to_ui32() == UINT32_C(1));
60 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(0), UINT32_C(0)));
61 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(4), UINT32_C(0)));
62 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(0), UINT32_C(1)));
63 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(4), UINT32_C(1)));
64 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(0), UINT32_C(0)));
65 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(3), UINT32_C(0)));
66 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(0), UINT32_C(1)));
67 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(3), UINT32_C(1)));
68 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(0))->to_ui32() == UINT32_C(3));
69 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(1))->to_ui32() == UINT32_C(3));
70 CHECK(bkend.call_with_return("env", "as-select-second", UINT32_C(0))->to_ui32() == UINT32_C(3));
71 CHECK(bkend.call_with_return("env", "as-select-second", UINT32_C(1))->to_ui32() == UINT32_C(3));
72 CHECK(bkend.call_with_return("env", "as-select-cond")->to_ui32() == UINT32_C(3));
73 CHECK(bkend.call_with_return("env", "as-call-first")->to_ui32() == UINT32_C(12));
74 CHECK(bkend.call_with_return("env", "as-call-mid")->to_ui32() == UINT32_C(13));
75 CHECK(bkend.call_with_return("env", "as-call-last")->to_ui32() == UINT32_C(14));
76 CHECK(bkend.call_with_return("env", "as-call_indirect-func")->to_ui32() == UINT32_C(4));
77 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(4));
78 CHECK(bkend.call_with_return("env", "as-call_indirect-mid")->to_ui32() == UINT32_C(4));
79 CHECK(bkend.call_with_return("env", "as-call_indirect-last")->to_ui32() == UINT32_C(4));
80 CHECK(bkend.call_with_return("env", "as-local.set-value", UINT32_C(0))->to_ui32() == UINT32_C(4294967295));
81 CHECK(bkend.call_with_return("env", "as-local.set-value", UINT32_C(1))->to_ui32() == UINT32_C(17));
82 CHECK(bkend.call_with_return("env", "as-local.tee-value", UINT32_C(0))->to_ui32() == UINT32_C(4294967295));
83 CHECK(bkend.call_with_return("env", "as-local.tee-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
84 CHECK(bkend.call_with_return("env", "as-global.set-value", UINT32_C(0))->to_ui32() == UINT32_C(4294967295));
85 CHECK(bkend.call_with_return("env", "as-global.set-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
86 CHECK(bkend.call_with_return("env", "as-load-address")->to_ui32() == UINT32_C(1));
87 CHECK(bkend.call_with_return("env", "as-loadN-address")->to_ui32() == UINT32_C(30));
88 CHECK(bkend.call_with_return("env", "as-store-address")->to_ui32() == UINT32_C(30));
89 CHECK(bkend.call_with_return("env", "as-store-value")->to_ui32() == UINT32_C(31));
90 CHECK(bkend.call_with_return("env", "as-storeN-address")->to_ui32() == UINT32_C(32));
91 CHECK(bkend.call_with_return("env", "as-storeN-value")->to_ui32() == UINT32_C(33));
92 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "as-unary-operand")->to_f64()) == UINT64_C(4607182418800017408));
93 CHECK(bkend.call_with_return("env", "as-binary-left")->to_ui32() == UINT32_C(1));
94 CHECK(bkend.call_with_return("env", "as-binary-right")->to_ui32() == UINT32_C(1));
95 CHECK(bkend.call_with_return("env", "as-test-operand")->to_ui32() == UINT32_C(0));
96 CHECK(bkend.call_with_return("env", "as-compare-left")->to_ui32() == UINT32_C(1));
97 CHECK(bkend.call_with_return("env", "as-compare-right")->to_ui32() == UINT32_C(1));
98 CHECK(bkend.call_with_return("env", "as-memory.grow-size")->to_ui32() == UINT32_C(1));
99 CHECK(bkend.call_with_return("env", "nested-block-value", UINT32_C(0))->to_ui32() == UINT32_C(21));
100 CHECK(bkend.call_with_return("env", "nested-block-value", UINT32_C(1))->to_ui32() == UINT32_C(9));
101 CHECK(bkend.call_with_return("env", "nested-br-value", UINT32_C(0))->to_ui32() == UINT32_C(5));
102 CHECK(bkend.call_with_return("env", "nested-br-value", UINT32_C(1))->to_ui32() == UINT32_C(9));
103 CHECK(bkend.call_with_return("env", "nested-br_if-value", UINT32_C(0))->to_ui32() == UINT32_C(5));
104 CHECK(bkend.call_with_return("env", "nested-br_if-value", UINT32_C(1))->to_ui32() == UINT32_C(9));
105 CHECK(bkend.call_with_return("env", "nested-br_if-value-cond", UINT32_C(0))->to_ui32() == UINT32_C(5));
106 CHECK(bkend.call_with_return("env", "nested-br_if-value-cond", UINT32_C(1))->to_ui32() == UINT32_C(9));
107 CHECK(bkend.call_with_return("env", "nested-br_table-value", UINT32_C(0))->to_ui32() == UINT32_C(5));
108 CHECK(bkend.call_with_return("env", "nested-br_table-value", UINT32_C(1))->to_ui32() == UINT32_C(9));
109 CHECK(bkend.call_with_return("env", "nested-br_table-value-index", UINT32_C(0))->to_ui32() == UINT32_C(5));
110 CHECK(bkend.call_with_return("env", "nested-br_table-value-index", UINT32_C(1))->to_ui32() == UINT32_C(9));
111}
112
113BACKEND_TEST_CASE( "Testing wasm <br_if_1_wasm>", "[br_if_1_wasm_tests]" ) {
115 auto code = read_wasm( std::string(wasm_directory) + "br_if.1.wasm");
116 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
117}
118
119BACKEND_TEST_CASE( "Testing wasm <br_if_10_wasm>", "[br_if_10_wasm_tests]" ) {
121 auto code = read_wasm( std::string(wasm_directory) + "br_if.10.wasm");
122 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
123}
124
125BACKEND_TEST_CASE( "Testing wasm <br_if_11_wasm>", "[br_if_11_wasm_tests]" ) {
127 auto code = read_wasm( std::string(wasm_directory) + "br_if.11.wasm");
128 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
129}
130
131BACKEND_TEST_CASE( "Testing wasm <br_if_12_wasm>", "[br_if_12_wasm_tests]" ) {
133 auto code = read_wasm( std::string(wasm_directory) + "br_if.12.wasm");
134 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
135}
136
137BACKEND_TEST_CASE( "Testing wasm <br_if_13_wasm>", "[br_if_13_wasm_tests]" ) {
139 auto code = read_wasm( std::string(wasm_directory) + "br_if.13.wasm");
140 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
141}
142
143BACKEND_TEST_CASE( "Testing wasm <br_if_14_wasm>", "[br_if_14_wasm_tests]" ) {
145 auto code = read_wasm( std::string(wasm_directory) + "br_if.14.wasm");
146 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
147}
148
149BACKEND_TEST_CASE( "Testing wasm <br_if_15_wasm>", "[br_if_15_wasm_tests]" ) {
151 auto code = read_wasm( std::string(wasm_directory) + "br_if.15.wasm");
152 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
153}
154
155BACKEND_TEST_CASE( "Testing wasm <br_if_16_wasm>", "[br_if_16_wasm_tests]" ) {
157 auto code = read_wasm( std::string(wasm_directory) + "br_if.16.wasm");
158 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
159}
160
161BACKEND_TEST_CASE( "Testing wasm <br_if_17_wasm>", "[br_if_17_wasm_tests]" ) {
163 auto code = read_wasm( std::string(wasm_directory) + "br_if.17.wasm");
164 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
165}
166
167BACKEND_TEST_CASE( "Testing wasm <br_if_18_wasm>", "[br_if_18_wasm_tests]" ) {
169 auto code = read_wasm( std::string(wasm_directory) + "br_if.18.wasm");
170 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
171}
172
173BACKEND_TEST_CASE( "Testing wasm <br_if_19_wasm>", "[br_if_19_wasm_tests]" ) {
175 auto code = read_wasm( std::string(wasm_directory) + "br_if.19.wasm");
176 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
177}
178
179BACKEND_TEST_CASE( "Testing wasm <br_if_2_wasm>", "[br_if_2_wasm_tests]" ) {
181 auto code = read_wasm( std::string(wasm_directory) + "br_if.2.wasm");
182 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
183}
184
185BACKEND_TEST_CASE( "Testing wasm <br_if_20_wasm>", "[br_if_20_wasm_tests]" ) {
187 auto code = read_wasm( std::string(wasm_directory) + "br_if.20.wasm");
188 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
189}
190
191BACKEND_TEST_CASE( "Testing wasm <br_if_21_wasm>", "[br_if_21_wasm_tests]" ) {
193 auto code = read_wasm( std::string(wasm_directory) + "br_if.21.wasm");
194 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
195}
196
197BACKEND_TEST_CASE( "Testing wasm <br_if_22_wasm>", "[br_if_22_wasm_tests]" ) {
199 auto code = read_wasm( std::string(wasm_directory) + "br_if.22.wasm");
200 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
201}
202
203BACKEND_TEST_CASE( "Testing wasm <br_if_23_wasm>", "[br_if_23_wasm_tests]" ) {
205 auto code = read_wasm( std::string(wasm_directory) + "br_if.23.wasm");
206 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
207}
208
209BACKEND_TEST_CASE( "Testing wasm <br_if_24_wasm>", "[br_if_24_wasm_tests]" ) {
211 auto code = read_wasm( std::string(wasm_directory) + "br_if.24.wasm");
212 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
213}
214
215BACKEND_TEST_CASE( "Testing wasm <br_if_25_wasm>", "[br_if_25_wasm_tests]" ) {
217 auto code = read_wasm( std::string(wasm_directory) + "br_if.25.wasm");
218 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
219}
220
221BACKEND_TEST_CASE( "Testing wasm <br_if_26_wasm>", "[br_if_26_wasm_tests]" ) {
223 auto code = read_wasm( std::string(wasm_directory) + "br_if.26.wasm");
224 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
225}
226
227BACKEND_TEST_CASE( "Testing wasm <br_if_27_wasm>", "[br_if_27_wasm_tests]" ) {
229 auto code = read_wasm( std::string(wasm_directory) + "br_if.27.wasm");
230 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
231}
232
233BACKEND_TEST_CASE( "Testing wasm <br_if_28_wasm>", "[br_if_28_wasm_tests]" ) {
235 auto code = read_wasm( std::string(wasm_directory) + "br_if.28.wasm");
236 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
237}
238
239BACKEND_TEST_CASE( "Testing wasm <br_if_29_wasm>", "[br_if_29_wasm_tests]" ) {
241 auto code = read_wasm( std::string(wasm_directory) + "br_if.29.wasm");
242 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
243}
244
245BACKEND_TEST_CASE( "Testing wasm <br_if_3_wasm>", "[br_if_3_wasm_tests]" ) {
247 auto code = read_wasm( std::string(wasm_directory) + "br_if.3.wasm");
248 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
249}
250
251BACKEND_TEST_CASE( "Testing wasm <br_if_4_wasm>", "[br_if_4_wasm_tests]" ) {
253 auto code = read_wasm( std::string(wasm_directory) + "br_if.4.wasm");
254 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
255}
256
257BACKEND_TEST_CASE( "Testing wasm <br_if_5_wasm>", "[br_if_5_wasm_tests]" ) {
259 auto code = read_wasm( std::string(wasm_directory) + "br_if.5.wasm");
260 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
261}
262
263BACKEND_TEST_CASE( "Testing wasm <br_if_6_wasm>", "[br_if_6_wasm_tests]" ) {
265 auto code = read_wasm( std::string(wasm_directory) + "br_if.6.wasm");
266 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
267}
268
269BACKEND_TEST_CASE( "Testing wasm <br_if_7_wasm>", "[br_if_7_wasm_tests]" ) {
271 auto code = read_wasm( std::string(wasm_directory) + "br_if.7.wasm");
272 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
273}
274
275BACKEND_TEST_CASE( "Testing wasm <br_if_8_wasm>", "[br_if_8_wasm_tests]" ) {
277 auto code = read_wasm( std::string(wasm_directory) + "br_if.8.wasm");
278 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
279}
280
281BACKEND_TEST_CASE( "Testing wasm <br_if_9_wasm>", "[br_if_9_wasm_tests]" ) {
283 auto code = read_wasm( std::string(wasm_directory) + "br_if.9.wasm");
284 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
285}
286
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)
sysio::vm::backend< rhf_t > backend_t
#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
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59
T bit_cast(const U &u)
Definition utils.hpp:35