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

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <labels_0_wasm>", "[labels_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <labels_1_wasm>", "[labels_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <labels_2_wasm>", "[labels_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <labels_3_wasm>", "[labels_3_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/4]

BACKEND_TEST_CASE ( "Testing wasm <labels_0_wasm>" ,
"" [labels_0_wasm_tests] )

Definition at line 18 of file labels_tests.cpp.

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

BACKEND_TEST_CASE ( "Testing wasm <labels_1_wasm>" ,
"" [labels_1_wasm_tests] )

Definition at line 50 of file labels_tests.cpp.

50 {
52 auto code = read_wasm( std::string(wasm_directory) + "labels.1.wasm");
53 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
54}
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() [3/4]

BACKEND_TEST_CASE ( "Testing wasm <labels_2_wasm>" ,
"" [labels_2_wasm_tests] )

Definition at line 56 of file labels_tests.cpp.

56 {
58 auto code = read_wasm( std::string(wasm_directory) + "labels.2.wasm");
59 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
60}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/4]

BACKEND_TEST_CASE ( "Testing wasm <labels_3_wasm>" ,
"" [labels_3_wasm_tests] )

Definition at line 62 of file labels_tests.cpp.

62 {
64 auto code = read_wasm( std::string(wasm_directory) + "labels.3.wasm");
65 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
66}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.