Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
labels_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 <labels_0_wasm>", "[labels_0_wasm_tests]" ) {
20 auto code = read_wasm( std::string(wasm_directory) + "labels.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "block")->to_ui32() == UINT32_C(1));
24 CHECK(bkend.call_with_return("env", "loop1")->to_ui32() == UINT32_C(5));
25 CHECK(bkend.call_with_return("env", "loop2")->to_ui32() == UINT32_C(8));
26 CHECK(bkend.call_with_return("env", "loop3")->to_ui32() == UINT32_C(1));
27 CHECK(bkend.call_with_return("env", "loop4", UINT32_C(8))->to_ui32() == UINT32_C(16));
28 CHECK(bkend.call_with_return("env", "loop5")->to_ui32() == UINT32_C(2));
29 CHECK(bkend.call_with_return("env", "loop6")->to_ui32() == UINT32_C(3));
30 CHECK(bkend.call_with_return("env", "if")->to_ui32() == UINT32_C(5));
31 CHECK(bkend.call_with_return("env", "if2")->to_ui32() == UINT32_C(5));
32 CHECK(bkend.call_with_return("env", "switch", UINT32_C(0))->to_ui32() == UINT32_C(50));
33 CHECK(bkend.call_with_return("env", "switch", UINT32_C(1))->to_ui32() == UINT32_C(20));
34 CHECK(bkend.call_with_return("env", "switch", UINT32_C(2))->to_ui32() == UINT32_C(20));
35 CHECK(bkend.call_with_return("env", "switch", UINT32_C(3))->to_ui32() == UINT32_C(3));
36 CHECK(bkend.call_with_return("env", "switch", UINT32_C(4))->to_ui32() == UINT32_C(50));
37 CHECK(bkend.call_with_return("env", "switch", UINT32_C(5))->to_ui32() == UINT32_C(50));
38 CHECK(bkend.call_with_return("env", "return", UINT32_C(0))->to_ui32() == UINT32_C(0));
39 CHECK(bkend.call_with_return("env", "return", UINT32_C(1))->to_ui32() == UINT32_C(2));
40 CHECK(bkend.call_with_return("env", "return", UINT32_C(2))->to_ui32() == UINT32_C(2));
41 CHECK(bkend.call_with_return("env", "br_if0")->to_ui32() == UINT32_C(29));
42 CHECK(bkend.call_with_return("env", "br_if1")->to_ui32() == UINT32_C(1));
43 CHECK(bkend.call_with_return("env", "br_if2")->to_ui32() == UINT32_C(1));
44 CHECK(bkend.call_with_return("env", "br_if3")->to_ui32() == UINT32_C(2));
45 CHECK(bkend.call_with_return("env", "br")->to_ui32() == UINT32_C(1));
46 CHECK(bkend.call_with_return("env", "shadowing")->to_ui32() == UINT32_C(1));
47 CHECK(bkend.call_with_return("env", "redefinition")->to_ui32() == UINT32_C(5));
48}
49
50BACKEND_TEST_CASE( "Testing wasm <labels_1_wasm>", "[labels_1_wasm_tests]" ) {
52 auto code = read_wasm( std::string(wasm_directory) + "labels.1.wasm");
53 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
54}
55
56BACKEND_TEST_CASE( "Testing wasm <labels_2_wasm>", "[labels_2_wasm_tests]" ) {
58 auto code = read_wasm( std::string(wasm_directory) + "labels.2.wasm");
59 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
60}
61
62BACKEND_TEST_CASE( "Testing wasm <labels_3_wasm>", "[labels_3_wasm_tests]" ) {
64 auto code = read_wasm( std::string(wasm_directory) + "labels.3.wasm");
65 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
66}
67
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