Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
max_table_elements_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 * (table 1024 funcref)
15 * )
16 */
17
18std::vector<uint8_t> _1024_elements_wasm = {
19 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x04, 0x05, 0x01, 0x70,
20 0x00, 0x80, 0x08
21};
22/*
23 * (module
24 * (table 1025 funcref)
25 * )
26 */
27
28std::vector<uint8_t> _1025_elements_wasm = {
29 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x04, 0x05, 0x01, 0x70,
30 0x00, 0x81, 0x08
31};
32
33struct empty_options {};
34struct dynamic_options {
35 std::uint32_t max_table_elements;
36};
37struct static_options {
38 static const std::uint32_t max_table_elements = 1024;
39};
40
41}
42
43BACKEND_TEST_CASE("Test max_table_elements default", "[max_table_elements_test]") {
45 backend_t backend1024(_1024_elements_wasm, &wa);
46 backend_t backend1025(_1025_elements_wasm, &wa);
47}
48
49BACKEND_TEST_CASE("Test max_table_elements static", "[max_table_elements_test]") {
51 backend_t backend(_1024_elements_wasm, &wa);
52 CHECK_THROWS_AS(backend_t(_1025_elements_wasm, &wa), wasm_parse_exception);
53}
54
55BACKEND_TEST_CASE("Test max_table_elements unlimited", "[max_table_elements_test]") {
57 backend_t backend1024(_1024_elements_wasm, &wa);
58 backend_t backend1025(_1025_elements_wasm, &wa);
59}
60
61BACKEND_TEST_CASE("Test max_table_elements dynamic", "[max_table_elements_test]") {
63 backend_t backend1024(_1024_elements_wasm, nullptr, dynamic_options{1024});
64 CHECK_THROWS_AS(backend_t(_1025_elements_wasm, nullptr, dynamic_options{1024}), wasm_parse_exception);
65 backend_t backend1025(_1025_elements_wasm, nullptr, dynamic_options{1025});
66}
sysio::vm::backend< rhf_t > backend_t
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
wasm_allocator wa
Definition main.cpp:10
#define BACKEND_TEST_CASE(name, tags)
Definition utils.hpp:59