-
Notifications
You must be signed in to change notification settings - Fork 8
/
limits.cpp
65 lines (48 loc) · 1.11 KB
/
limits.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "codebuilder.hpp"
TEST_CASE("Out of instructions", "[Limits]")
{
const auto program = build_and_load(R"M(
__asm__(".global lbl\t\n"
"lbl: j lbl\t\n");
extern "C" void lbl();
int main() {
lbl();
})M");
REQUIRE_THROWS(
[&] {
Script script {program, "MyScript", "/tmp/myscript"};
}());
}
TEST_CASE("Out of instructions VM calls", "[Limits]")
{
const auto program = build_and_load(R"M(
extern "C" void infinite_loop() {
infinite_loop();
}
int main() {
})M");
Script script {program, "MyScript", "/tmp/myscript"};
script.call("infinite_loop");
}
TEST_CASE("Recursive", "[Limits]")
{
const auto program = build_and_load(R"M(
#include <api.h>
using namespace api;
extern "C" void exit_caller() {
Game::exit();
}
int main() {
return 666;
})M");
bool exit_called = false;
Script::on_exit([&] (Script& script) {
script.call("exit_caller");
exit_called = true;
});
Script script {program, "MyScript", "/tmp/myscript"};
REQUIRE(!exit_called);
// This will recursively call exit_caller, but eventually throw an exception
script.call("exit_caller");
REQUIRE(exit_called);
}