Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memory_size_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_size_0_wasm>", "[memory_size_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "memory_size.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(0));
24 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
25 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
26 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(4)));
27 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(5));
28 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(0)));
29 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(5));
30}
31
32BACKEND_TEST_CASE( "Testing wasm <memory_size_1_wasm>", "[memory_size_1_wasm_tests]" ) {
34 auto code = read_wasm( std::string(wasm_directory) + "memory_size.1.wasm");
35 backend_t bkend( code, &wa );
36
37 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
38 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
39 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(2));
40 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(4)));
41 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(6));
42 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(0)));
43 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(6));
44}
45
46BACKEND_TEST_CASE( "Testing wasm <memory_size_2_wasm>", "[memory_size_2_wasm_tests]" ) {
48 auto code = read_wasm( std::string(wasm_directory) + "memory_size.2.wasm");
49 backend_t bkend( code, &wa );
50
51 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(0));
52 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(3)));
53 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(0));
54 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
55 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
56 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(0)));
57 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
58 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(4)));
59 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(1));
60 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
61 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(2));
62}
63
64BACKEND_TEST_CASE( "Testing wasm <memory_size_3_wasm>", "[memory_size_3_wasm_tests]" ) {
66 auto code = read_wasm( std::string(wasm_directory) + "memory_size.3.wasm");
67 backend_t bkend( code, &wa );
68
69 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(3));
70 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
71 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(4));
72 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(3)));
73 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(7));
74 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(0)));
75 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(7));
76 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(2)));
77 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(7));
78 CHECK(!bkend.call_with_return("env", "grow", UINT32_C(1)));
79 CHECK(bkend.call_with_return("env", "size")->to_ui32() == UINT32_C(8));
80}
81
82BACKEND_TEST_CASE( "Testing wasm <memory_size_4_wasm>", "[memory_size_4_wasm_tests]" ) {
84 auto code = read_wasm( std::string(wasm_directory) + "memory_size.4.wasm");
85 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
86}
87
88BACKEND_TEST_CASE( "Testing wasm <memory_size_5_wasm>", "[memory_size_5_wasm_tests]" ) {
90 auto code = read_wasm( std::string(wasm_directory) + "memory_size.5.wasm");
91 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
92}
93
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
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 BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59