Skip to content

Commit edbe96f

Browse files
committed
Add the test case for the canary failure
Signed-off-by: Ingwon Song <igsong@google.com>
1 parent d3f7de2 commit edbe96f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

test/test_data/configure_check.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class TestRootContext1 : public RootContext {
2323
explicit TestRootContext1(uint32_t id, std::string_view root_id) : RootContext(id, root_id) {}
2424
bool onConfigure(size_t s) override {
2525
LOG_TRACE("onConfigure: root_id_1");
26+
if (s == 0) {
27+
return false;
28+
}
2629
return true;
2730
}
2831
};
@@ -37,6 +40,9 @@ class TestRootContext2 : public RootContext {
3740
explicit TestRootContext2(uint32_t id, std::string_view root_id) : RootContext(id, root_id) {}
3841
bool onConfigure(size_t s) override {
3942
LOG_TRACE("onConfigure: root_id_2");
43+
if (s == 0) {
44+
return false;
45+
}
4046
return true;
4147
}
4248
};

test/wasm_test.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ TEST_P(TestVm, AlwaysApplyCanary) {
125125
const std::string root_ids[2] = {"root_id_1", "root_id_2"};
126126
const std::string vm_ids[2] = {"vm_id_1", "vm_id_2"};
127127
const std::string vm_configs[2] = {"vm_config_1", "vm_config_2"};
128-
const std::string plugin_configs[2] = {"plugin_config_1", "plugin_config_2"};
128+
const std::string plugin_configs[3] = {"plugin_config_1", "plugin_config_2",
129+
/* raising the error */ ""};
129130
const std::string plugin_keys[2] = {"plugin_key_1", "plugin_key_2"};
130131
const auto fail_open = false;
131132

@@ -182,8 +183,8 @@ TEST_P(TestVm, AlwaysApplyCanary) {
182183
for (const auto &root_id : root_ids) {
183184
for (const auto &vm_id : vm_ids) {
184185
for (const auto &vm_config : vm_configs) {
185-
for (const auto &plugin_config : plugin_configs) {
186-
for (const auto &plugin_key : plugin_keys) {
186+
for (const auto &plugin_key : plugin_keys) {
187+
for (const auto &plugin_config : plugin_configs) {
187188
canary_count = 0;
188189
TestContext::resetGlobalLog();
189190
WasmHandleFactory wasm_handle_factory_comp =
@@ -199,6 +200,14 @@ TEST_P(TestVm, AlwaysApplyCanary) {
199200
auto wasm_handle_comp =
200201
createWasm(vm_key, source, plugin_comp, wasm_handle_factory_comp,
201202
wasm_handle_clone_factory_for_canary, false);
203+
204+
if (plugin_config.empty()) {
205+
// configure_check.wasm should raise the error at `onConfigure` in canary when the
206+
// `plugin_config` is empty string.
207+
EXPECT_EQ(wasm_handle_comp, nullptr);
208+
return;
209+
}
210+
202211
ASSERT_TRUE(wasm_handle_comp && wasm_handle_comp->wasm());
203212

204213
EXPECT_TRUE(TestContext::isGlobalLogged("onConfigure: " + root_id));

0 commit comments

Comments
 (0)