Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
max_code_bytes_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 (local i32))
15 * )
16 */
17std::vector<uint8_t> func_wasm = {
18 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60,
19 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x06, 0x01, 0x04, 0x01, 0x01,
20 0x7f, 0x0b
21};
22
23struct empty_options {};
24struct static_options_3 {
25 static constexpr std::uint32_t max_code_bytes = 3;
26};
27struct static_options_4 {
28 static constexpr std::uint32_t max_code_bytes = 4;
29};
30struct dynamic_options {
31 std::uint32_t max_code_bytes;
32};
33
34}
35
36BACKEND_TEST_CASE("Test max_code_bytes default", "[max_code_bytes_test]") {
38 backend_t backend(func_wasm, &wa);
39}
40
41BACKEND_TEST_CASE("Test max_code_bytes unlimited", "[max_code_bytes_test]") {
43 backend_t backend(func_wasm, &wa);
44}
45
46BACKEND_TEST_CASE("Test max_code_bytes static fail", "[max_code_bytes_test]") {
48 CHECK_THROWS_AS(backend_t(func_wasm, &wa), wasm_parse_exception);
49}
50
51BACKEND_TEST_CASE("Test max_code_bytes static pass", "[max_code_bytes_test]") {
53 backend_t backend(func_wasm, &wa);
54}
55
56BACKEND_TEST_CASE("Test max_code_bytes dynamic fail", "[max_code_bytes_test]") {
58 CHECK_THROWS_AS(backend_t(func_wasm, nullptr, dynamic_options{3}), wasm_parse_exception);
59}
60
61BACKEND_TEST_CASE("Test max_code_bytes dynamic pass", "[max_code_bytes_test]") {
63 backend_t backend(func_wasm, nullptr, dynamic_options{4});
64}
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