Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
traps_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 <traps_0_wasm>", "[traps_0_wasm_tests]" ) {
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}
30
31BACKEND_TEST_CASE( "Testing wasm <traps_1_wasm>", "[traps_1_wasm_tests]" ) {
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}
41
42BACKEND_TEST_CASE( "Testing wasm <traps_2_wasm>", "[traps_2_wasm_tests]" ) {
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}
56
57BACKEND_TEST_CASE( "Testing wasm <traps_3_wasm>", "[traps_3_wasm_tests]" ) {
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}
77
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
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59
T bit_cast(const U &u)
Definition utils.hpp:35
wasm_allocator wa
Definition main.cpp:10