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

Go to the source code of this file.

Functions

 BACKEND_TEST_CASE ("Testing wasm <traps_0_wasm>", "[traps_0_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <traps_1_wasm>", "[traps_1_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <traps_2_wasm>", "[traps_2_wasm_tests]")
 
 BACKEND_TEST_CASE ("Testing wasm <traps_3_wasm>", "[traps_3_wasm_tests]")
 

Variables

wasm_allocator wa
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/4]

BACKEND_TEST_CASE ( "Testing wasm <traps_0_wasm>" ,
"" [traps_0_wasm_tests] )

Definition at line 18 of file traps_tests.cpp.

18 {
20 auto code = read_wasm( std::string(wasm_directory) + "traps.0.wasm");
21 backend_t bkend( code, &wa );
22
23 CHECK_THROWS_AS(bkend("env", "no_dce.i32.div_s", UINT32_C(1), UINT32_C(0)), std::exception);
24 CHECK_THROWS_AS(bkend("env", "no_dce.i32.div_u", UINT32_C(1), UINT32_C(0)), std::exception);
25 CHECK_THROWS_AS(bkend("env", "no_dce.i64.div_s", UINT64_C(1), UINT64_C(0)), std::exception);
26 CHECK_THROWS_AS(bkend("env", "no_dce.i64.div_u", UINT64_C(1), UINT64_C(0)), std::exception);
27 CHECK_THROWS_AS(bkend("env", "no_dce.i32.div_s", UINT32_C(2147483648), UINT32_C(4294967295)), std::exception);
28 CHECK_THROWS_AS(bkend("env", "no_dce.i64.div_s", UINT64_C(9223372036854775808), UINT64_C(18446744073709551615)), std::exception);
29}
backend_t bkend(hello_wasm, ehm, &wa)
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
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/4]

BACKEND_TEST_CASE ( "Testing wasm <traps_1_wasm>" ,
"" [traps_1_wasm_tests] )

Definition at line 31 of file traps_tests.cpp.

31 {
33 auto code = read_wasm( std::string(wasm_directory) + "traps.1.wasm");
34 backend_t bkend( code, &wa );
35
36 CHECK_THROWS_AS(bkend("env", "no_dce.i32.rem_s", UINT32_C(1), UINT32_C(0)), std::exception);
37 CHECK_THROWS_AS(bkend("env", "no_dce.i32.rem_u", UINT32_C(1), UINT32_C(0)), std::exception);
38 CHECK_THROWS_AS(bkend("env", "no_dce.i64.rem_s", UINT64_C(1), UINT64_C(0)), std::exception);
39 CHECK_THROWS_AS(bkend("env", "no_dce.i64.rem_u", UINT64_C(1), UINT64_C(0)), std::exception);
40}
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [3/4]

BACKEND_TEST_CASE ( "Testing wasm <traps_2_wasm>" ,
"" [traps_2_wasm_tests] )

Definition at line 42 of file traps_tests.cpp.

42 {
44 auto code = read_wasm( std::string(wasm_directory) + "traps.2.wasm");
45 backend_t bkend( code, &wa );
46
47 CHECK_THROWS_AS(bkend("env", "no_dce.i32.trunc_f32_s", bit_cast<float>(UINT32_C(2143289344))), std::exception);
48 CHECK_THROWS_AS(bkend("env", "no_dce.i32.trunc_f32_u", bit_cast<float>(UINT32_C(2143289344))), std::exception);
49 CHECK_THROWS_AS(bkend("env", "no_dce.i32.trunc_f64_s", bit_cast<double>(UINT64_C(9221120237041090560))), std::exception);
50 CHECK_THROWS_AS(bkend("env", "no_dce.i32.trunc_f64_u", bit_cast<double>(UINT64_C(9221120237041090560))), std::exception);
51 CHECK_THROWS_AS(bkend("env", "no_dce.i64.trunc_f32_s", bit_cast<float>(UINT32_C(2143289344))), std::exception);
52 CHECK_THROWS_AS(bkend("env", "no_dce.i64.trunc_f32_u", bit_cast<float>(UINT32_C(2143289344))), std::exception);
53 CHECK_THROWS_AS(bkend("env", "no_dce.i64.trunc_f64_s", bit_cast<double>(UINT64_C(9221120237041090560))), std::exception);
54 CHECK_THROWS_AS(bkend("env", "no_dce.i64.trunc_f64_u", bit_cast<double>(UINT64_C(9221120237041090560))), std::exception);
55}
T bit_cast(const U &u)
Definition utils.hpp:35
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [4/4]

BACKEND_TEST_CASE ( "Testing wasm <traps_3_wasm>" ,
"" [traps_3_wasm_tests] )

Definition at line 57 of file traps_tests.cpp.

57 {
59 auto code = read_wasm( std::string(wasm_directory) + "traps.3.wasm");
60 backend_t bkend( code, &wa );
61
62 CHECK_THROWS_AS(bkend("env", "no_dce.i32.load", UINT32_C(65536)), std::exception);
63 CHECK_THROWS_AS(bkend("env", "no_dce.i32.load16_s", UINT32_C(65536)), std::exception);
64 CHECK_THROWS_AS(bkend("env", "no_dce.i32.load16_u", UINT32_C(65536)), std::exception);
65 CHECK_THROWS_AS(bkend("env", "no_dce.i32.load8_s", UINT32_C(65536)), std::exception);
66 CHECK_THROWS_AS(bkend("env", "no_dce.i32.load8_u", UINT32_C(65536)), std::exception);
67 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load", UINT32_C(65536)), std::exception);
68 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load32_s", UINT32_C(65536)), std::exception);
69 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load32_u", UINT32_C(65536)), std::exception);
70 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load16_s", UINT32_C(65536)), std::exception);
71 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load16_u", UINT32_C(65536)), std::exception);
72 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load8_s", UINT32_C(65536)), std::exception);
73 CHECK_THROWS_AS(bkend("env", "no_dce.i64.load8_u", UINT32_C(65536)), std::exception);
74 CHECK_THROWS_AS(bkend("env", "no_dce.f32.load", UINT32_C(65536)), std::exception);
75 CHECK_THROWS_AS(bkend("env", "no_dce.f64.load", UINT32_C(65536)), std::exception);
76}
Here is the call graph for this function:

Variable Documentation

◆ wa

wasm_allocator wa
extern

Definition at line 10 of file main.cpp.