Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
func_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 <func_0_wasm>", "[func_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "func.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(!bkend.call_with_return("env", "type-use-1"));
24 CHECK(bkend.call_with_return("env", "type-use-2")->to_ui32() == UINT32_C(0));
25 CHECK(!bkend.call_with_return("env", "type-use-3", UINT32_C(1)));
26 CHECK(bkend.call_with_return("env", "type-use-4", UINT32_C(1), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(1))->to_ui32() == UINT32_C(0));
27 CHECK(bkend.call_with_return("env", "type-use-5")->to_ui32() == UINT32_C(0));
28 CHECK(!bkend.call_with_return("env", "type-use-6", UINT32_C(1)));
29 CHECK(bkend.call_with_return("env", "type-use-7", UINT32_C(1), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(1))->to_ui32() == UINT32_C(0));
30 CHECK(bkend.call_with_return("env", "local-first-i32")->to_ui32() == UINT32_C(0));
31 CHECK(bkend.call_with_return("env", "local-first-i64")->to_ui64() == UINT32_C(0));
32 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "local-first-f32")->to_f32()) == UINT32_C(0));
33 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "local-first-f64")->to_f64()) == UINT64_C(0));
34 CHECK(bkend.call_with_return("env", "local-second-i32")->to_ui32() == UINT32_C(0));
35 CHECK(bkend.call_with_return("env", "local-second-i64")->to_ui64() == UINT32_C(0));
36 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "local-second-f32")->to_f32()) == UINT32_C(0));
37 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "local-second-f64")->to_f64()) == UINT64_C(0));
38 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "local-mixed")->to_f64()) == UINT64_C(0));
39 CHECK(bkend.call_with_return("env", "param-first-i32", UINT32_C(2), UINT32_C(3))->to_ui32() == UINT32_C(2));
40 CHECK(bkend.call_with_return("env", "param-first-i64", UINT64_C(2), UINT64_C(3))->to_ui64() == UINT32_C(2));
41 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "param-first-f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(1077936128)))->to_f32()) == UINT32_C(1073741824));
42 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "param-first-f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(4613937818241073152)))->to_f64()) == UINT64_C(4611686018427387904));
43 CHECK(bkend.call_with_return("env", "param-second-i32", UINT32_C(2), UINT32_C(3))->to_ui32() == UINT32_C(3));
44 CHECK(bkend.call_with_return("env", "param-second-i64", UINT64_C(2), UINT64_C(3))->to_ui64() == UINT32_C(3));
45 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "param-second-f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(1077936128)))->to_f32()) == UINT32_C(1077936128));
46 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "param-second-f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(4613937818241073152)))->to_f64()) == UINT64_C(4613937818241073152));
47 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "param-mixed", bit_cast<float>(UINT32_C(1065353216)), UINT32_C(2), UINT64_C(3), UINT32_C(4), bit_cast<double>(UINT64_C(4617878467915022336)), UINT32_C(6))->to_f64()) == UINT64_C(4617878467915022336));
48 CHECK(!bkend.call_with_return("env", "empty"));
49 CHECK(!bkend.call_with_return("env", "value-void"));
50 CHECK(bkend.call_with_return("env", "value-i32")->to_ui32() == UINT32_C(77));
51 CHECK(bkend.call_with_return("env", "value-i64")->to_ui64() == UINT32_C(7777));
52 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "value-f32")->to_f32()) == UINT32_C(1117480550));
53 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "value-f64")->to_f64()) == UINT64_C(4635172994171566817));
54 CHECK(!bkend.call_with_return("env", "value-block-void"));
55 CHECK(bkend.call_with_return("env", "value-block-i32")->to_ui32() == UINT32_C(77));
56 CHECK(!bkend.call_with_return("env", "return-empty"));
57 CHECK(bkend.call_with_return("env", "return-i32")->to_ui32() == UINT32_C(78));
58 CHECK(bkend.call_with_return("env", "return-i64")->to_ui64() == UINT32_C(7878));
59 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "return-f32")->to_f32()) == UINT32_C(1117611622));
60 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "return-f64")->to_f64()) == UINT64_C(4635244066603186258));
61 CHECK(bkend.call_with_return("env", "return-block-i32")->to_ui32() == UINT32_C(77));
62 CHECK(!bkend.call_with_return("env", "break-empty"));
63 CHECK(bkend.call_with_return("env", "break-i32")->to_ui32() == UINT32_C(79));
64 CHECK(bkend.call_with_return("env", "break-i64")->to_ui64() == UINT32_C(7979));
65 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "break-f32")->to_f32()) == UINT32_C(1117768909));
66 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "break-f64")->to_f64()) == UINT64_C(4635315139034805699));
67 CHECK(bkend.call_with_return("env", "break-block-i32")->to_ui32() == UINT32_C(77));
68 CHECK(!bkend.call_with_return("env", "break-br_if-empty", UINT32_C(0)));
69 CHECK(!bkend.call_with_return("env", "break-br_if-empty", UINT32_C(2)));
70 CHECK(bkend.call_with_return("env", "break-br_if-num", UINT32_C(0))->to_ui32() == UINT32_C(51));
71 CHECK(bkend.call_with_return("env", "break-br_if-num", UINT32_C(1))->to_ui32() == UINT32_C(50));
72 CHECK(!bkend.call_with_return("env", "break-br_table-empty", UINT32_C(0)));
73 CHECK(!bkend.call_with_return("env", "break-br_table-empty", UINT32_C(1)));
74 CHECK(!bkend.call_with_return("env", "break-br_table-empty", UINT32_C(5)));
75 CHECK(!bkend.call_with_return("env", "break-br_table-empty", UINT32_C(4294967295)));
76 CHECK(bkend.call_with_return("env", "break-br_table-num", UINT32_C(0))->to_ui32() == UINT32_C(50));
77 CHECK(bkend.call_with_return("env", "break-br_table-num", UINT32_C(1))->to_ui32() == UINT32_C(50));
78 CHECK(bkend.call_with_return("env", "break-br_table-num", UINT32_C(10))->to_ui32() == UINT32_C(50));
79 CHECK(bkend.call_with_return("env", "break-br_table-num", UINT32_C(4294967196))->to_ui32() == UINT32_C(50));
80 CHECK(!bkend.call_with_return("env", "break-br_table-nested-empty", UINT32_C(0)));
81 CHECK(!bkend.call_with_return("env", "break-br_table-nested-empty", UINT32_C(1)));
82 CHECK(!bkend.call_with_return("env", "break-br_table-nested-empty", UINT32_C(3)));
83 CHECK(!bkend.call_with_return("env", "break-br_table-nested-empty", UINT32_C(4294967294)));
84 CHECK(bkend.call_with_return("env", "break-br_table-nested-num", UINT32_C(0))->to_ui32() == UINT32_C(52));
85 CHECK(bkend.call_with_return("env", "break-br_table-nested-num", UINT32_C(1))->to_ui32() == UINT32_C(50));
86 CHECK(bkend.call_with_return("env", "break-br_table-nested-num", UINT32_C(2))->to_ui32() == UINT32_C(52));
87 CHECK(bkend.call_with_return("env", "break-br_table-nested-num", UINT32_C(4294967293))->to_ui32() == UINT32_C(52));
88 CHECK(bkend.call_with_return("env", "init-local-i32")->to_ui32() == UINT32_C(0));
89 CHECK(bkend.call_with_return("env", "init-local-i64")->to_ui64() == UINT32_C(0));
90 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "init-local-f32")->to_f32()) == UINT32_C(0));
91 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "init-local-f64")->to_f64()) == UINT64_C(0));
92}
93
94BACKEND_TEST_CASE( "Testing wasm <func_1_wasm>", "[func_1_wasm_tests]" ) {
96 auto code = read_wasm( std::string(wasm_directory) + "func.1.wasm");
97 backend_t bkend( code, &wa );
98
99}
100
101BACKEND_TEST_CASE( "Testing wasm <func_14_wasm>", "[func_14_wasm_tests]" ) {
103 auto code = read_wasm( std::string(wasm_directory) + "func.14.wasm");
104 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
105}
106
107BACKEND_TEST_CASE( "Testing wasm <func_15_wasm>", "[func_15_wasm_tests]" ) {
109 auto code = read_wasm( std::string(wasm_directory) + "func.15.wasm");
110 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
111}
112
113BACKEND_TEST_CASE( "Testing wasm <func_16_wasm>", "[func_16_wasm_tests]" ) {
115 auto code = read_wasm( std::string(wasm_directory) + "func.16.wasm");
116 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
117}
118
119BACKEND_TEST_CASE( "Testing wasm <func_17_wasm>", "[func_17_wasm_tests]" ) {
121 auto code = read_wasm( std::string(wasm_directory) + "func.17.wasm");
122 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
123}
124
125BACKEND_TEST_CASE( "Testing wasm <func_18_wasm>", "[func_18_wasm_tests]" ) {
127 auto code = read_wasm( std::string(wasm_directory) + "func.18.wasm");
128 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
129}
130
131BACKEND_TEST_CASE( "Testing wasm <func_19_wasm>", "[func_19_wasm_tests]" ) {
133 auto code = read_wasm( std::string(wasm_directory) + "func.19.wasm");
134 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
135}
136
137BACKEND_TEST_CASE( "Testing wasm <func_2_wasm>", "[func_2_wasm_tests]" ) {
139 auto code = read_wasm( std::string(wasm_directory) + "func.2.wasm");
140 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
141}
142
143BACKEND_TEST_CASE( "Testing wasm <func_20_wasm>", "[func_20_wasm_tests]" ) {
145 auto code = read_wasm( std::string(wasm_directory) + "func.20.wasm");
146 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
147}
148
149BACKEND_TEST_CASE( "Testing wasm <func_21_wasm>", "[func_21_wasm_tests]" ) {
151 auto code = read_wasm( std::string(wasm_directory) + "func.21.wasm");
152 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
153}
154
155BACKEND_TEST_CASE( "Testing wasm <func_22_wasm>", "[func_22_wasm_tests]" ) {
157 auto code = read_wasm( std::string(wasm_directory) + "func.22.wasm");
158 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
159}
160
161BACKEND_TEST_CASE( "Testing wasm <func_23_wasm>", "[func_23_wasm_tests]" ) {
163 auto code = read_wasm( std::string(wasm_directory) + "func.23.wasm");
164 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
165}
166
167BACKEND_TEST_CASE( "Testing wasm <func_24_wasm>", "[func_24_wasm_tests]" ) {
169 auto code = read_wasm( std::string(wasm_directory) + "func.24.wasm");
170 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
171}
172
173BACKEND_TEST_CASE( "Testing wasm <func_25_wasm>", "[func_25_wasm_tests]" ) {
175 auto code = read_wasm( std::string(wasm_directory) + "func.25.wasm");
176 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
177}
178
179BACKEND_TEST_CASE( "Testing wasm <func_26_wasm>", "[func_26_wasm_tests]" ) {
181 auto code = read_wasm( std::string(wasm_directory) + "func.26.wasm");
182 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
183}
184
185BACKEND_TEST_CASE( "Testing wasm <func_27_wasm>", "[func_27_wasm_tests]" ) {
187 auto code = read_wasm( std::string(wasm_directory) + "func.27.wasm");
188 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
189}
190
191BACKEND_TEST_CASE( "Testing wasm <func_28_wasm>", "[func_28_wasm_tests]" ) {
193 auto code = read_wasm( std::string(wasm_directory) + "func.28.wasm");
194 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
195}
196
197BACKEND_TEST_CASE( "Testing wasm <func_29_wasm>", "[func_29_wasm_tests]" ) {
199 auto code = read_wasm( std::string(wasm_directory) + "func.29.wasm");
200 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
201}
202
203BACKEND_TEST_CASE( "Testing wasm <func_3_wasm>", "[func_3_wasm_tests]" ) {
205 auto code = read_wasm( std::string(wasm_directory) + "func.3.wasm");
206 backend_t bkend( code, &wa );
207
208 CHECK(!bkend.call_with_return("env", "signature-explicit-reused"));
209 CHECK(!bkend.call_with_return("env", "signature-implicit-reused"));
210 CHECK(!bkend.call_with_return("env", "signature-explicit-duplicate"));
211 CHECK(!bkend.call_with_return("env", "signature-implicit-duplicate"));
212}
213
214BACKEND_TEST_CASE( "Testing wasm <func_30_wasm>", "[func_30_wasm_tests]" ) {
216 auto code = read_wasm( std::string(wasm_directory) + "func.30.wasm");
217 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
218}
219
220BACKEND_TEST_CASE( "Testing wasm <func_31_wasm>", "[func_31_wasm_tests]" ) {
222 auto code = read_wasm( std::string(wasm_directory) + "func.31.wasm");
223 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
224}
225
226BACKEND_TEST_CASE( "Testing wasm <func_32_wasm>", "[func_32_wasm_tests]" ) {
228 auto code = read_wasm( std::string(wasm_directory) + "func.32.wasm");
229 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
230}
231
232BACKEND_TEST_CASE( "Testing wasm <func_33_wasm>", "[func_33_wasm_tests]" ) {
234 auto code = read_wasm( std::string(wasm_directory) + "func.33.wasm");
235 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
236}
237
238BACKEND_TEST_CASE( "Testing wasm <func_34_wasm>", "[func_34_wasm_tests]" ) {
240 auto code = read_wasm( std::string(wasm_directory) + "func.34.wasm");
241 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
242}
243
244BACKEND_TEST_CASE( "Testing wasm <func_35_wasm>", "[func_35_wasm_tests]" ) {
246 auto code = read_wasm( std::string(wasm_directory) + "func.35.wasm");
247 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
248}
249
250BACKEND_TEST_CASE( "Testing wasm <func_36_wasm>", "[func_36_wasm_tests]" ) {
252 auto code = read_wasm( std::string(wasm_directory) + "func.36.wasm");
253 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
254}
255
256BACKEND_TEST_CASE( "Testing wasm <func_37_wasm>", "[func_37_wasm_tests]" ) {
258 auto code = read_wasm( std::string(wasm_directory) + "func.37.wasm");
259 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
260}
261
262BACKEND_TEST_CASE( "Testing wasm <func_38_wasm>", "[func_38_wasm_tests]" ) {
264 auto code = read_wasm( std::string(wasm_directory) + "func.38.wasm");
265 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
266}
267
268BACKEND_TEST_CASE( "Testing wasm <func_39_wasm>", "[func_39_wasm_tests]" ) {
270 auto code = read_wasm( std::string(wasm_directory) + "func.39.wasm");
271 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
272}
273
274BACKEND_TEST_CASE( "Testing wasm <func_40_wasm>", "[func_40_wasm_tests]" ) {
276 auto code = read_wasm( std::string(wasm_directory) + "func.40.wasm");
277 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
278}
279
280BACKEND_TEST_CASE( "Testing wasm <func_41_wasm>", "[func_41_wasm_tests]" ) {
282 auto code = read_wasm( std::string(wasm_directory) + "func.41.wasm");
283 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
284}
285
286BACKEND_TEST_CASE( "Testing wasm <func_42_wasm>", "[func_42_wasm_tests]" ) {
288 auto code = read_wasm( std::string(wasm_directory) + "func.42.wasm");
289 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
290}
291
292BACKEND_TEST_CASE( "Testing wasm <func_43_wasm>", "[func_43_wasm_tests]" ) {
294 auto code = read_wasm( std::string(wasm_directory) + "func.43.wasm");
295 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
296}
297
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
wasm_allocator wa
Definition main.cpp:10
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