Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
nop_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 <nop_0_wasm>", "[nop_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "nop.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "as-func-first")->to_ui32() == UINT32_C(1));
24 CHECK(bkend.call_with_return("env", "as-func-mid")->to_ui32() == UINT32_C(2));
25 CHECK(bkend.call_with_return("env", "as-func-last")->to_ui32() == UINT32_C(3));
26 CHECK(bkend.call_with_return("env", "as-func-everywhere")->to_ui32() == UINT32_C(4));
27 CHECK(!bkend.call_with_return("env", "as-drop-first", UINT32_C(0)));
28 CHECK(!bkend.call_with_return("env", "as-drop-last", UINT32_C(0)));
29 CHECK(!bkend.call_with_return("env", "as-drop-everywhere", UINT32_C(0)));
30 CHECK(bkend.call_with_return("env", "as-select-first", UINT32_C(3))->to_ui32() == UINT32_C(3));
31 CHECK(bkend.call_with_return("env", "as-select-mid1", UINT32_C(3))->to_ui32() == UINT32_C(3));
32 CHECK(bkend.call_with_return("env", "as-select-mid2", UINT32_C(3))->to_ui32() == UINT32_C(3));
33 CHECK(bkend.call_with_return("env", "as-select-last", UINT32_C(3))->to_ui32() == UINT32_C(3));
34 CHECK(bkend.call_with_return("env", "as-select-everywhere", UINT32_C(3))->to_ui32() == UINT32_C(3));
35 CHECK(bkend.call_with_return("env", "as-block-first")->to_ui32() == UINT32_C(2));
36 CHECK(bkend.call_with_return("env", "as-block-mid")->to_ui32() == UINT32_C(2));
37 CHECK(bkend.call_with_return("env", "as-block-last")->to_ui32() == UINT32_C(3));
38 CHECK(bkend.call_with_return("env", "as-block-everywhere")->to_ui32() == UINT32_C(4));
39 CHECK(bkend.call_with_return("env", "as-loop-first")->to_ui32() == UINT32_C(2));
40 CHECK(bkend.call_with_return("env", "as-loop-mid")->to_ui32() == UINT32_C(2));
41 CHECK(bkend.call_with_return("env", "as-loop-last")->to_ui32() == UINT32_C(3));
42 CHECK(bkend.call_with_return("env", "as-loop-everywhere")->to_ui32() == UINT32_C(4));
43 CHECK(!bkend.call_with_return("env", "as-if-condition", UINT32_C(0)));
44 CHECK(!bkend.call_with_return("env", "as-if-condition", UINT32_C(4294967295)));
45 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(0)));
46 CHECK(!bkend.call_with_return("env", "as-if-then", UINT32_C(4)));
47 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(0)));
48 CHECK(!bkend.call_with_return("env", "as-if-else", UINT32_C(3)));
49 CHECK(bkend.call_with_return("env", "as-br-first", UINT32_C(5))->to_ui32() == UINT32_C(5));
50 CHECK(bkend.call_with_return("env", "as-br-last", UINT32_C(6))->to_ui32() == UINT32_C(6));
51 CHECK(bkend.call_with_return("env", "as-br-everywhere", UINT32_C(7))->to_ui32() == UINT32_C(7));
52 CHECK(bkend.call_with_return("env", "as-br_if-first", UINT32_C(4))->to_ui32() == UINT32_C(4));
53 CHECK(bkend.call_with_return("env", "as-br_if-mid", UINT32_C(5))->to_ui32() == UINT32_C(5));
54 CHECK(bkend.call_with_return("env", "as-br_if-last", UINT32_C(6))->to_ui32() == UINT32_C(6));
55 CHECK(bkend.call_with_return("env", "as-br_if-everywhere", UINT32_C(7))->to_ui32() == UINT32_C(7));
56 CHECK(bkend.call_with_return("env", "as-br_table-first", UINT32_C(4))->to_ui32() == UINT32_C(4));
57 CHECK(bkend.call_with_return("env", "as-br_table-mid", UINT32_C(5))->to_ui32() == UINT32_C(5));
58 CHECK(bkend.call_with_return("env", "as-br_table-last", UINT32_C(6))->to_ui32() == UINT32_C(6));
59 CHECK(bkend.call_with_return("env", "as-br_table-everywhere", UINT32_C(7))->to_ui32() == UINT32_C(7));
60 CHECK(bkend.call_with_return("env", "as-return-first", UINT32_C(5))->to_ui32() == UINT32_C(5));
61 CHECK(bkend.call_with_return("env", "as-return-last", UINT32_C(6))->to_ui32() == UINT32_C(6));
62 CHECK(bkend.call_with_return("env", "as-return-everywhere", UINT32_C(7))->to_ui32() == UINT32_C(7));
63 CHECK(bkend.call_with_return("env", "as-call-first", UINT32_C(3), UINT32_C(1), UINT32_C(2))->to_ui32() == UINT32_C(2));
64 CHECK(bkend.call_with_return("env", "as-call-mid1", UINT32_C(3), UINT32_C(1), UINT32_C(2))->to_ui32() == UINT32_C(2));
65 CHECK(bkend.call_with_return("env", "as-call-mid2", UINT32_C(0), UINT32_C(3), UINT32_C(1))->to_ui32() == UINT32_C(2));
66 CHECK(bkend.call_with_return("env", "as-call-last", UINT32_C(10), UINT32_C(9), UINT32_C(4294967295))->to_ui32() == UINT32_C(20));
67 CHECK(bkend.call_with_return("env", "as-call-everywhere", UINT32_C(2), UINT32_C(1), UINT32_C(5))->to_ui32() == UINT32_C(4294967294));
68 CHECK(bkend.call_with_return("env", "as-unary-first", UINT32_C(30))->to_ui32() == UINT32_C(1));
69 CHECK(bkend.call_with_return("env", "as-unary-last", UINT32_C(30))->to_ui32() == UINT32_C(1));
70 CHECK(bkend.call_with_return("env", "as-unary-everywhere", UINT32_C(12))->to_ui32() == UINT32_C(2));
71 CHECK(bkend.call_with_return("env", "as-binary-first", UINT32_C(3))->to_ui32() == UINT32_C(6));
72 CHECK(bkend.call_with_return("env", "as-binary-mid", UINT32_C(3))->to_ui32() == UINT32_C(6));
73 CHECK(bkend.call_with_return("env", "as-binary-last", UINT32_C(3))->to_ui32() == UINT32_C(6));
74 CHECK(bkend.call_with_return("env", "as-binary-everywhere", UINT32_C(3))->to_ui32() == UINT32_C(6));
75 CHECK(bkend.call_with_return("env", "as-test-first", UINT32_C(0))->to_ui32() == UINT32_C(1));
76 CHECK(bkend.call_with_return("env", "as-test-last", UINT32_C(0))->to_ui32() == UINT32_C(1));
77 CHECK(bkend.call_with_return("env", "as-test-everywhere", UINT32_C(0))->to_ui32() == UINT32_C(1));
78 CHECK(bkend.call_with_return("env", "as-compare-first", UINT32_C(3))->to_ui32() == UINT32_C(0));
79 CHECK(bkend.call_with_return("env", "as-compare-mid", UINT32_C(3))->to_ui32() == UINT32_C(0));
80 CHECK(bkend.call_with_return("env", "as-compare-last", UINT32_C(3))->to_ui32() == UINT32_C(0));
81 CHECK(bkend.call_with_return("env", "as-compare-everywhere", UINT32_C(3))->to_ui32() == UINT32_C(1));
82 CHECK(bkend.call_with_return("env", "as-memory.grow-first", UINT32_C(0))->to_ui32() == UINT32_C(1));
83 CHECK(bkend.call_with_return("env", "as-memory.grow-last", UINT32_C(2))->to_ui32() == UINT32_C(1));
84 CHECK(bkend.call_with_return("env", "as-memory.grow-everywhere", UINT32_C(12))->to_ui32() == UINT32_C(3));
85 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(1));
86 CHECK(bkend.call_with_return("env", "as-call_indirect-mid1")->to_ui32() == UINT32_C(1));
87 CHECK(bkend.call_with_return("env", "as-call_indirect-mid2")->to_ui32() == UINT32_C(1));
88 CHECK(bkend.call_with_return("env", "as-call_indirect-last")->to_ui32() == UINT32_C(1));
89 CHECK(bkend.call_with_return("env", "as-call_indirect-everywhere")->to_ui32() == UINT32_C(1));
90 CHECK(bkend.call_with_return("env", "as-local.set-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
91 CHECK(bkend.call_with_return("env", "as-local.set-last", UINT32_C(1))->to_ui32() == UINT32_C(2));
92 CHECK(bkend.call_with_return("env", "as-local.set-everywhere", UINT32_C(1))->to_ui32() == UINT32_C(2));
93 CHECK(bkend.call_with_return("env", "as-local.tee-first", UINT32_C(1))->to_ui32() == UINT32_C(2));
94 CHECK(bkend.call_with_return("env", "as-local.tee-last", UINT32_C(1))->to_ui32() == UINT32_C(2));
95 CHECK(bkend.call_with_return("env", "as-local.tee-everywhere", UINT32_C(1))->to_ui32() == UINT32_C(2));
96 CHECK(bkend.call_with_return("env", "as-global.set-first")->to_ui32() == UINT32_C(2));
97 CHECK(bkend.call_with_return("env", "as-global.set-last")->to_ui32() == UINT32_C(2));
98 CHECK(bkend.call_with_return("env", "as-global.set-everywhere")->to_ui32() == UINT32_C(2));
99 CHECK(bkend.call_with_return("env", "as-load-first", UINT32_C(100))->to_ui32() == UINT32_C(0));
100 CHECK(bkend.call_with_return("env", "as-load-last", UINT32_C(100))->to_ui32() == UINT32_C(0));
101 CHECK(bkend.call_with_return("env", "as-load-everywhere", UINT32_C(100))->to_ui32() == UINT32_C(0));
102 CHECK(!bkend.call_with_return("env", "as-store-first", UINT32_C(0), UINT32_C(1)));
103 CHECK(!bkend.call_with_return("env", "as-store-mid", UINT32_C(0), UINT32_C(2)));
104 CHECK(!bkend.call_with_return("env", "as-store-last", UINT32_C(0), UINT32_C(3)));
105 CHECK(!bkend.call_with_return("env", "as-store-everywhere", UINT32_C(0), UINT32_C(4)));
106}
107
108BACKEND_TEST_CASE( "Testing wasm <nop_1_wasm>", "[nop_1_wasm_tests]" ) {
110 auto code = read_wasm( std::string(wasm_directory) + "nop.1.wasm");
111 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
112}
113
114BACKEND_TEST_CASE( "Testing wasm <nop_2_wasm>", "[nop_2_wasm_tests]" ) {
116 auto code = read_wasm( std::string(wasm_directory) + "nop.2.wasm");
117 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
118}
119
120BACKEND_TEST_CASE( "Testing wasm <nop_3_wasm>", "[nop_3_wasm_tests]" ) {
122 auto code = read_wasm( std::string(wasm_directory) + "nop.3.wasm");
123 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
124}
125
126BACKEND_TEST_CASE( "Testing wasm <nop_4_wasm>", "[nop_4_wasm_tests]" ) {
128 auto code = read_wasm( std::string(wasm_directory) + "nop.4.wasm");
129 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
130}
131
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
std::vector< uint8_t > read_wasm(const std::string &fname)
Definition utils.hpp:30
wasm_allocator wa
Definition main.cpp:10
#define UINT32_C(val)
Definition stdint.h:283
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59