Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory_tests.cpp File Reference
#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdlib>
#include <catch2/catch.hpp>
#include <utils.hpp>
#include <wasm_config.hpp>
#include <sysio/vm/backend.hpp>
Include dependency graph for memory_tests.cpp:

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <memory_0_wasm>", "[memory_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_1_wasm>", "[memory_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_10_wasm>", "[memory_10_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_11_wasm>", "[memory_11_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_12_wasm>", "[memory_12_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_13_wasm>", "[memory_13_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_14_wasm>", "[memory_14_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_15_wasm>", "[memory_15_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_16_wasm>", "[memory_16_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_17_wasm>", "[memory_17_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_18_wasm>", "[memory_18_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_19_wasm>", "[memory_19_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_2_wasm>", "[memory_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_20_wasm>", "[memory_20_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_21_wasm>", "[memory_21_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_22_wasm>", "[memory_22_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_23_wasm>", "[memory_23_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_24_wasm>", "[memory_24_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_25_wasm>", "[memory_25_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_3_wasm>", "[memory_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_4_wasm>", "[memory_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_5_wasm>", "[memory_5_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_6_wasm>", "[memory_6_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_7_wasm>", "[memory_7_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_8_wasm>", "[memory_8_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_9_wasm>", "[memory_9_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_0_wasm>" ,
"" [memory_0_wasm_tests] )

Definition at line 18 of file memory_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "memory.0.wasm");
21 backend_t bkend( code, &wa );
22
23}
backend_t bkend(hello_wasm, ehm, &wa)
wasm_allocator wa
Definition main.cpp:10
std::vector< uint8_t > read_wasm(const std::string &fname)
Definition utils.hpp:30
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_10_wasm>" ,
"" [memory_10_wasm_tests] )

Definition at line 32 of file memory_tests.cpp.

32 {
34 auto code = read_wasm( std::string(wasm_directory) + "memory.10.wasm");
35 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
36}
sysio::vm::backend< rhf_t > backend_t
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_11_wasm>" ,
"" [memory_11_wasm_tests] )

Definition at line 38 of file memory_tests.cpp.

38 {
40 auto code = read_wasm( std::string(wasm_directory) + "memory.11.wasm");
41 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
42}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_12_wasm>" ,
"" [memory_12_wasm_tests] )

Definition at line 44 of file memory_tests.cpp.

44 {
46 auto code = read_wasm( std::string(wasm_directory) + "memory.12.wasm");
47 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
48}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [5/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_13_wasm>" ,
"" [memory_13_wasm_tests] )

Definition at line 50 of file memory_tests.cpp.

50 {
52 auto code = read_wasm( std::string(wasm_directory) + "memory.13.wasm");
53 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
54}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [6/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_14_wasm>" ,
"" [memory_14_wasm_tests] )

Definition at line 56 of file memory_tests.cpp.

56 {
58 auto code = read_wasm( std::string(wasm_directory) + "memory.14.wasm");
59 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
60}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [7/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_15_wasm>" ,
"" [memory_15_wasm_tests] )

Definition at line 62 of file memory_tests.cpp.

62 {
64 auto code = read_wasm( std::string(wasm_directory) + "memory.15.wasm");
65 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
66}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [8/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_16_wasm>" ,
"" [memory_16_wasm_tests] )

Definition at line 68 of file memory_tests.cpp.

68 {
70 auto code = read_wasm( std::string(wasm_directory) + "memory.16.wasm");
71 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
72}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [9/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_17_wasm>" ,
"" [memory_17_wasm_tests] )

Definition at line 74 of file memory_tests.cpp.

74 {
76 auto code = read_wasm( std::string(wasm_directory) + "memory.17.wasm");
77 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
78}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [10/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_18_wasm>" ,
"" [memory_18_wasm_tests] )

Definition at line 80 of file memory_tests.cpp.

80 {
82 auto code = read_wasm( std::string(wasm_directory) + "memory.18.wasm");
83 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
84}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [11/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_19_wasm>" ,
"" [memory_19_wasm_tests] )

Definition at line 86 of file memory_tests.cpp.

86 {
88 auto code = read_wasm( std::string(wasm_directory) + "memory.19.wasm");
89 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
90}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [12/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_1_wasm>" ,
"" [memory_1_wasm_tests] )

Definition at line 25 of file memory_tests.cpp.

25 {
27 auto code = read_wasm( std::string(wasm_directory) + "memory.1.wasm");
28 backend_t bkend( code, &wa );
29
30}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [13/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_20_wasm>" ,
"" [memory_20_wasm_tests] )

Definition at line 99 of file memory_tests.cpp.

99 {
101 auto code = read_wasm( std::string(wasm_directory) + "memory.20.wasm");
102 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
103}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [14/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_21_wasm>" ,
"" [memory_21_wasm_tests] )

Definition at line 105 of file memory_tests.cpp.

105 {
107 auto code = read_wasm( std::string(wasm_directory) + "memory.21.wasm");
108 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
109}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [15/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_22_wasm>" ,
"" [memory_22_wasm_tests] )

Definition at line 111 of file memory_tests.cpp.

111 {
113 auto code = read_wasm( std::string(wasm_directory) + "memory.22.wasm");
114 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
115}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [16/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_23_wasm>" ,
"" [memory_23_wasm_tests] )

Definition at line 117 of file memory_tests.cpp.

117 {
119 auto code = read_wasm( std::string(wasm_directory) + "memory.23.wasm");
120 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
121}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [17/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_24_wasm>" ,
"" [memory_24_wasm_tests] )

Definition at line 123 of file memory_tests.cpp.

123 {
125 auto code = read_wasm( std::string(wasm_directory) + "memory.24.wasm");
126 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
127}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [18/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_25_wasm>" ,
"" [memory_25_wasm_tests] )

Definition at line 129 of file memory_tests.cpp.

129 {
131 auto code = read_wasm( std::string(wasm_directory) + "memory.25.wasm");
132 backend_t bkend( code, &wa );
133
134 CHECK(bkend.call_with_return("env", "data")->to_ui32() == UINT32_C(1));
135 CHECK(bit_cast<uint64_t>(bkend.call_with_return("env", "cast")->to_f64()) == UINT64_C(4631107791820423168));
136 CHECK(bkend.call_with_return("env", "i32_load8_s", UINT32_C(4294967295))->to_ui32() == UINT32_C(4294967295));
137 CHECK(bkend.call_with_return("env", "i32_load8_u", UINT32_C(4294967295))->to_ui32() == UINT32_C(255));
138 CHECK(bkend.call_with_return("env", "i32_load16_s", UINT32_C(4294967295))->to_ui32() == UINT32_C(4294967295));
139 CHECK(bkend.call_with_return("env", "i32_load16_u", UINT32_C(4294967295))->to_ui32() == UINT32_C(65535));
140 CHECK(bkend.call_with_return("env", "i32_load8_s", UINT32_C(100))->to_ui32() == UINT32_C(100));
141 CHECK(bkend.call_with_return("env", "i32_load8_u", UINT32_C(200))->to_ui32() == UINT32_C(200));
142 CHECK(bkend.call_with_return("env", "i32_load16_s", UINT32_C(20000))->to_ui32() == UINT32_C(20000));
143 CHECK(bkend.call_with_return("env", "i32_load16_u", UINT32_C(40000))->to_ui32() == UINT32_C(40000));
144 CHECK(bkend.call_with_return("env", "i32_load8_s", UINT32_C(4275856707))->to_ui32() == UINT32_C(67));
145 CHECK(bkend.call_with_return("env", "i32_load8_s", UINT32_C(878104047))->to_ui32() == UINT32_C(4294967279));
146 CHECK(bkend.call_with_return("env", "i32_load8_u", UINT32_C(4275856707))->to_ui32() == UINT32_C(67));
147 CHECK(bkend.call_with_return("env", "i32_load8_u", UINT32_C(878104047))->to_ui32() == UINT32_C(239));
148 CHECK(bkend.call_with_return("env", "i32_load16_s", UINT32_C(4275856707))->to_ui32() == UINT32_C(25923));
149 CHECK(bkend.call_with_return("env", "i32_load16_s", UINT32_C(878104047))->to_ui32() == UINT32_C(4294954479));
150 CHECK(bkend.call_with_return("env", "i32_load16_u", UINT32_C(4275856707))->to_ui32() == UINT32_C(25923));
151 CHECK(bkend.call_with_return("env", "i32_load16_u", UINT32_C(878104047))->to_ui32() == UINT32_C(52719));
152 CHECK(bkend.call_with_return("env", "i64_load8_s", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(18446744073709551615));
153 CHECK(bkend.call_with_return("env", "i64_load8_u", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(255));
154 CHECK(bkend.call_with_return("env", "i64_load16_s", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(18446744073709551615));
155 CHECK(bkend.call_with_return("env", "i64_load16_u", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(65535));
156 CHECK(bkend.call_with_return("env", "i64_load32_s", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(18446744073709551615));
157 CHECK(bkend.call_with_return("env", "i64_load32_u", UINT64_C(18446744073709551615))->to_ui64() == UINT32_C(4294967295));
158 CHECK(bkend.call_with_return("env", "i64_load8_s", UINT64_C(100))->to_ui64() == UINT32_C(100));
159 CHECK(bkend.call_with_return("env", "i64_load8_u", UINT64_C(200))->to_ui64() == UINT32_C(200));
160 CHECK(bkend.call_with_return("env", "i64_load16_s", UINT64_C(20000))->to_ui64() == UINT32_C(20000));
161 CHECK(bkend.call_with_return("env", "i64_load16_u", UINT64_C(40000))->to_ui64() == UINT32_C(40000));
162 CHECK(bkend.call_with_return("env", "i64_load32_s", UINT64_C(20000))->to_ui64() == UINT32_C(20000));
163 CHECK(bkend.call_with_return("env", "i64_load32_u", UINT64_C(40000))->to_ui64() == UINT32_C(40000));
164 CHECK(bkend.call_with_return("env", "i64_load8_s", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(67));
165 CHECK(bkend.call_with_return("env", "i64_load8_s", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(18446744073709551599));
166 CHECK(bkend.call_with_return("env", "i64_load8_u", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(67));
167 CHECK(bkend.call_with_return("env", "i64_load8_u", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(239));
168 CHECK(bkend.call_with_return("env", "i64_load16_s", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(25923));
169 CHECK(bkend.call_with_return("env", "i64_load16_s", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(18446744073709538799));
170 CHECK(bkend.call_with_return("env", "i64_load16_u", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(25923));
171 CHECK(bkend.call_with_return("env", "i64_load16_u", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(52719));
172 CHECK(bkend.call_with_return("env", "i64_load32_s", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(1446274371));
173 CHECK(bkend.call_with_return("env", "i64_load32_s", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(18446744071976963567));
174 CHECK(bkend.call_with_return("env", "i64_load32_u", UINT64_C(18364758543954109763))->to_ui64() == UINT32_C(1446274371));
175 CHECK(bkend.call_with_return("env", "i64_load32_u", UINT64_C(3771275841602506223))->to_ui64() == UINT32_C(2562379247));
176}
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
#define UINT32_C(val)
Definition stdint.h:283
#define UINT64_C(val)
Definition stdint.h:284
T bit_cast(const U &u)
Definition utils.hpp:35
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [19/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_2_wasm>" ,
"" [memory_2_wasm_tests] )

Definition at line 92 of file memory_tests.cpp.

92 {
94 auto code = read_wasm( std::string(wasm_directory) + "memory.2.wasm");
95 backend_t bkend( code, &wa );
96
97}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [20/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_3_wasm>" ,
"" [memory_3_wasm_tests] )

Definition at line 178 of file memory_tests.cpp.

178 {
180 auto code = read_wasm( std::string(wasm_directory) + "memory.3.wasm");
181 backend_t bkend( code, &wa );
182
183}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [21/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_4_wasm>" ,
"" [memory_4_wasm_tests] )

Definition at line 185 of file memory_tests.cpp.

185 {
187 auto code = read_wasm( std::string(wasm_directory) + "memory.4.wasm");
188 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
189}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [22/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_5_wasm>" ,
"" [memory_5_wasm_tests] )

Definition at line 191 of file memory_tests.cpp.

191 {
193 auto code = read_wasm( std::string(wasm_directory) + "memory.5.wasm");
194 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
195}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [23/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_6_wasm>" ,
"" [memory_6_wasm_tests] )

Definition at line 197 of file memory_tests.cpp.

197 {
199 auto code = read_wasm( std::string(wasm_directory) + "memory.6.wasm");
200 backend_t bkend( code, &wa );
201
202 CHECK(bkend.call_with_return("env", "memsize")->to_ui32() == UINT32_C(0));
203}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [24/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_7_wasm>" ,
"" [memory_7_wasm_tests] )

Definition at line 205 of file memory_tests.cpp.

205 {
207 auto code = read_wasm( std::string(wasm_directory) + "memory.7.wasm");
208 backend_t bkend( code, &wa );
209
210 CHECK(bkend.call_with_return("env", "memsize")->to_ui32() == UINT32_C(0));
211}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [25/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_8_wasm>" ,
"" [memory_8_wasm_tests] )

Definition at line 213 of file memory_tests.cpp.

213 {
215 auto code = read_wasm( std::string(wasm_directory) + "memory.8.wasm");
216 backend_t bkend( code, &wa );
217
218 CHECK(bkend.call_with_return("env", "memsize")->to_ui32() == UINT32_C(1));
219}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [26/26]

BACKEND_TEST_CASE ( "Testing wasm <memory_9_wasm>" ,
"" [memory_9_wasm_tests] )

Definition at line 221 of file memory_tests.cpp.

221 {
223 auto code = read_wasm( std::string(wasm_directory) + "memory.9.wasm");
224 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
225}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.