Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
allow_zero_blocktype_tests.cpp
Go to the documentation of this file.
1#include <sysio/vm/backend.hpp>
2
3#include "utils.hpp"
4#include <catch2/catch.hpp>
5
6using namespace sysio::vm;
7
8extern wasm_allocator wa;
9
10namespace {
11
12/*
13 * (module
14 * (func (block))
15 * )
16 */
17std::vector<uint8_t> block_wasm = {
18 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
19 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x07, 0x01, 0x05, 0x00, 0x02,
20 0x00 /* was 0x40 */, 0x0b, 0x0b
21};
22
23/*
24 * (module
25 * (func (loop))
26 * )
27 */
28std::vector<uint8_t> loop_wasm = {
29 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
30 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x07, 0x01, 0x05, 0x00, 0x03,
31 0x00 /* was 0x40 */, 0x0b, 0x0b
32};
33
34/*
35 * (module
36 * (func (if (i32.const 0) (then)))
37 * )
38 */
39std::vector<uint8_t> if_wasm = {
40 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
41 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x41,
42 0x00, 0x04, 0x00 /* was 0x40 */, 0x0b, 0x0b
43};
44
45struct empty_options {};
46struct static_options_false {
47 static constexpr bool allow_zero_blocktype = false;
48};
49struct static_options_true {
50 static constexpr std::uint32_t allow_zero_blocktype = true;
51};
52struct dynamic_options {
53 bool allow_zero_blocktype;
54};
55
56}
57
58BACKEND_TEST_CASE("Test allow_zero_blocktype default", "[allow_zero_blocktype_test]") {
60 CHECK_THROWS_AS(backend_t(block_wasm, &wa), wasm_parse_exception);
61 CHECK_THROWS_AS(backend_t(loop_wasm, &wa), wasm_parse_exception);
62 CHECK_THROWS_AS(backend_t(if_wasm, &wa), wasm_parse_exception);
63}
64
65BACKEND_TEST_CASE("Test allow_zero_blocktype empty", "[allow_zero_blocktype_test]") {
67 CHECK_THROWS_AS(backend_t(block_wasm, &wa), wasm_parse_exception);
68 CHECK_THROWS_AS(backend_t(loop_wasm, &wa), wasm_parse_exception);
69 CHECK_THROWS_AS(backend_t(if_wasm, &wa), wasm_parse_exception);
70}
71
72BACKEND_TEST_CASE("Test allow_zero_blocktype static fail", "[allow_zero_blocktype_test]") {
74 CHECK_THROWS_AS(backend_t(block_wasm, &wa), wasm_parse_exception);
75 CHECK_THROWS_AS(backend_t(loop_wasm, &wa), wasm_parse_exception);
76 CHECK_THROWS_AS(backend_t(if_wasm, &wa), wasm_parse_exception);
77}
78
79BACKEND_TEST_CASE("Test allow_zero_blocktype static pass", "[allow_zero_blocktype_test]") {
81 backend_t backend_block(block_wasm, &wa);
82 backend_t backend_loop(loop_wasm, &wa);
83 backend_t backend_if(if_wasm, &wa);
84}
85
86BACKEND_TEST_CASE("Test allow_zero_blocktype dynamic fail", "[allow_zero_blocktype_test]") {
88 CHECK_THROWS_AS(backend_t(block_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
89 CHECK_THROWS_AS(backend_t(loop_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
90 CHECK_THROWS_AS(backend_t(if_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
91}
92
93BACKEND_TEST_CASE("Test allow_zero_blocktype dynamic pass", "[allow_zero_blocktype_test]") {
95 backend_t backend_block(block_wasm, nullptr, dynamic_options{true});
96 backend_t backend_loop(loop_wasm, nullptr, dynamic_options{true});
97 backend_t backend_if(if_wasm, nullptr, dynamic_options{true});
98}
wasm_allocator wa
Definition main.cpp:10
sysio::vm::backend< rhf_t > backend_t
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59