Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
allow_u32_limits_flags_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// All of these wasms use 0x3FFE/0x3FFF instead of 0x00/0x01 for the flags
13
14/*
15 * (module
16 * (memory 1)
17 * )
18 */
19std::vector<uint8_t> mem_no_max_wasm = {
20 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x05, 0x04, 0x01, 0xFE,
21 0x7F, 0x01
22};
23
24/*
25 * (module
26 * (memory 1 2)
27 * )
28 */
29std::vector<uint8_t> mem_max_wasm = {
30 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x05, 0x05, 0x01, 0xFF,
31 0x7F, 0x01, 0x02
32};
33
34/*
35 * (module
36 * (table 1)
37 * )
38 */
39std::vector<uint8_t> table_no_max_wasm = {
40 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x04, 0x05, 0x01, 0x70,
41 0xFE, 0x7F, 0x01
42};
43
44/*
45 * (module
46 * (table 1 2)
47 * )
48 */
49std::vector<uint8_t> table_max_wasm = {
50 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x04, 0x06, 0x01, 0x70,
51 0xFF, 0x7F, 0x01, 0x02
52};
53
54struct empty_options {};
55struct static_options_false {
56 static constexpr bool allow_u32_limits_flags = false;
57};
58struct static_options_true {
59 static constexpr bool allow_u32_limits_flags = true;
60};
61struct dynamic_options {
62 bool allow_u32_limits_flags;
63};
64
65}
66
67BACKEND_TEST_CASE("Test allow_u32_limits_flags default", "[allow_u32_limits_flags_test]") {
69 CHECK_THROWS_AS(backend_t(mem_no_max_wasm, &wa), wasm_parse_exception);
70 CHECK_THROWS_AS(backend_t(mem_max_wasm, &wa), wasm_parse_exception);
71 CHECK_THROWS_AS(backend_t(table_no_max_wasm, &wa), wasm_parse_exception);
72 CHECK_THROWS_AS(backend_t(table_max_wasm, &wa), wasm_parse_exception);
73}
74
75BACKEND_TEST_CASE("Test allow_u32_limits_flags empty", "[allow_u32_limits_flags_test]") {
77 CHECK_THROWS_AS(backend_t(mem_no_max_wasm, &wa), wasm_parse_exception);
78 CHECK_THROWS_AS(backend_t(mem_max_wasm, &wa), wasm_parse_exception);
79 CHECK_THROWS_AS(backend_t(table_no_max_wasm, &wa), wasm_parse_exception);
80 CHECK_THROWS_AS(backend_t(table_max_wasm, &wa), wasm_parse_exception);
81}
82
83BACKEND_TEST_CASE("Test allow_u32_limits_flags static fail", "[allow_u32_limits_flags_test]") {
85 CHECK_THROWS_AS(backend_t(mem_no_max_wasm, &wa), wasm_parse_exception);
86 CHECK_THROWS_AS(backend_t(mem_max_wasm, &wa), wasm_parse_exception);
87 CHECK_THROWS_AS(backend_t(table_no_max_wasm, &wa), wasm_parse_exception);
88 CHECK_THROWS_AS(backend_t(table_max_wasm, &wa), wasm_parse_exception);
89}
90
91BACKEND_TEST_CASE("Test allow_u32_limits_flags static pass", "[allow_u32_limits_flags_test]") {
93 backend_t backend_mem_no_max(mem_no_max_wasm, &wa);
94 backend_t backend_mem_max(mem_max_wasm, &wa);
95 backend_t backend_table_no_max(table_no_max_wasm, &wa);
96 backend_t backend_table_max(table_max_wasm, &wa);
97}
98
99BACKEND_TEST_CASE("Test allow_u32_limits_flags dynamic fail", "[allow_u32_limits_flags_test]") {
101 CHECK_THROWS_AS(backend_t(mem_max_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
102 CHECK_THROWS_AS(backend_t(mem_no_max_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
103 CHECK_THROWS_AS(backend_t(table_max_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
104 CHECK_THROWS_AS(backend_t(table_no_max_wasm, nullptr, dynamic_options{false}), wasm_parse_exception);
105}
106
107BACKEND_TEST_CASE("Test allow_u32_limits_flags dynamic pass", "[allow_u32_limits_flags_test]") {
109 backend_t backend_mem_max(mem_max_wasm, nullptr, dynamic_options{true});
110 backend_t backend_mem_no_max(mem_no_max_wasm, nullptr, dynamic_options{true});
111 backend_t backend_table_max(table_max_wasm, nullptr, dynamic_options{true});
112 backend_t backend_table_no_max(table_no_max_wasm, nullptr, dynamic_options{true});
113}
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