Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory_grow_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_grow_tests.cpp:

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <memory_grow_0_wasm>", "[memory_grow_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_1_wasm>", "[memory_grow_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_2_wasm>", "[memory_grow_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_3_wasm>", "[memory_grow_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_4_wasm>", "[memory_grow_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_5_wasm>", "[memory_grow_5_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_6_wasm>", "[memory_grow_6_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_7_wasm>", "[memory_grow_7_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_8_wasm>", "[memory_grow_8_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_grow_9_wasm>", "[memory_grow_9_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_0_wasm>" ,
"" [memory_grow_0_wasm_tests] )

Definition at line 18 of file memory_grow_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(0));
24 CHECK_THROWS_AS(bkend("env", "store_at_zero"), std::exception);
25 CHECK_THROWS_AS(bkend("env", "load_at_zero"), std::exception);
26 CHECK_THROWS_AS(bkend("env", "store_at_page_size"), std::exception);
27 CHECK_THROWS_AS(bkend("env", "load_at_page_size"), std::exception);
28 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(0));
29 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
30 CHECK(bkend.call_with_return("env", "load_at_zero")->to_ui32() == UINT32_C(0));
31 CHECK(!bkend.call_with_return("env", "store_at_zero"));
32 CHECK(bkend.call_with_return("env", "load_at_zero")->to_ui32() == UINT32_C(2));
33 CHECK_THROWS_AS(bkend("env", "store_at_page_size"), std::exception);
34 CHECK_THROWS_AS(bkend("env", "load_at_page_size"), std::exception);
35 CHECK(bkend.call_with_return("env", "grow", UINT32_C(4))->to_ui32() == UINT32_C(1));
36 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(5));
37 CHECK(bkend.call_with_return("env", "load_at_zero")->to_ui32() == UINT32_C(2));
38 CHECK(!bkend.call_with_return("env", "store_at_zero"));
39 CHECK(bkend.call_with_return("env", "load_at_zero")->to_ui32() == UINT32_C(2));
40 CHECK(bkend.call_with_return("env", "load_at_page_size")->to_ui32() == UINT32_C(0));
41 CHECK(!bkend.call_with_return("env", "store_at_page_size"));
42 CHECK(bkend.call_with_return("env", "load_at_page_size")->to_ui32() == UINT32_C(3));
43}
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
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_1_wasm>" ,
"" [memory_grow_1_wasm_tests] )

Definition at line 45 of file memory_grow_tests.cpp.

45 {
47 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.1.wasm");
48 backend_t bkend( code, &wa );
49
50 CHECK(bkend.call_with_return("env", "grow", UINT32_C(0))->to_ui32() == UINT32_C(0));
51 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(0));
52 CHECK(bkend.call_with_return("env", "grow", UINT32_C(0))->to_ui32() == UINT32_C(1));
53 CHECK(bkend.call_with_return("env", "grow", UINT32_C(2))->to_ui32() == UINT32_C(1));
54 CHECK(bkend.call_with_return("env", "grow", UINT32_C(800))->to_ui32() == UINT32_C(3));
55 CHECK(bkend.call_with_return("env", "grow", UINT32_C(65536))->to_ui32() == UINT32_C(4294967295));
56 CHECK(bkend.call_with_return("env", "grow", UINT32_C(64736))->to_ui32() == UINT32_C(4294967295));
57 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(803));
58}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_2_wasm>" ,
"" [memory_grow_2_wasm_tests] )

Definition at line 60 of file memory_grow_tests.cpp.

60 {
62 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.2.wasm");
63 backend_t bkend( code, &wa );
64
65 CHECK(bkend.call_with_return("env", "grow", UINT32_C(0))->to_ui32() == UINT32_C(0));
66 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(0));
67 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(1));
68 CHECK(bkend.call_with_return("env", "grow", UINT32_C(2))->to_ui32() == UINT32_C(2));
69 CHECK(bkend.call_with_return("env", "grow", UINT32_C(6))->to_ui32() == UINT32_C(4));
70 CHECK(bkend.call_with_return("env", "grow", UINT32_C(0))->to_ui32() == UINT32_C(10));
71 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(4294967295));
72 CHECK(bkend.call_with_return("env", "grow", UINT32_C(65536))->to_ui32() == UINT32_C(4294967295));
73}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_3_wasm>" ,
"" [memory_grow_3_wasm_tests] )

Definition at line 75 of file memory_grow_tests.cpp.

75 {
77 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.3.wasm");
78 backend_t bkend( code, &wa );
79
80 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(0), UINT32_C(65535))->to_ui32() == UINT32_C(0));
81 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(1));
82 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(65536), UINT32_C(131071))->to_ui32() == UINT32_C(0));
83 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(2));
84 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(131072), UINT32_C(196607))->to_ui32() == UINT32_C(0));
85 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(3));
86 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(196608), UINT32_C(262143))->to_ui32() == UINT32_C(0));
87 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(4));
88 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(262144), UINT32_C(327679))->to_ui32() == UINT32_C(0));
89 CHECK(bkend.call_with_return("env", "grow", UINT32_C(1))->to_ui32() == UINT32_C(5));
90 CHECK(bkend.call_with_return("env", "check-memory-zero", UINT32_C(327680), UINT32_C(393215))->to_ui32() == UINT32_C(0));
91}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [5/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_4_wasm>" ,
"" [memory_grow_4_wasm_tests] )

Definition at line 93 of file memory_grow_tests.cpp.

93 {
95 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.4.wasm");
96 backend_t bkend( code, &wa );
97
98 CHECK(bkend.call_with_return("env", "as-br-value")->to_ui32() == UINT32_C(1));
99 CHECK(!bkend.call_with_return("env", "as-br_if-cond"));
100 CHECK(bkend.call_with_return("env", "as-br_if-value")->to_ui32() == UINT32_C(1));
101 CHECK(bkend.call_with_return("env", "as-br_if-value-cond")->to_ui32() == UINT32_C(6));
102 CHECK(!bkend.call_with_return("env", "as-br_table-index"));
103 CHECK(bkend.call_with_return("env", "as-br_table-value")->to_ui32() == UINT32_C(1));
104 CHECK(bkend.call_with_return("env", "as-br_table-value-index")->to_ui32() == UINT32_C(6));
105 CHECK(bkend.call_with_return("env", "as-return-value")->to_ui32() == UINT32_C(1));
106 CHECK(bkend.call_with_return("env", "as-if-cond")->to_ui32() == UINT32_C(0));
107 CHECK(bkend.call_with_return("env", "as-if-then")->to_ui32() == UINT32_C(1));
108 CHECK(bkend.call_with_return("env", "as-if-else")->to_ui32() == UINT32_C(1));
109 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(0), UINT32_C(1))->to_ui32() == UINT32_C(1));
110 CHECK(bkend.call_with_return("env", "as-select-second", UINT32_C(0), UINT32_C(0))->to_ui32() == UINT32_C(1));
111 CHECK(bkend.call_with_return("env", "as-select-cond")->to_ui32() == UINT32_C(0));
112 CHECK(bkend.call_with_return("env", "as-call-first")->to_ui32() == UINT32_C(4294967295));
113 CHECK(bkend.call_with_return("env", "as-call-mid")->to_ui32() == UINT32_C(4294967295));
114 CHECK(bkend.call_with_return("env", "as-call-last")->to_ui32() == UINT32_C(4294967295));
115 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(4294967295));
116 CHECK(bkend.call_with_return("env", "as-call_indirect-mid")->to_ui32() == UINT32_C(4294967295));
117 CHECK(bkend.call_with_return("env", "as-call_indirect-last")->to_ui32() == UINT32_C(4294967295));
118 CHECK_THROWS_AS(bkend("env", "as-call_indirect-index"), std::exception);
119 CHECK(!bkend.call_with_return("env", "as-local.set-value"));
120 CHECK(bkend.call_with_return("env", "as-local.tee-value")->to_ui32() == UINT32_C(1));
121 CHECK(!bkend.call_with_return("env", "as-global.set-value"));
122 CHECK(bkend.call_with_return("env", "as-load-address")->to_ui32() == UINT32_C(0));
123 CHECK(bkend.call_with_return("env", "as-loadN-address")->to_ui32() == UINT32_C(0));
124 CHECK(!bkend.call_with_return("env", "as-store-address"));
125 CHECK(!bkend.call_with_return("env", "as-store-value"));
126 CHECK(!bkend.call_with_return("env", "as-storeN-address"));
127 CHECK(!bkend.call_with_return("env", "as-storeN-value"));
128 CHECK(bkend.call_with_return("env", "as-unary-operand")->to_ui32() == UINT32_C(31));
129 CHECK(bkend.call_with_return("env", "as-binary-left")->to_ui32() == UINT32_C(11));
130 CHECK(bkend.call_with_return("env", "as-binary-right")->to_ui32() == UINT32_C(9));
131 CHECK(bkend.call_with_return("env", "as-test-operand")->to_ui32() == UINT32_C(0));
132 CHECK(bkend.call_with_return("env", "as-compare-left")->to_ui32() == UINT32_C(1));
133 CHECK(bkend.call_with_return("env", "as-compare-right")->to_ui32() == UINT32_C(1));
134 CHECK(bkend.call_with_return("env", "as-memory.grow-size")->to_ui32() == UINT32_C(1));
135}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [6/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_5_wasm>" ,
"" [memory_grow_5_wasm_tests] )

Definition at line 137 of file memory_grow_tests.cpp.

137 {
139 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.5.wasm");
140 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
141}
sysio::vm::backend< rhf_t > backend_t
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [7/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_6_wasm>" ,
"" [memory_grow_6_wasm_tests] )

Definition at line 143 of file memory_grow_tests.cpp.

143 {
145 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.6.wasm");
146 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
147}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [8/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_7_wasm>" ,
"" [memory_grow_7_wasm_tests] )

Definition at line 149 of file memory_grow_tests.cpp.

149 {
151 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.7.wasm");
152 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
153}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [9/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_8_wasm>" ,
"" [memory_grow_8_wasm_tests] )

Definition at line 155 of file memory_grow_tests.cpp.

155 {
157 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.8.wasm");
158 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
159}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [10/10]

BACKEND_TEST_CASE ( "Testing wasm <memory_grow_9_wasm>" ,
"" [memory_grow_9_wasm_tests] )

Definition at line 161 of file memory_grow_tests.cpp.

161 {
163 auto code = read_wasm( std::string(wasm_directory) + "memory_grow.9.wasm");
164 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
165}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.