Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory_trap_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 <memory_trap_0_wasm>", "[memory_trap_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "memory_trap.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(!bkend.call_with_return("env", "store", UINT32_C(4294967292), UINT32_C(42)));
24 CHECK(bkend.call_with_return("env", "load", UINT32_C(4294967292))->to_ui32() == UINT32_C(42));
25 CHECK_THROWS_AS(bkend("env", "store", UINT32_C(4294967293), UINT32_C(13)), std::exception);
26 CHECK_THROWS_AS(bkend("env", "load", UINT32_C(4294967293)), std::exception);
27 CHECK_THROWS_AS(bkend("env", "store", UINT32_C(4294967294), UINT32_C(13)), std::exception);
28 CHECK_THROWS_AS(bkend("env", "load", UINT32_C(4294967294)), std::exception);
29 CHECK_THROWS_AS(bkend("env", "store", UINT32_C(4294967295), UINT32_C(13)), std::exception);
30 CHECK_THROWS_AS(bkend("env", "load", UINT32_C(4294967295)), std::exception);
31 CHECK_THROWS_AS(bkend("env", "store", UINT32_C(0), UINT32_C(13)), std::exception);
32 CHECK_THROWS_AS(bkend("env", "load", UINT32_C(0)), std::exception);
33 CHECK_THROWS_AS(bkend("env", "store", UINT32_C(2147483648), UINT32_C(13)), std::exception);
34 CHECK_THROWS_AS(bkend("env", "load", UINT32_C(2147483648)), std::exception);
35 CHECK(bkend.call_with_return("env", "memory.grow", UINT32_C(65537))->to_ui32() == UINT32_C(4294967295));
36}
37
38BACKEND_TEST_CASE( "Testing wasm <memory_trap_1_wasm>", "[memory_trap_1_wasm_tests]" ) {
40 auto code = read_wasm( std::string(wasm_directory) + "memory_trap.1.wasm");
41 backend_t bkend( code, &wa );
42
43 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(65536), UINT32_C(0)), std::exception);
44 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(65535), UINT32_C(0)), std::exception);
45 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(65534), UINT32_C(0)), std::exception);
46 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(65533), UINT32_C(0)), std::exception);
47 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(4294967295), UINT32_C(0)), std::exception);
48 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(4294967294), UINT32_C(0)), std::exception);
49 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(4294967293), UINT32_C(0)), std::exception);
50 CHECK_THROWS_AS(bkend("env", "i32.store", UINT32_C(4294967292), UINT32_C(0)), std::exception);
51 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65536), UINT64_C(0)), std::exception);
52 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65535), UINT64_C(0)), std::exception);
53 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65534), UINT64_C(0)), std::exception);
54 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65533), UINT64_C(0)), std::exception);
55 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65532), UINT64_C(0)), std::exception);
56 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65531), UINT64_C(0)), std::exception);
57 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65530), UINT64_C(0)), std::exception);
58 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(65529), UINT64_C(0)), std::exception);
59 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967295), UINT64_C(0)), std::exception);
60 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967294), UINT64_C(0)), std::exception);
61 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967293), UINT64_C(0)), std::exception);
62 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967292), UINT64_C(0)), std::exception);
63 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967291), UINT64_C(0)), std::exception);
64 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967290), UINT64_C(0)), std::exception);
65 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967289), UINT64_C(0)), std::exception);
66 CHECK_THROWS_AS(bkend("env", "i64.store", UINT32_C(4294967288), UINT64_C(0)), std::exception);
67 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(65536), bit_cast<float>(UINT32_C(0))), std::exception);
68 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(65535), bit_cast<float>(UINT32_C(0))), std::exception);
69 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(65534), bit_cast<float>(UINT32_C(0))), std::exception);
70 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(65533), bit_cast<float>(UINT32_C(0))), std::exception);
71 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(4294967295), bit_cast<float>(UINT32_C(0))), std::exception);
72 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(4294967294), bit_cast<float>(UINT32_C(0))), std::exception);
73 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(4294967293), bit_cast<float>(UINT32_C(0))), std::exception);
74 CHECK_THROWS_AS(bkend("env", "f32.store", UINT32_C(4294967292), bit_cast<float>(UINT32_C(0))), std::exception);
75 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65536), bit_cast<double>(UINT64_C(0))), std::exception);
76 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65535), bit_cast<double>(UINT64_C(0))), std::exception);
77 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65534), bit_cast<double>(UINT64_C(0))), std::exception);
78 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65533), bit_cast<double>(UINT64_C(0))), std::exception);
79 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65532), bit_cast<double>(UINT64_C(0))), std::exception);
80 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65531), bit_cast<double>(UINT64_C(0))), std::exception);
81 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65530), bit_cast<double>(UINT64_C(0))), std::exception);
82 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(65529), bit_cast<double>(UINT64_C(0))), std::exception);
83 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967295), bit_cast<double>(UINT64_C(0))), std::exception);
84 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967294), bit_cast<double>(UINT64_C(0))), std::exception);
85 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967293), bit_cast<double>(UINT64_C(0))), std::exception);
86 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967292), bit_cast<double>(UINT64_C(0))), std::exception);
87 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967291), bit_cast<double>(UINT64_C(0))), std::exception);
88 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967290), bit_cast<double>(UINT64_C(0))), std::exception);
89 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967289), bit_cast<double>(UINT64_C(0))), std::exception);
90 CHECK_THROWS_AS(bkend("env", "f64.store", UINT32_C(4294967288), bit_cast<double>(UINT64_C(0))), std::exception);
91 CHECK_THROWS_AS(bkend("env", "i32.store8", UINT32_C(65536), UINT32_C(0)), std::exception);
92 CHECK_THROWS_AS(bkend("env", "i32.store8", UINT32_C(4294967295), UINT32_C(0)), std::exception);
93 CHECK_THROWS_AS(bkend("env", "i32.store16", UINT32_C(65536), UINT32_C(0)), std::exception);
94 CHECK_THROWS_AS(bkend("env", "i32.store16", UINT32_C(65535), UINT32_C(0)), std::exception);
95 CHECK_THROWS_AS(bkend("env", "i32.store16", UINT32_C(4294967295), UINT32_C(0)), std::exception);
96 CHECK_THROWS_AS(bkend("env", "i32.store16", UINT32_C(4294967294), UINT32_C(0)), std::exception);
97 CHECK_THROWS_AS(bkend("env", "i64.store8", UINT32_C(65536), UINT64_C(0)), std::exception);
98 CHECK_THROWS_AS(bkend("env", "i64.store8", UINT32_C(4294967295), UINT64_C(0)), std::exception);
99 CHECK_THROWS_AS(bkend("env", "i64.store16", UINT32_C(65536), UINT64_C(0)), std::exception);
100 CHECK_THROWS_AS(bkend("env", "i64.store16", UINT32_C(65535), UINT64_C(0)), std::exception);
101 CHECK_THROWS_AS(bkend("env", "i64.store16", UINT32_C(4294967295), UINT64_C(0)), std::exception);
102 CHECK_THROWS_AS(bkend("env", "i64.store16", UINT32_C(4294967294), UINT64_C(0)), std::exception);
103 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(65536), UINT64_C(0)), std::exception);
104 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(65535), UINT64_C(0)), std::exception);
105 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(65534), UINT64_C(0)), std::exception);
106 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(65533), UINT64_C(0)), std::exception);
107 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(4294967295), UINT64_C(0)), std::exception);
108 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(4294967294), UINT64_C(0)), std::exception);
109 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(4294967293), UINT64_C(0)), std::exception);
110 CHECK_THROWS_AS(bkend("env", "i64.store32", UINT32_C(4294967292), UINT64_C(0)), std::exception);
111 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(65536)), std::exception);
112 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(65535)), std::exception);
113 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(65534)), std::exception);
114 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(65533)), std::exception);
115 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(4294967295)), std::exception);
116 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(4294967294)), std::exception);
117 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(4294967293)), std::exception);
118 CHECK_THROWS_AS(bkend("env", "i32.load", UINT32_C(4294967292)), std::exception);
119 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65536)), std::exception);
120 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65535)), std::exception);
121 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65534)), std::exception);
122 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65533)), std::exception);
123 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65532)), std::exception);
124 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65531)), std::exception);
125 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65530)), std::exception);
126 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(65529)), std::exception);
127 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967295)), std::exception);
128 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967294)), std::exception);
129 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967293)), std::exception);
130 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967292)), std::exception);
131 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967291)), std::exception);
132 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967290)), std::exception);
133 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967289)), std::exception);
134 CHECK_THROWS_AS(bkend("env", "i64.load", UINT32_C(4294967288)), std::exception);
135 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(65536)), std::exception);
136 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(65535)), std::exception);
137 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(65534)), std::exception);
138 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(65533)), std::exception);
139 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(4294967295)), std::exception);
140 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(4294967294)), std::exception);
141 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(4294967293)), std::exception);
142 CHECK_THROWS_AS(bkend("env", "f32.load", UINT32_C(4294967292)), std::exception);
143 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65536)), std::exception);
144 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65535)), std::exception);
145 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65534)), std::exception);
146 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65533)), std::exception);
147 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65532)), std::exception);
148 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65531)), std::exception);
149 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65530)), std::exception);
150 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(65529)), std::exception);
151 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967295)), std::exception);
152 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967294)), std::exception);
153 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967293)), std::exception);
154 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967292)), std::exception);
155 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967291)), std::exception);
156 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967290)), std::exception);
157 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967289)), std::exception);
158 CHECK_THROWS_AS(bkend("env", "f64.load", UINT32_C(4294967288)), std::exception);
159 CHECK_THROWS_AS(bkend("env", "i32.load8_s", UINT32_C(65536)), std::exception);
160 CHECK_THROWS_AS(bkend("env", "i32.load8_s", UINT32_C(4294967295)), std::exception);
161 CHECK_THROWS_AS(bkend("env", "i32.load8_u", UINT32_C(65536)), std::exception);
162 CHECK_THROWS_AS(bkend("env", "i32.load8_u", UINT32_C(4294967295)), std::exception);
163 CHECK_THROWS_AS(bkend("env", "i32.load16_s", UINT32_C(65536)), std::exception);
164 CHECK_THROWS_AS(bkend("env", "i32.load16_s", UINT32_C(65535)), std::exception);
165 CHECK_THROWS_AS(bkend("env", "i32.load16_s", UINT32_C(4294967295)), std::exception);
166 CHECK_THROWS_AS(bkend("env", "i32.load16_s", UINT32_C(4294967294)), std::exception);
167 CHECK_THROWS_AS(bkend("env", "i32.load16_u", UINT32_C(65536)), std::exception);
168 CHECK_THROWS_AS(bkend("env", "i32.load16_u", UINT32_C(65535)), std::exception);
169 CHECK_THROWS_AS(bkend("env", "i32.load16_u", UINT32_C(4294967295)), std::exception);
170 CHECK_THROWS_AS(bkend("env", "i32.load16_u", UINT32_C(4294967294)), std::exception);
171 CHECK_THROWS_AS(bkend("env", "i64.load8_s", UINT32_C(65536)), std::exception);
172 CHECK_THROWS_AS(bkend("env", "i64.load8_s", UINT32_C(4294967295)), std::exception);
173 CHECK_THROWS_AS(bkend("env", "i64.load8_u", UINT32_C(65536)), std::exception);
174 CHECK_THROWS_AS(bkend("env", "i64.load8_u", UINT32_C(4294967295)), std::exception);
175 CHECK_THROWS_AS(bkend("env", "i64.load16_s", UINT32_C(65536)), std::exception);
176 CHECK_THROWS_AS(bkend("env", "i64.load16_s", UINT32_C(65535)), std::exception);
177 CHECK_THROWS_AS(bkend("env", "i64.load16_s", UINT32_C(4294967295)), std::exception);
178 CHECK_THROWS_AS(bkend("env", "i64.load16_s", UINT32_C(4294967294)), std::exception);
179 CHECK_THROWS_AS(bkend("env", "i64.load16_u", UINT32_C(65536)), std::exception);
180 CHECK_THROWS_AS(bkend("env", "i64.load16_u", UINT32_C(65535)), std::exception);
181 CHECK_THROWS_AS(bkend("env", "i64.load16_u", UINT32_C(4294967295)), std::exception);
182 CHECK_THROWS_AS(bkend("env", "i64.load16_u", UINT32_C(4294967294)), std::exception);
183 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(65536)), std::exception);
184 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(65535)), std::exception);
185 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(65534)), std::exception);
186 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(65533)), std::exception);
187 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(4294967295)), std::exception);
188 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(4294967294)), std::exception);
189 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(4294967293)), std::exception);
190 CHECK_THROWS_AS(bkend("env", "i64.load32_s", UINT32_C(4294967292)), std::exception);
191 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(65536)), std::exception);
192 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(65535)), std::exception);
193 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(65534)), std::exception);
194 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(65533)), std::exception);
195 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(4294967295)), std::exception);
196 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(4294967294)), std::exception);
197 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(4294967293)), std::exception);
198 CHECK_THROWS_AS(bkend("env", "i64.load32_u", UINT32_C(4294967292)), std::exception);
199 CHECK(bkend.call_with_return("env", "i64.load", UINT32_C(65528))->to_ui64() == UINT32_C(7523094288207667809));
200 CHECK(bkend.call_with_return("env", "i64.load", UINT32_C(0))->to_ui64() == UINT32_C(7523094288207667809));
201}
202
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
T bit_cast(const U &u)
Definition utils.hpp:35