Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
implementation_limits_tests.cpp File Reference
#include <algorithm>
#include <vector>
#include <iterator>
#include <cstdlib>
#include <fstream>
#include <string>
#include <catch2/catch.hpp>
#include <sysio/vm/backend.hpp>
#include "wasm_config.hpp"
#include "utils.hpp"
#include "implementation_limits.hpp"
Include dependency graph for implementation_limits_tests.cpp:

Go to the source code of this file.

Functions

void host_call ()
 
 BACKEND_TEST_CASE ("Test call depth", "[call_depth]")
 
 BACKEND_TEST_CASE ("Test call depth dynamic", "[call_depth]")
 

Function Documentation

◆ BACKEND_TEST_CASE() [1/2]

BACKEND_TEST_CASE ( "Test call depth dynamic" ,
"" [call_depth] )

Definition at line 55 of file implementation_limits_tests.cpp.

55 {
59 rhf_t::add<&host_call>("env", "host.call");
60
61 backend_t bkend(implementation_limits_wasm_code, nullptr, dynamic_options{151});
63 bkend.initialize(nullptr);
64
66
67 CHECK(!bkend.call_with_return("env", "call", (uint32_t)150));
68 CHECK_THROWS_AS(bkend.call("env", "call", (uint32_t)151), std::exception);
69 CHECK(!bkend.call_with_return("env", "call.indirect", (uint32_t)150));
70 CHECK_THROWS_AS(bkend.call("env", "call.indirect", (uint32_t)151), std::exception);
71 // The host call is added to the recursive function, so we have one fewer frames
72 CHECK(!bkend.call_with_return("env", "call.host", (uint32_t)149));
73 CHECK_THROWS_AS(bkend.call("env", "call.host", (uint32_t)150), std::exception);
74 CHECK(!bkend.call_with_return("env", "call.indirect.host", (uint32_t)149));
75 CHECK_THROWS_AS(bkend.call("env", "call.indirect.host", (uint32_t)150), std::exception);
76
77 bkend.initialize(nullptr, dynamic_options{51});
78
79 CHECK(!bkend.call_with_return("env", "call", (uint32_t)50));
80 CHECK_THROWS_AS(bkend.call("env", "call", (uint32_t)51), std::exception);
81 CHECK(!bkend.call_with_return("env", "call.indirect", (uint32_t)50));
82 CHECK_THROWS_AS(bkend.call("env", "call.indirect", (uint32_t)51), std::exception);
83 // The host call is added to the recursive function, so we have one fewer frames
84 CHECK(!bkend.call_with_return("env", "call.host", (uint32_t)49));
85 CHECK_THROWS_AS(bkend.call("env", "call.host", (uint32_t)50), std::exception);
86 CHECK(!bkend.call_with_return("env", "call.indirect.host", (uint32_t)49));
87 CHECK_THROWS_AS(bkend.call("env", "call.indirect.host", (uint32_t)50), std::exception);
88
89 // Very large call depth requires dynamically allocating a new stack
90 bkend.initialize(nullptr, dynamic_options{1024*1024});
91
92 CHECK(!bkend.call_with_return("env", "call", (uint32_t)1024*1024 - 1));
93}
wasm_allocator wa
Definition main.cpp:10
bool call(host_t *host, uint32_t func_index, Args... args)
Definition backend.hpp:148
backend & initialize(host_t *host, const Options &new_options)
Definition backend.hpp:118
auto call_with_return(host_t &host, const std::string_view &mod, const std::string_view &func, Args... args)
Definition backend.hpp:178
module & get_module()
Definition backend.hpp:248
void set_wasm_allocator(wasm_allocator *alloc)
Definition backend.hpp:242
#define CHECK(cond)
Definition util.h:80
backend_t bkend(hello_wasm, ehm, &wa)
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
unsigned int uint32_t
Definition stdint.h:126
static void add(const std::string &mod, const std::string &name)
Here is the call graph for this function:

◆ BACKEND_TEST_CASE() [2/2]

BACKEND_TEST_CASE ( "Test call depth" ,
"" [call_depth] )

Definition at line 33 of file implementation_limits_tests.cpp.

33 {
37
38 rhf_t::add<&host_call>("env", "host.call");
39
40 backend_t bkend(implementation_limits_wasm_code, get_wasm_allocator());
41
43
44 CHECK(!bkend.call_with_return("env", "call", (uint32_t)250));
45 CHECK_THROWS_AS(bkend.call("env", "call", (uint32_t)251), std::exception);
46 CHECK(!bkend.call_with_return("env", "call.indirect", (uint32_t)250));
47 CHECK_THROWS_AS(bkend.call("env", "call.indirect", (uint32_t)251), std::exception);
48 // The host call is added to the recursive function, so we have one fewer frames
49 CHECK(!bkend.call_with_return("env", "call.host", (uint32_t)249));
50 CHECK_THROWS_AS(bkend.call("env", "call.host", (uint32_t)250), std::exception);
51 CHECK(!bkend.call_with_return("env", "call.indirect.host", (uint32_t)249));
52 CHECK_THROWS_AS(bkend.call("env", "call.indirect.host", (uint32_t)250), std::exception);
53}
sysio::vm::wasm_allocator * get_wasm_allocator()
Definition utils.hpp:50
Here is the call graph for this function:

◆ host_call()

void host_call ( )

Definition at line 17 of file implementation_limits_tests.cpp.

17{}