Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
int_exprs_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 <int_exprs_0_wasm>", "[int_exprs_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "i32.no_fold_cmp_s_offset", UINT32_C(2147483647), UINT32_C(0))->to_ui32() == UINT32_C(1));
24 CHECK(bkend.call_with_return("env", "i32.no_fold_cmp_u_offset", UINT32_C(4294967295), UINT32_C(0))->to_ui32() == UINT32_C(1));
25 CHECK(bkend.call_with_return("env", "i64.no_fold_cmp_s_offset", UINT64_C(9223372036854775807), UINT64_C(0))->to_ui32() == UINT32_C(1));
26 CHECK(bkend.call_with_return("env", "i64.no_fold_cmp_u_offset", UINT64_C(18446744073709551615), UINT64_C(0))->to_ui32() == UINT32_C(1));
27}
28
29BACKEND_TEST_CASE( "Testing wasm <int_exprs_1_wasm>", "[int_exprs_1_wasm_tests]" ) {
31 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.1.wasm");
32 backend_t bkend( code, &wa );
33
34 CHECK(bkend.call_with_return("env", "i64.no_fold_wrap_extend_s", UINT64_C(4538991236898928))->to_ui64() == UINT32_C(1079009392));
35 CHECK(bkend.call_with_return("env", "i64.no_fold_wrap_extend_s", UINT64_C(45230338458316960))->to_ui64() == UINT32_C(18446744072918986912));
36}
37
38BACKEND_TEST_CASE( "Testing wasm <int_exprs_10_wasm>", "[int_exprs_10_wasm_tests]" ) {
40 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.10.wasm");
41 backend_t bkend( code, &wa );
42
43 CHECK(bkend.call_with_return("env", "i32.no_fold_rem_s_2", UINT32_C(4294967285))->to_ui32() == UINT32_C(4294967295));
44 CHECK(bkend.call_with_return("env", "i64.no_fold_rem_s_2", UINT64_C(18446744073709551605))->to_ui64() == UINT32_C(18446744073709551615));
45}
46
47BACKEND_TEST_CASE( "Testing wasm <int_exprs_11_wasm>", "[int_exprs_11_wasm_tests]" ) {
49 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.11.wasm");
50 backend_t bkend( code, &wa );
51
52 CHECK_THROWS_AS(bkend("env", "i32.div_s_0", UINT32_C(71)), std::exception);
53 CHECK_THROWS_AS(bkend("env", "i32.div_u_0", UINT32_C(71)), std::exception);
54 CHECK_THROWS_AS(bkend("env", "i64.div_s_0", UINT64_C(71)), std::exception);
55 CHECK_THROWS_AS(bkend("env", "i64.div_u_0", UINT64_C(71)), std::exception);
56}
57
58BACKEND_TEST_CASE( "Testing wasm <int_exprs_12_wasm>", "[int_exprs_12_wasm_tests]" ) {
60 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.12.wasm");
61 backend_t bkend( code, &wa );
62
63 CHECK(bkend.call_with_return("env", "i32.div_s_3", UINT32_C(71))->to_ui32() == UINT32_C(23));
64 CHECK(bkend.call_with_return("env", "i32.div_s_3", UINT32_C(1610612736))->to_ui32() == UINT32_C(536870912));
65 CHECK(bkend.call_with_return("env", "i32.div_u_3", UINT32_C(71))->to_ui32() == UINT32_C(23));
66 CHECK(bkend.call_with_return("env", "i32.div_u_3", UINT32_C(3221225472))->to_ui32() == UINT32_C(1073741824));
67 CHECK(bkend.call_with_return("env", "i64.div_s_3", UINT64_C(71))->to_ui64() == UINT32_C(23));
68 CHECK(bkend.call_with_return("env", "i64.div_s_3", UINT64_C(3458764513820540928))->to_ui64() == UINT32_C(1152921504606846976));
69 CHECK(bkend.call_with_return("env", "i64.div_u_3", UINT64_C(71))->to_ui64() == UINT32_C(23));
70 CHECK(bkend.call_with_return("env", "i64.div_u_3", UINT64_C(13835058055282163712))->to_ui64() == UINT32_C(4611686018427387904));
71}
72
73BACKEND_TEST_CASE( "Testing wasm <int_exprs_13_wasm>", "[int_exprs_13_wasm_tests]" ) {
75 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.13.wasm");
76 backend_t bkend( code, &wa );
77
78 CHECK(bkend.call_with_return("env", "i32.div_s_5", UINT32_C(71))->to_ui32() == UINT32_C(14));
79 CHECK(bkend.call_with_return("env", "i32.div_s_5", UINT32_C(1342177280))->to_ui32() == UINT32_C(268435456));
80 CHECK(bkend.call_with_return("env", "i32.div_u_5", UINT32_C(71))->to_ui32() == UINT32_C(14));
81 CHECK(bkend.call_with_return("env", "i32.div_u_5", UINT32_C(2684354560))->to_ui32() == UINT32_C(536870912));
82 CHECK(bkend.call_with_return("env", "i64.div_s_5", UINT64_C(71))->to_ui64() == UINT32_C(14));
83 CHECK(bkend.call_with_return("env", "i64.div_s_5", UINT64_C(5764607523034234880))->to_ui64() == UINT32_C(1152921504606846976));
84 CHECK(bkend.call_with_return("env", "i64.div_u_5", UINT64_C(71))->to_ui64() == UINT32_C(14));
85 CHECK(bkend.call_with_return("env", "i64.div_u_5", UINT64_C(11529215046068469760))->to_ui64() == UINT32_C(2305843009213693952));
86}
87
88BACKEND_TEST_CASE( "Testing wasm <int_exprs_14_wasm>", "[int_exprs_14_wasm_tests]" ) {
90 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.14.wasm");
91 backend_t bkend( code, &wa );
92
93 CHECK(bkend.call_with_return("env", "i32.div_s_7", UINT32_C(71))->to_ui32() == UINT32_C(10));
94 CHECK(bkend.call_with_return("env", "i32.div_s_7", UINT32_C(1879048192))->to_ui32() == UINT32_C(268435456));
95 CHECK(bkend.call_with_return("env", "i32.div_u_7", UINT32_C(71))->to_ui32() == UINT32_C(10));
96 CHECK(bkend.call_with_return("env", "i32.div_u_7", UINT32_C(3758096384))->to_ui32() == UINT32_C(536870912));
97 CHECK(bkend.call_with_return("env", "i64.div_s_7", UINT64_C(71))->to_ui64() == UINT32_C(10));
98 CHECK(bkend.call_with_return("env", "i64.div_s_7", UINT64_C(8070450532247928832))->to_ui64() == UINT32_C(1152921504606846976));
99 CHECK(bkend.call_with_return("env", "i64.div_u_7", UINT64_C(71))->to_ui64() == UINT32_C(10));
100 CHECK(bkend.call_with_return("env", "i64.div_u_7", UINT64_C(16140901064495857664))->to_ui64() == UINT32_C(2305843009213693952));
101}
102
103BACKEND_TEST_CASE( "Testing wasm <int_exprs_15_wasm>", "[int_exprs_15_wasm_tests]" ) {
105 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.15.wasm");
106 backend_t bkend( code, &wa );
107
108 CHECK(bkend.call_with_return("env", "i32.rem_s_3", UINT32_C(71))->to_ui32() == UINT32_C(2));
109 CHECK(bkend.call_with_return("env", "i32.rem_s_3", UINT32_C(1610612736))->to_ui32() == UINT32_C(0));
110 CHECK(bkend.call_with_return("env", "i32.rem_u_3", UINT32_C(71))->to_ui32() == UINT32_C(2));
111 CHECK(bkend.call_with_return("env", "i32.rem_u_3", UINT32_C(3221225472))->to_ui32() == UINT32_C(0));
112 CHECK(bkend.call_with_return("env", "i64.rem_s_3", UINT64_C(71))->to_ui64() == UINT32_C(2));
113 CHECK(bkend.call_with_return("env", "i64.rem_s_3", UINT64_C(3458764513820540928))->to_ui64() == UINT32_C(0));
114 CHECK(bkend.call_with_return("env", "i64.rem_u_3", UINT64_C(71))->to_ui64() == UINT32_C(2));
115 CHECK(bkend.call_with_return("env", "i64.rem_u_3", UINT64_C(13835058055282163712))->to_ui64() == UINT32_C(0));
116}
117
118BACKEND_TEST_CASE( "Testing wasm <int_exprs_16_wasm>", "[int_exprs_16_wasm_tests]" ) {
120 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.16.wasm");
121 backend_t bkend( code, &wa );
122
123 CHECK(bkend.call_with_return("env", "i32.rem_s_5", UINT32_C(71))->to_ui32() == UINT32_C(1));
124 CHECK(bkend.call_with_return("env", "i32.rem_s_5", UINT32_C(1342177280))->to_ui32() == UINT32_C(0));
125 CHECK(bkend.call_with_return("env", "i32.rem_u_5", UINT32_C(71))->to_ui32() == UINT32_C(1));
126 CHECK(bkend.call_with_return("env", "i32.rem_u_5", UINT32_C(2684354560))->to_ui32() == UINT32_C(0));
127 CHECK(bkend.call_with_return("env", "i64.rem_s_5", UINT64_C(71))->to_ui64() == UINT32_C(1));
128 CHECK(bkend.call_with_return("env", "i64.rem_s_5", UINT64_C(5764607523034234880))->to_ui64() == UINT32_C(0));
129 CHECK(bkend.call_with_return("env", "i64.rem_u_5", UINT64_C(71))->to_ui64() == UINT32_C(1));
130 CHECK(bkend.call_with_return("env", "i64.rem_u_5", UINT64_C(11529215046068469760))->to_ui64() == UINT32_C(0));
131}
132
133BACKEND_TEST_CASE( "Testing wasm <int_exprs_17_wasm>", "[int_exprs_17_wasm_tests]" ) {
135 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.17.wasm");
136 backend_t bkend( code, &wa );
137
138 CHECK(bkend.call_with_return("env", "i32.rem_s_7", UINT32_C(71))->to_ui32() == UINT32_C(1));
139 CHECK(bkend.call_with_return("env", "i32.rem_s_7", UINT32_C(1879048192))->to_ui32() == UINT32_C(0));
140 CHECK(bkend.call_with_return("env", "i32.rem_u_7", UINT32_C(71))->to_ui32() == UINT32_C(1));
141 CHECK(bkend.call_with_return("env", "i32.rem_u_7", UINT32_C(3758096384))->to_ui32() == UINT32_C(0));
142 CHECK(bkend.call_with_return("env", "i64.rem_s_7", UINT64_C(71))->to_ui64() == UINT32_C(1));
143 CHECK(bkend.call_with_return("env", "i64.rem_s_7", UINT64_C(8070450532247928832))->to_ui64() == UINT32_C(0));
144 CHECK(bkend.call_with_return("env", "i64.rem_u_7", UINT64_C(71))->to_ui64() == UINT32_C(1));
145 CHECK(bkend.call_with_return("env", "i64.rem_u_7", UINT64_C(16140901064495857664))->to_ui64() == UINT32_C(0));
146}
147
148BACKEND_TEST_CASE( "Testing wasm <int_exprs_18_wasm>", "[int_exprs_18_wasm_tests]" ) {
150 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.18.wasm");
151 backend_t bkend( code, &wa );
152
153 CHECK_THROWS_AS(bkend("env", "i32.no_fold_div_neg1", UINT32_C(2147483648)), std::exception);
154 CHECK_THROWS_AS(bkend("env", "i64.no_fold_div_neg1", UINT64_C(9223372036854775808)), std::exception);
155}
156
157BACKEND_TEST_CASE( "Testing wasm <int_exprs_2_wasm>", "[int_exprs_2_wasm_tests]" ) {
159 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.2.wasm");
160 backend_t bkend( code, &wa );
161
162 CHECK(bkend.call_with_return("env", "i64.no_fold_wrap_extend_u", UINT64_C(4538991236898928))->to_ui64() == UINT32_C(1079009392));
163}
164
165BACKEND_TEST_CASE( "Testing wasm <int_exprs_3_wasm>", "[int_exprs_3_wasm_tests]" ) {
167 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.3.wasm");
168 backend_t bkend( code, &wa );
169
170 CHECK(bkend.call_with_return("env", "i32.no_fold_shl_shr_s", UINT32_C(2147483648))->to_ui32() == UINT32_C(0));
171 CHECK(bkend.call_with_return("env", "i32.no_fold_shl_shr_u", UINT32_C(2147483648))->to_ui32() == UINT32_C(0));
172 CHECK(bkend.call_with_return("env", "i64.no_fold_shl_shr_s", UINT64_C(9223372036854775808))->to_ui64() == UINT32_C(0));
173 CHECK(bkend.call_with_return("env", "i64.no_fold_shl_shr_u", UINT64_C(9223372036854775808))->to_ui64() == UINT32_C(0));
174}
175
176BACKEND_TEST_CASE( "Testing wasm <int_exprs_4_wasm>", "[int_exprs_4_wasm_tests]" ) {
178 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.4.wasm");
179 backend_t bkend( code, &wa );
180
181 CHECK(bkend.call_with_return("env", "i32.no_fold_shr_s_shl", UINT32_C(1))->to_ui32() == UINT32_C(0));
182 CHECK(bkend.call_with_return("env", "i32.no_fold_shr_u_shl", UINT32_C(1))->to_ui32() == UINT32_C(0));
183 CHECK(bkend.call_with_return("env", "i64.no_fold_shr_s_shl", UINT64_C(1))->to_ui64() == UINT32_C(0));
184 CHECK(bkend.call_with_return("env", "i64.no_fold_shr_u_shl", UINT64_C(1))->to_ui64() == UINT32_C(0));
185}
186
187BACKEND_TEST_CASE( "Testing wasm <int_exprs_5_wasm>", "[int_exprs_5_wasm_tests]" ) {
189 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.5.wasm");
190 backend_t bkend( code, &wa );
191
192 CHECK(bkend.call_with_return("env", "i32.no_fold_div_s_mul", UINT32_C(1))->to_ui32() == UINT32_C(0));
193 CHECK(bkend.call_with_return("env", "i32.no_fold_div_u_mul", UINT32_C(1))->to_ui32() == UINT32_C(0));
194 CHECK(bkend.call_with_return("env", "i64.no_fold_div_s_mul", UINT64_C(1))->to_ui64() == UINT32_C(0));
195 CHECK(bkend.call_with_return("env", "i64.no_fold_div_u_mul", UINT64_C(1))->to_ui64() == UINT32_C(0));
196}
197
198BACKEND_TEST_CASE( "Testing wasm <int_exprs_6_wasm>", "[int_exprs_6_wasm_tests]" ) {
200 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.6.wasm");
201 backend_t bkend( code, &wa );
202
203 CHECK_THROWS_AS(bkend("env", "i32.no_fold_div_s_self", UINT32_C(0)), std::exception);
204 CHECK_THROWS_AS(bkend("env", "i32.no_fold_div_u_self", UINT32_C(0)), std::exception);
205 CHECK_THROWS_AS(bkend("env", "i64.no_fold_div_s_self", UINT64_C(0)), std::exception);
206 CHECK_THROWS_AS(bkend("env", "i64.no_fold_div_u_self", UINT64_C(0)), std::exception);
207}
208
209BACKEND_TEST_CASE( "Testing wasm <int_exprs_7_wasm>", "[int_exprs_7_wasm_tests]" ) {
211 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.7.wasm");
212 backend_t bkend( code, &wa );
213
214 CHECK_THROWS_AS(bkend("env", "i32.no_fold_rem_s_self", UINT32_C(0)), std::exception);
215 CHECK_THROWS_AS(bkend("env", "i32.no_fold_rem_u_self", UINT32_C(0)), std::exception);
216 CHECK_THROWS_AS(bkend("env", "i64.no_fold_rem_s_self", UINT64_C(0)), std::exception);
217 CHECK_THROWS_AS(bkend("env", "i64.no_fold_rem_u_self", UINT64_C(0)), std::exception);
218}
219
220BACKEND_TEST_CASE( "Testing wasm <int_exprs_8_wasm>", "[int_exprs_8_wasm_tests]" ) {
222 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.8.wasm");
223 backend_t bkend( code, &wa );
224
225 CHECK(bkend.call_with_return("env", "i32.no_fold_mul_div_s", UINT32_C(2147483648))->to_ui32() == UINT32_C(0));
226 CHECK(bkend.call_with_return("env", "i32.no_fold_mul_div_u", UINT32_C(2147483648))->to_ui32() == UINT32_C(0));
227 CHECK(bkend.call_with_return("env", "i64.no_fold_mul_div_s", UINT64_C(9223372036854775808))->to_ui64() == UINT32_C(0));
228 CHECK(bkend.call_with_return("env", "i64.no_fold_mul_div_u", UINT64_C(9223372036854775808))->to_ui64() == UINT32_C(0));
229}
230
231BACKEND_TEST_CASE( "Testing wasm <int_exprs_9_wasm>", "[int_exprs_9_wasm_tests]" ) {
233 auto code = read_wasm( std::string(wasm_directory) + "int_exprs.9.wasm");
234 backend_t bkend( code, &wa );
235
236 CHECK(bkend.call_with_return("env", "i32.no_fold_div_s_2", UINT32_C(4294967285))->to_ui32() == UINT32_C(4294967291));
237 CHECK(bkend.call_with_return("env", "i64.no_fold_div_s_2", UINT64_C(18446744073709551605))->to_ui64() == UINT32_C(18446744073709551611));
238}
239
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)
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
wasm_allocator wa
Definition main.cpp:10
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