Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
forbid_export_mutable_globals_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 * (global (export "i") (mut i32) (i32.const 0))
15 * )
16 */
17std::vector<uint8_t> mut_global_wasm = {
18 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x06, 0x06, 0x01, 0x7f,
19 0x01, 0x41, 0x00, 0x0b, 0x07, 0x05, 0x01, 0x01, 0x69, 0x03, 0x00
20};
21
22struct empty_options {};
23struct static_options_false {
24 static constexpr bool forbid_export_mutable_globals = false;
25};
26struct static_options_true {
27 static constexpr bool forbid_export_mutable_globals = true;
28};
29struct dynamic_options {
30 bool forbid_export_mutable_globals;
31};
32
33}
34
35BACKEND_TEST_CASE("Test forbid_export_mutable_globals default", "[forbid_export_mutable_globals_test]") {
37 backend_t backend(mut_global_wasm, &wa);
38}
39
40BACKEND_TEST_CASE("Test forbid_export_mutable_globals empty", "[forbid_export_mutable_globals_test]") {
42 backend_t backend(mut_global_wasm, &wa);
43}
44
45BACKEND_TEST_CASE("Test forbid_export_mutable_globals static pass", "[forbid_export_mutable_globals_test]") {
47 backend_t backend(mut_global_wasm, &wa);
48}
49
50BACKEND_TEST_CASE("Test forbid_export_mutable_globals static fail", "[forbid_export_mutable_globals_test]") {
52 CHECK_THROWS_AS(backend_t(mut_global_wasm, &wa), wasm_parse_exception);
53}
54
55BACKEND_TEST_CASE("Test forbid_export_mutable_globals dynamic pass", "[forbid_export_mutable_globals_test]") {
57 backend_t backend(mut_global_wasm, nullptr, dynamic_options{false});
58}
59
60BACKEND_TEST_CASE("Test forbid_export_mutable_globals dynamic fail", "[forbid_export_mutable_globals_test]") {
62 CHECK_THROWS_AS(backend_t(mut_global_wasm, nullptr, dynamic_options{true}), wasm_parse_exception);
63}
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