Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
select_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 <select_0_wasm>", "[select_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "select.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "select_i32", UINT32_C(1), UINT32_C(2), UINT32_C(1))->to_ui32() == UINT32_C(1));
24 CHECK(bkend.call_with_return("env", "select_i64", UINT64_C(2), UINT64_C(1), UINT32_C(1))->to_ui64() == UINT32_C(2));
25 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1073741824)), UINT32_C(1))->to_f32()) == UINT32_C(1065353216));
26 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(4607182418800017408)), bit_cast<double>(UINT64_C(4611686018427387904)), UINT32_C(1))->to_f64()) == UINT64_C(4607182418800017408));
27 CHECK(bkend.call_with_return("env", "select_i32", UINT32_C(1), UINT32_C(2), UINT32_C(0))->to_ui32() == UINT32_C(2));
28 CHECK(bkend.call_with_return("env", "select_i32", UINT32_C(2), UINT32_C(1), UINT32_C(0))->to_ui32() == UINT32_C(1));
29 CHECK(bkend.call_with_return("env", "select_i64", UINT64_C(2), UINT64_C(1), UINT32_C(4294967295))->to_ui64() == UINT32_C(2));
30 CHECK(bkend.call_with_return("env", "select_i64", UINT64_C(2), UINT64_C(1), UINT32_C(4042322160))->to_ui64() == UINT32_C(2));
31 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(2143289344)), bit_cast<float>(UINT32_C(1065353216)), UINT32_C(1))->to_f32()) == UINT32_C(2143289344));
32 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(2139226884)), bit_cast<float>(UINT32_C(1065353216)), UINT32_C(1))->to_f32()) == UINT32_C(2139226884));
33 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(2143289344)), bit_cast<float>(UINT32_C(1065353216)), UINT32_C(0))->to_f32()) == UINT32_C(1065353216));
34 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(2139226884)), bit_cast<float>(UINT32_C(1065353216)), UINT32_C(0))->to_f32()) == UINT32_C(1065353216));
35 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(2143289344)), UINT32_C(1))->to_f32()) == UINT32_C(1073741824));
36 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(2139226884)), UINT32_C(1))->to_f32()) == UINT32_C(1073741824));
37 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(2143289344)), UINT32_C(0))->to_f32()) == UINT32_C(2143289344));
38 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "select_f32", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(2139226884)), UINT32_C(0))->to_f32()) == UINT32_C(2139226884));
39 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(9221120237041090560)), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(1))->to_f64()) == UINT64_C(9221120237041090560));
40 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(9218868437227537156)), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(1))->to_f64()) == UINT64_C(9218868437227537156));
41 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(9221120237041090560)), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(0))->to_f64()) == UINT64_C(4607182418800017408));
42 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(9218868437227537156)), bit_cast<double>(UINT64_C(4607182418800017408)), UINT32_C(0))->to_f64()) == UINT64_C(4607182418800017408));
43 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(9221120237041090560)), UINT32_C(1))->to_f64()) == UINT64_C(4611686018427387904));
44 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(9218868437227537156)), UINT32_C(1))->to_f64()) == UINT64_C(4611686018427387904));
45 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(9221120237041090560)), UINT32_C(0))->to_f64()) == UINT64_C(9221120237041090560));
46 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "select_f64", bit_cast<double>(UINT64_C(4611686018427387904)), bit_cast<double>(UINT64_C(9218868437227537156)), UINT32_C(0))->to_f64()) == UINT64_C(9218868437227537156));
47 CHECK_THROWS_AS(bkend("env", "select_trap_l", UINT32_C(1)), std::exception);
48 CHECK_THROWS_AS(bkend("env", "select_trap_l", UINT32_C(0)), std::exception);
49 CHECK_THROWS_AS(bkend("env", "select_trap_r", UINT32_C(1)), std::exception);
50 CHECK_THROWS_AS(bkend("env", "select_trap_r", UINT32_C(0)), std::exception);
51 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(0))->to_ui32() == UINT32_C(1));
52 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(1))->to_ui32() == UINT32_C(0));
53 CHECK(bkend.call_with_return("env", "as-select-mid", UINT32_C(0))->to_ui32() == UINT32_C(2));
54 CHECK(bkend.call_with_return("env", "as-select-mid", UINT32_C(1))->to_ui32() == UINT32_C(2));
55 CHECK(bkend.call_with_return("env", "as-select-last", UINT32_C(0))->to_ui32() == UINT32_C(2));
56 CHECK(bkend.call_with_return("env", "as-select-last", UINT32_C(1))->to_ui32() == UINT32_C(3));
57 CHECK(bkend.call_with_return("env", "as-loop-first", UINT32_C(0))->to_ui32() == UINT32_C(3));
58 CHECK(bkend.call_with_return("env", "as-loop-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
59 CHECK(bkend.call_with_return("env", "as-loop-mid", UINT32_C(0))->to_ui32() == UINT32_C(3));
60 CHECK(bkend.call_with_return("env", "as-loop-mid", UINT32_C(1))->to_ui32() == UINT32_C(2));
61 CHECK(bkend.call_with_return("env", "as-loop-last", UINT32_C(0))->to_ui32() == UINT32_C(3));
62 CHECK(bkend.call_with_return("env", "as-loop-last", UINT32_C(1))->to_ui32() == UINT32_C(2));
63 CHECK(!bkend.call_with_return("env", "as-if-condition", UINT32_C(0)));
64 CHECK(!bkend.call_with_return("env", "as-if-condition", UINT32_C(1)));
65 CHECK(bkend.call_with_return("env", "as-if-then", UINT32_C(0))->to_ui32() == UINT32_C(3));
66 CHECK(bkend.call_with_return("env", "as-if-then", UINT32_C(1))->to_ui32() == UINT32_C(2));
67 CHECK(bkend.call_with_return("env", "as-if-else", UINT32_C(0))->to_ui32() == UINT32_C(3));
68 CHECK(bkend.call_with_return("env", "as-if-else", UINT32_C(1))->to_ui32() == UINT32_C(2));
69 CHECK(bkend.call_with_return("env", "as-br_if-first", UINT32_C(0))->to_ui32() == UINT32_C(3));
70 CHECK(bkend.call_with_return("env", "as-br_if-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
71 CHECK(bkend.call_with_return("env", "as-br_if-last", UINT32_C(0))->to_ui32() == UINT32_C(2));
72 CHECK(bkend.call_with_return("env", "as-br_if-last", UINT32_C(1))->to_ui32() == UINT32_C(2));
73 CHECK(bkend.call_with_return("env", "as-br_table-first", UINT32_C(0))->to_ui32() == UINT32_C(3));
74 CHECK(bkend.call_with_return("env", "as-br_table-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
75 CHECK(bkend.call_with_return("env", "as-br_table-last", UINT32_C(0))->to_ui32() == UINT32_C(2));
76 CHECK(bkend.call_with_return("env", "as-br_table-last", UINT32_C(1))->to_ui32() == UINT32_C(2));
77 CHECK(bkend.call_with_return("env", "as-call_indirect-first", UINT32_C(0))->to_ui32() == UINT32_C(3));
78 CHECK(bkend.call_with_return("env", "as-call_indirect-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
79 CHECK(bkend.call_with_return("env", "as-call_indirect-mid", UINT32_C(0))->to_ui32() == UINT32_C(1));
80 CHECK(bkend.call_with_return("env", "as-call_indirect-mid", UINT32_C(1))->to_ui32() == UINT32_C(1));
81 CHECK_THROWS_AS(bkend("env", "as-call_indirect-last", UINT32_C(0)), std::exception);
82 CHECK_THROWS_AS(bkend("env", "as-call_indirect-last", UINT32_C(1)), std::exception);
83 CHECK(!bkend.call_with_return("env", "as-store-first", UINT32_C(0)));
84 CHECK(!bkend.call_with_return("env", "as-store-first", UINT32_C(1)));
85 CHECK(!bkend.call_with_return("env", "as-store-last", UINT32_C(0)));
86 CHECK(!bkend.call_with_return("env", "as-store-last", UINT32_C(1)));
87 CHECK(bkend.call_with_return("env", "as-memory.grow-value", UINT32_C(0))->to_ui32() == UINT32_C(1));
88 CHECK(bkend.call_with_return("env", "as-memory.grow-value", UINT32_C(1))->to_ui32() == UINT32_C(3));
89 CHECK(bkend.call_with_return("env", "as-call-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
90 CHECK(bkend.call_with_return("env", "as-call-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
91 CHECK(bkend.call_with_return("env", "as-return-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
92 CHECK(bkend.call_with_return("env", "as-return-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
93 CHECK(!bkend.call_with_return("env", "as-drop-operand", UINT32_C(0)));
94 CHECK(!bkend.call_with_return("env", "as-drop-operand", UINT32_C(1)));
95 CHECK(bkend.call_with_return("env", "as-br-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
96 CHECK(bkend.call_with_return("env", "as-br-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
97 CHECK(bkend.call_with_return("env", "as-local.set-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
98 CHECK(bkend.call_with_return("env", "as-local.set-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
99 CHECK(bkend.call_with_return("env", "as-local.tee-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
100 CHECK(bkend.call_with_return("env", "as-local.tee-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
101 CHECK(bkend.call_with_return("env", "as-global.set-value", UINT32_C(0))->to_ui32() == UINT32_C(2));
102 CHECK(bkend.call_with_return("env", "as-global.set-value", UINT32_C(1))->to_ui32() == UINT32_C(1));
103 CHECK(bkend.call_with_return("env", "as-load-operand", UINT32_C(0))->to_ui32() == UINT32_C(1));
104 CHECK(bkend.call_with_return("env", "as-load-operand", UINT32_C(1))->to_ui32() == UINT32_C(1));
105 CHECK(bkend.call_with_return("env", "as-unary-operand", UINT32_C(0))->to_ui32() == UINT32_C(0));
106 CHECK(bkend.call_with_return("env", "as-unary-operand", UINT32_C(1))->to_ui32() == UINT32_C(1));
107 CHECK(bkend.call_with_return("env", "as-binary-operand", UINT32_C(0))->to_ui32() == UINT32_C(4));
108 CHECK(bkend.call_with_return("env", "as-binary-operand", UINT32_C(1))->to_ui32() == UINT32_C(1));
109 CHECK(bkend.call_with_return("env", "as-test-operand", UINT32_C(0))->to_ui32() == UINT32_C(0));
110 CHECK(bkend.call_with_return("env", "as-test-operand", UINT32_C(1))->to_ui32() == UINT32_C(1));
111 CHECK(bkend.call_with_return("env", "as-compare-left", UINT32_C(0))->to_ui32() == UINT32_C(0));
112 CHECK(bkend.call_with_return("env", "as-compare-left", UINT32_C(1))->to_ui32() == UINT32_C(1));
113 CHECK(bkend.call_with_return("env", "as-compare-right", UINT32_C(0))->to_ui32() == UINT32_C(0));
114 CHECK(bkend.call_with_return("env", "as-compare-right", UINT32_C(1))->to_ui32() == UINT32_C(1));
115 CHECK(bkend.call_with_return("env", "as-convert-operand", UINT32_C(0))->to_ui32() == UINT32_C(0));
116 CHECK(bkend.call_with_return("env", "as-convert-operand", UINT32_C(1))->to_ui32() == UINT32_C(1));
117}
118
119BACKEND_TEST_CASE( "Testing wasm <select_1_wasm>", "[select_1_wasm_tests]" ) {
121 auto code = read_wasm( std::string(wasm_directory) + "select.1.wasm");
122 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
123}
124
125BACKEND_TEST_CASE( "Testing wasm <select_10_wasm>", "[select_10_wasm_tests]" ) {
127 auto code = read_wasm( std::string(wasm_directory) + "select.10.wasm");
128 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
129}
130
131BACKEND_TEST_CASE( "Testing wasm <select_11_wasm>", "[select_11_wasm_tests]" ) {
133 auto code = read_wasm( std::string(wasm_directory) + "select.11.wasm");
134 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
135}
136
137BACKEND_TEST_CASE( "Testing wasm <select_12_wasm>", "[select_12_wasm_tests]" ) {
139 auto code = read_wasm( std::string(wasm_directory) + "select.12.wasm");
140 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
141}
142
143BACKEND_TEST_CASE( "Testing wasm <select_13_wasm>", "[select_13_wasm_tests]" ) {
145 auto code = read_wasm( std::string(wasm_directory) + "select.13.wasm");
146 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
147}
148
149BACKEND_TEST_CASE( "Testing wasm <select_14_wasm>", "[select_14_wasm_tests]" ) {
151 auto code = read_wasm( std::string(wasm_directory) + "select.14.wasm");
152 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
153}
154
155BACKEND_TEST_CASE( "Testing wasm <select_15_wasm>", "[select_15_wasm_tests]" ) {
157 auto code = read_wasm( std::string(wasm_directory) + "select.15.wasm");
158 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
159}
160
161BACKEND_TEST_CASE( "Testing wasm <select_16_wasm>", "[select_16_wasm_tests]" ) {
163 auto code = read_wasm( std::string(wasm_directory) + "select.16.wasm");
164 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
165}
166
167BACKEND_TEST_CASE( "Testing wasm <select_2_wasm>", "[select_2_wasm_tests]" ) {
169 auto code = read_wasm( std::string(wasm_directory) + "select.2.wasm");
170 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
171}
172
173BACKEND_TEST_CASE( "Testing wasm <select_3_wasm>", "[select_3_wasm_tests]" ) {
175 auto code = read_wasm( std::string(wasm_directory) + "select.3.wasm");
176 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
177}
178
179BACKEND_TEST_CASE( "Testing wasm <select_4_wasm>", "[select_4_wasm_tests]" ) {
181 auto code = read_wasm( std::string(wasm_directory) + "select.4.wasm");
182 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
183}
184
185BACKEND_TEST_CASE( "Testing wasm <select_5_wasm>", "[select_5_wasm_tests]" ) {
187 auto code = read_wasm( std::string(wasm_directory) + "select.5.wasm");
188 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
189}
190
191BACKEND_TEST_CASE( "Testing wasm <select_6_wasm>", "[select_6_wasm_tests]" ) {
193 auto code = read_wasm( std::string(wasm_directory) + "select.6.wasm");
194 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
195}
196
197BACKEND_TEST_CASE( "Testing wasm <select_7_wasm>", "[select_7_wasm_tests]" ) {
199 auto code = read_wasm( std::string(wasm_directory) + "select.7.wasm");
200 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
201}
202
203BACKEND_TEST_CASE( "Testing wasm <select_8_wasm>", "[select_8_wasm_tests]" ) {
205 auto code = read_wasm( std::string(wasm_directory) + "select.8.wasm");
206 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
207}
208
209BACKEND_TEST_CASE( "Testing wasm <select_9_wasm>", "[select_9_wasm_tests]" ) {
211 auto code = read_wasm( std::string(wasm_directory) + "select.9.wasm");
212 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
213}
214
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
wasm_allocator wa
Definition main.cpp:10
#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