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

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <switch_0_wasm>", "[switch_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <switch_1_wasm>", "[switch_1_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/2]

BACKEND_TEST_CASE ( "Testing wasm <switch_0_wasm>" ,
"" [switch_0_wasm_tests] )

Definition at line 18 of file switch_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "switch.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(0))->to_ui32() == UINT32_C(0));
24 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(1))->to_ui32() == UINT32_C(4294967295));
25 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(2))->to_ui32() == UINT32_C(4294967294));
26 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(3))->to_ui32() == UINT32_C(4294967293));
27 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(4))->to_ui32() == UINT32_C(100));
28 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(5))->to_ui32() == UINT32_C(101));
29 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(6))->to_ui32() == UINT32_C(102));
30 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(7))->to_ui32() == UINT32_C(100));
31 CHECK(bkend.call_with_return("env", "stmt", UINT32_C(4294967286))->to_ui32() == UINT32_C(102));
32 CHECK(bkend.call_with_return("env", "expr", UINT64_C(0))->to_ui64() == UINT32_C(0));
33 CHECK(bkend.call_with_return("env", "expr", UINT64_C(1))->to_ui64() == UINT32_C(18446744073709551615));
34 CHECK(bkend.call_with_return("env", "expr", UINT64_C(2))->to_ui64() == UINT32_C(18446744073709551614));
35 CHECK(bkend.call_with_return("env", "expr", UINT64_C(3))->to_ui64() == UINT32_C(18446744073709551613));
36 CHECK(bkend.call_with_return("env", "expr", UINT64_C(6))->to_ui64() == UINT32_C(101));
37 CHECK(bkend.call_with_return("env", "expr", UINT64_C(7))->to_ui64() == UINT32_C(18446744073709551611));
38 CHECK(bkend.call_with_return("env", "expr", UINT64_C(18446744073709551606))->to_ui64() == UINT32_C(100));
39 CHECK(bkend.call_with_return("env", "arg", UINT32_C(0))->to_ui32() == UINT32_C(110));
40 CHECK(bkend.call_with_return("env", "arg", UINT32_C(1))->to_ui32() == UINT32_C(12));
41 CHECK(bkend.call_with_return("env", "arg", UINT32_C(2))->to_ui32() == UINT32_C(4));
42 CHECK(bkend.call_with_return("env", "arg", UINT32_C(3))->to_ui32() == UINT32_C(1116));
43 CHECK(bkend.call_with_return("env", "arg", UINT32_C(4))->to_ui32() == UINT32_C(118));
44 CHECK(bkend.call_with_return("env", "arg", UINT32_C(5))->to_ui32() == UINT32_C(20));
45 CHECK(bkend.call_with_return("env", "arg", UINT32_C(6))->to_ui32() == UINT32_C(12));
46 CHECK(bkend.call_with_return("env", "arg", UINT32_C(7))->to_ui32() == UINT32_C(1124));
47 CHECK(bkend.call_with_return("env", "arg", UINT32_C(8))->to_ui32() == UINT32_C(126));
48 CHECK(bkend.call_with_return("env", "corner")->to_ui32() == UINT32_C(1));
49}
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)
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
wasm_allocator wa
Definition main.cpp:10
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/2]

BACKEND_TEST_CASE ( "Testing wasm <switch_1_wasm>" ,
"" [switch_1_wasm_tests] )

Definition at line 51 of file switch_tests.cpp.

51 {
53 auto code = read_wasm( std::string(wasm_directory) + "switch.1.wasm");
54 CHECK_THROWS_AS(backend_t(code, nullptr), std::exception);
55}
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:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.