MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / TEST

Function TEST

crates/c-api/tests/trap.cc:8–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace wasmtime;
7
8TEST(Trap, Smoke) {
9 Trap t("foo");
10 EXPECT_EQ(t.message(), "foo");
11 EXPECT_EQ(t.trace().size(), 0);
12
13 Engine engine;
14 Module m =
15 Module::compile(engine, "(module (func (export \"\") unreachable))")
16 .unwrap();
17 Store store(engine);
18 Instance i = Instance::create(store, m, {}).unwrap();
19 auto func = std::get<Func>(*i.get(store, ""));
20 auto trap = std::get<Trap>(func.call(store, {}).err().data);
21 auto trace = trap.trace();
22 EXPECT_EQ(trace.size(), 1);
23 auto frame = *trace.begin();
24 EXPECT_EQ(frame.func_name(), std::nullopt);
25 EXPECT_EQ(frame.module_name(), std::nullopt);
26 EXPECT_EQ(frame.func_index(), 0);
27 EXPECT_EQ(frame.func_offset(), 1);
28 EXPECT_EQ(frame.module_offset(), 29);
29 for (auto &frame : trace) {
30 }
31
32 auto unreachable_trap = std::get<Trap>(func.call(store, {}).err().data);
33
34 EXPECT_EQ(unreachable_trap.code(),
35 WASMTIME_TRAP_CODE_UNREACHABLE_CODE_REACHED);
36 EXPECT_TRUE(unreachable_trap.message().find("unreachable") !=
37 std::string::npos);
38 EXPECT_EQ(func.call(store, {1}).err().message(),
39 "expected 0 arguments, got 1");
40
41 Trap out_of_fuel(WASMTIME_TRAP_CODE_OUT_OF_FUEL);
42 EXPECT_EQ(out_of_fuel.code(), WASMTIME_TRAP_CODE_OUT_OF_FUEL);
43 EXPECT_TRUE(out_of_fuel.message().find("all fuel consumed") !=
44 std::string::npos);
45}
46
47TEST(Trap, Codes) {
48#define TEST_CODE(trapcode) \

Callers

nothing calls this directly

Calls 15

module_nameMethod · 0.80
compileFunction · 0.50
createFunction · 0.50
messageMethod · 0.45
sizeMethod · 0.45
traceMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
errMethod · 0.45
callMethod · 0.45
beginMethod · 0.45
func_nameMethod · 0.45

Tested by

no test coverage detected