Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
loop_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 <loop_0_wasm>", "[loop_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "loop.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(!bkend.call_with_return("env", "empty"));
24 CHECK(bkend.call_with_return("env", "singular")->to_ui32() == UINT32_C(7));
25 CHECK(bkend.call_with_return("env", "multi")->to_ui32() == UINT32_C(8));
26 CHECK(bkend.call_with_return("env", "nested")->to_ui32() == UINT32_C(9));
27 CHECK(bkend.call_with_return("env", "deep")->to_ui32() == UINT32_C(150));
28 CHECK(bkend.call_with_return("env", "as-select-first")->to_ui32() == UINT32_C(1));
29 CHECK(bkend.call_with_return("env", "as-select-mid")->to_ui32() == UINT32_C(2));
30 CHECK(bkend.call_with_return("env", "as-select-last")->to_ui32() == UINT32_C(2));
31 CHECK(!bkend.call_with_return("env", "as-if-condition"));
32 CHECK(bkend.call_with_return("env", "as-if-then")->to_ui32() == UINT32_C(1));
33 CHECK(bkend.call_with_return("env", "as-if-else")->to_ui32() == UINT32_C(2));
34 CHECK(bkend.call_with_return("env", "as-br_if-first")->to_ui32() == UINT32_C(1));
35 CHECK(bkend.call_with_return("env", "as-br_if-last")->to_ui32() == UINT32_C(2));
36 CHECK(bkend.call_with_return("env", "as-br_table-first")->to_ui32() == UINT32_C(1));
37 CHECK(bkend.call_with_return("env", "as-br_table-last")->to_ui32() == UINT32_C(2));
38 CHECK(bkend.call_with_return("env", "as-call_indirect-first")->to_ui32() == UINT32_C(1));
39 CHECK(bkend.call_with_return("env", "as-call_indirect-mid")->to_ui32() == UINT32_C(2));
40 CHECK(bkend.call_with_return("env", "as-call_indirect-last")->to_ui32() == UINT32_C(1));
41 CHECK(!bkend.call_with_return("env", "as-store-first"));
42 CHECK(!bkend.call_with_return("env", "as-store-last"));
43 CHECK(bkend.call_with_return("env", "as-memory.grow-value")->to_ui32() == UINT32_C(1));
44 CHECK(bkend.call_with_return("env", "as-call-value")->to_ui32() == UINT32_C(1));
45 CHECK(bkend.call_with_return("env", "as-return-value")->to_ui32() == UINT32_C(1));
46 CHECK(!bkend.call_with_return("env", "as-drop-operand"));
47 CHECK(bkend.call_with_return("env", "as-br-value")->to_ui32() == UINT32_C(1));
48 CHECK(bkend.call_with_return("env", "as-local.set-value")->to_ui32() == UINT32_C(1));
49 CHECK(bkend.call_with_return("env", "as-local.tee-value")->to_ui32() == UINT32_C(1));
50 CHECK(bkend.call_with_return("env", "as-global.set-value")->to_ui32() == UINT32_C(1));
51 CHECK(bkend.call_with_return("env", "as-load-operand")->to_ui32() == UINT32_C(1));
52 CHECK(bkend.call_with_return("env", "as-unary-operand")->to_ui32() == UINT32_C(0));
53 CHECK(bkend.call_with_return("env", "as-binary-operand")->to_ui32() == UINT32_C(12));
54 CHECK(bkend.call_with_return("env", "as-test-operand")->to_ui32() == UINT32_C(0));
55 CHECK(bkend.call_with_return("env", "as-compare-operand")->to_ui32() == UINT32_C(0));
56 CHECK(bkend.call_with_return("env", "break-bare")->to_ui32() == UINT32_C(19));
57 CHECK(bkend.call_with_return("env", "break-value")->to_ui32() == UINT32_C(18));
58 CHECK(bkend.call_with_return("env", "break-repeated")->to_ui32() == UINT32_C(18));
59 CHECK(bkend.call_with_return("env", "break-inner")->to_ui32() == UINT32_C(31));
60 CHECK(bkend.call_with_return("env", "effects")->to_ui32() == UINT32_C(1));
61 CHECK(bkend.call_with_return("env", "while", UINT64_C(0))->to_ui64() == UINT32_C(1));
62 CHECK(bkend.call_with_return("env", "while", UINT64_C(1))->to_ui64() == UINT32_C(1));
63 CHECK(bkend.call_with_return("env", "while", UINT64_C(2))->to_ui64() == UINT32_C(2));
64 CHECK(bkend.call_with_return("env", "while", UINT64_C(3))->to_ui64() == UINT32_C(6));
65 CHECK(bkend.call_with_return("env", "while", UINT64_C(5))->to_ui64() == UINT32_C(120));
66 CHECK(bkend.call_with_return("env", "while", UINT64_C(20))->to_ui64() == UINT32_C(2432902008176640000));
67 CHECK(bkend.call_with_return("env", "for", UINT64_C(0))->to_ui64() == UINT32_C(1));
68 CHECK(bkend.call_with_return("env", "for", UINT64_C(1))->to_ui64() == UINT32_C(1));
69 CHECK(bkend.call_with_return("env", "for", UINT64_C(2))->to_ui64() == UINT32_C(2));
70 CHECK(bkend.call_with_return("env", "for", UINT64_C(3))->to_ui64() == UINT32_C(6));
71 CHECK(bkend.call_with_return("env", "for", UINT64_C(5))->to_ui64() == UINT32_C(120));
72 CHECK(bkend.call_with_return("env", "for", UINT64_C(20))->to_ui64() == UINT32_C(2432902008176640000));
73 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(0)), bit_cast<float>(UINT32_C(1088421888)))->to_f32()) == UINT32_C(0));
74 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1088421888)), bit_cast<float>(UINT32_C(0)))->to_f32()) == UINT32_C(0));
75 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1065353216)))->to_f32()) == UINT32_C(1065353216));
76 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1073741824)))->to_f32()) == UINT32_C(1073741824));
77 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1077936128)))->to_f32()) == UINT32_C(1082130432));
78 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1082130432)))->to_f32()) == UINT32_C(1086324736));
79 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1120403456)))->to_f32()) == UINT32_C(1159684096));
80 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1065353216)), bit_cast<float>(UINT32_C(1120534528)))->to_f32()) == UINT32_C(1159892992));
81 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(1065353216)))->to_f32()) == UINT32_C(1065353216));
82 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1077936128)), bit_cast<float>(UINT32_C(1065353216)))->to_f32()) == UINT32_C(1065353216));
83 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1092616192)), bit_cast<float>(UINT32_C(1065353216)))->to_f32()) == UINT32_C(1065353216));
84 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(1073741824)))->to_f32()) == UINT32_C(1077936128));
85 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1073741824)), bit_cast<float>(UINT32_C(1077936128)))->to_f32()) == UINT32_C(1082130432));
86 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1088421888)), bit_cast<float>(UINT32_C(1082130432)))->to_f32()) == UINT32_C(1092940751));
87 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1088421888)), bit_cast<float>(UINT32_C(1120403456)))->to_f32()) == UINT32_C(1166601314));
88 CHECK(bit_cast<uint32_t>(bkend.call_with_return("env", "nesting", bit_cast<float>(UINT32_C(1088421888)), bit_cast<float>(UINT32_C(1120534528)))->to_f32()) == UINT32_C(1159892992));
89}
90
91BACKEND_TEST_CASE( "Testing wasm <loop_1_wasm>", "[loop_1_wasm_tests]" ) {
93 auto code = read_wasm( std::string(wasm_directory) + "loop.1.wasm");
94 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
95}
96
97BACKEND_TEST_CASE( "Testing wasm <loop_10_wasm>", "[loop_10_wasm_tests]" ) {
99 auto code = read_wasm( std::string(wasm_directory) + "loop.10.wasm");
100 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
101}
102
103BACKEND_TEST_CASE( "Testing wasm <loop_11_wasm>", "[loop_11_wasm_tests]" ) {
105 auto code = read_wasm( std::string(wasm_directory) + "loop.11.wasm");
106 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
107}
108
109BACKEND_TEST_CASE( "Testing wasm <loop_12_wasm>", "[loop_12_wasm_tests]" ) {
111 auto code = read_wasm( std::string(wasm_directory) + "loop.12.wasm");
112 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
113}
114
115BACKEND_TEST_CASE( "Testing wasm <loop_2_wasm>", "[loop_2_wasm_tests]" ) {
117 auto code = read_wasm( std::string(wasm_directory) + "loop.2.wasm");
118 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
119}
120
121BACKEND_TEST_CASE( "Testing wasm <loop_3_wasm>", "[loop_3_wasm_tests]" ) {
123 auto code = read_wasm( std::string(wasm_directory) + "loop.3.wasm");
124 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
125}
126
127BACKEND_TEST_CASE( "Testing wasm <loop_4_wasm>", "[loop_4_wasm_tests]" ) {
129 auto code = read_wasm( std::string(wasm_directory) + "loop.4.wasm");
130 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
131}
132
133BACKEND_TEST_CASE( "Testing wasm <loop_5_wasm>", "[loop_5_wasm_tests]" ) {
135 auto code = read_wasm( std::string(wasm_directory) + "loop.5.wasm");
136 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
137}
138
139BACKEND_TEST_CASE( "Testing wasm <loop_6_wasm>", "[loop_6_wasm_tests]" ) {
141 auto code = read_wasm( std::string(wasm_directory) + "loop.6.wasm");
142 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
143}
144
145BACKEND_TEST_CASE( "Testing wasm <loop_7_wasm>", "[loop_7_wasm_tests]" ) {
147 auto code = read_wasm( std::string(wasm_directory) + "loop.7.wasm");
148 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
149}
150
151BACKEND_TEST_CASE( "Testing wasm <loop_8_wasm>", "[loop_8_wasm_tests]" ) {
153 auto code = read_wasm( std::string(wasm_directory) + "loop.8.wasm");
154 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
155}
156
157BACKEND_TEST_CASE( "Testing wasm <loop_9_wasm>", "[loop_9_wasm_tests]" ) {
159 auto code = read_wasm( std::string(wasm_directory) + "loop.9.wasm");
160 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
161}
162
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 UINT64_C(val)
Definition stdint.h:284
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59
T bit_cast(const U &u)
Definition utils.hpp:35