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

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <memory_size_0_wasm>", "[memory_size_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_size_1_wasm>", "[memory_size_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_size_2_wasm>", "[memory_size_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_size_3_wasm>", "[memory_size_3_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_size_4_wasm>", "[memory_size_4_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <memory_size_5_wasm>", "[memory_size_5_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_0_wasm>" ,
"" [memory_size_0_wasm_tests] )

Definition at line 18 of file memory_size_tests.cpp.

18 {
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}
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)
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/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_1_wasm>" ,
"" [memory_size_1_wasm_tests] )

Definition at line 32 of file memory_size_tests.cpp.

32 {
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}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_2_wasm>" ,
"" [memory_size_2_wasm_tests] )

Definition at line 46 of file memory_size_tests.cpp.

46 {
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}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_3_wasm>" ,
"" [memory_size_3_wasm_tests] )

Definition at line 64 of file memory_size_tests.cpp.

64 {
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}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [5/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_4_wasm>" ,
"" [memory_size_4_wasm_tests] )

Definition at line 82 of file memory_size_tests.cpp.

82 {
84 auto code = read_wasm( std::string(wasm_directory) + "memory_size.4.wasm");
85 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
86}
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() [6/6]

BACKEND_TEST_CASE ( "Testing wasm <memory_size_5_wasm>" ,
"" [memory_size_5_wasm_tests] )

Definition at line 88 of file memory_size_tests.cpp.

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

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.