Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio_max_nested_structures_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)
15 * (func
16 * (if (i32.const 0) (then) (else (drop (i32.const 0))))
17 * (block (block))
18 * )
19 * )
20 */
21std::vector<uint8_t> nested_4_wasm = {
22 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
23 0x00, 0x00, 0x03, 0x03, 0x02, 0x00, 0x00, 0x0a, 0x16, 0x02, 0x02, 0x00,
24 0x0b, 0x11, 0x00, 0x41, 0x00, 0x04, 0x40, 0x05, 0x41, 0x00, 0x1a, 0x0b,
25 0x02, 0x40, 0x02, 0x40, 0x0b, 0x0b, 0x0b
26};
27
28/*
29 * (module
30 * (func
31 * (if (i32.const 0) (then) (else (drop (i32.const 0))))
32 * (block (block (block)))
33 * )
34 * )
35 */
36std::vector<uint8_t> nested_4_wasm_2 = {
37 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
38 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x16, 0x01, 0x14, 0x00, 0x41,
39 0x00, 0x04, 0x40, 0x05, 0x41, 0x00, 0x1a, 0x0b, 0x02, 0x40, 0x02, 0x40,
40 0x02, 0x40, 0x0b, 0x0b, 0x0b, 0x0b
41};
42
43struct empty_options {};
44struct static_options_3 {
45 static constexpr std::uint32_t sysio_max_nested_structures = 3;
46};
47struct static_options_4 {
48 static constexpr std::uint32_t sysio_max_nested_structures = 4;
49};
50struct dynamic_options {
51 std::uint32_t sysio_max_nested_structures;
52};
53
54}
55
56BACKEND_TEST_CASE("Test sysio_max_nested_structures default", "[sysio_max_nested_structures_test]") {
58 backend_t backend(nested_4_wasm, &wa);
59 backend_t backend2(nested_4_wasm_2, &wa);
60}
61
62BACKEND_TEST_CASE("Test sysio_max_nested_structures unlimited", "[sysio_max_nested_structures_test]") {
64 backend_t backend(nested_4_wasm, &wa);
65 backend_t backend2(nested_4_wasm_2, &wa);
66}
67
68BACKEND_TEST_CASE("Test sysio_max_nested_structures static fail", "[sysio_max_nested_structures_test]") {
70 CHECK_THROWS_AS(backend_t(nested_4_wasm, &wa), wasm_parse_exception);
71 CHECK_THROWS_AS(backend_t(nested_4_wasm_2, &wa), wasm_parse_exception);
72}
73
74BACKEND_TEST_CASE("Test sysio_max_nested_structures static pass", "[sysio_max_nested_structures_test]") {
76 backend_t backend(nested_4_wasm, &wa);
77 backend_t backend2(nested_4_wasm_2, &wa);
78}
79
80BACKEND_TEST_CASE("Test sysio_max_nested_structures dynamic fail", "[sysio_max_nested_structures_test]") {
82 CHECK_THROWS_AS(backend_t(nested_4_wasm, nullptr, dynamic_options{3}), wasm_parse_exception);
83 CHECK_THROWS_AS(backend_t(nested_4_wasm_2, nullptr, dynamic_options{3}), wasm_parse_exception);
84}
85
86BACKEND_TEST_CASE("Test sysio_max_nested_structures dynamic pass", "[sysio_max_nested_structures_test]") {
88 backend_t backend(nested_4_wasm, nullptr, dynamic_options{4});
89 backend_t backend2(nested_4_wasm_2, nullptr, dynamic_options{4});
90}
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
wasm_allocator wa
Definition main.cpp:10