Skip to content

Commit

Permalink
Fix missing start() which caused the WASM plugin to fail. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
jplevyak authored Mar 4, 2019
1 parent 6539ef9 commit bcb5fc4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ bool Context::isSsl() { return decoder_callbacks_->connection()->ssl() != nullpt
// Calls into the WASM code.
//
void Context::onStart() {
wasm_->wasmVm()->start(this);
if (wasm_->onStart_) {
wasm_->onStart_(this);
}
Expand Down Expand Up @@ -1032,6 +1031,8 @@ bool Wasm::initialize(const std::string& code, absl::string_view name, bool allo
auto ok = wasm_vm_->initialize(code, name, allow_precompiled);
if (!ok)
return false;
general_context_ = createContext();
wasm_vm_->start(general_context_.get());
code_ = code;
allow_precompiled_ = allow_precompiled;
getFunctions();
Expand Down Expand Up @@ -1255,6 +1256,7 @@ std::shared_ptr<Wasm> createThreadLocalWasm(Wasm& base_wasm, absl::string_view c
wasm->configure(base_wasm.initial_configuration());
}
wasm->configure(configuration);
wasm->start();
if (!wasm->id().empty())
local_wasms[wasm->id()] = wasm;
return wasm;
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/common/wasm/wavm/wavm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void getFunctionWavmReturn(WasmVm* vm, absl::string_view functionName,
throw WasmVmException(fmt::format("Bad function signature for: {}", functionName));
}
*function = [wavm, f](Context* context, Args... args) -> R {
UntaggedValue values[] = { args...};
UntaggedValue values[] = {args...};
CALL_WITH_CONTEXT_RETURN(invokeFunctionUnchecked(wavm->context(), f, &values[0]), context,
uint32_t, i32);
};
Expand All @@ -461,7 +461,7 @@ void getFunctionWavmReturn(WasmVm* vm, absl::string_view functionName,
throw WasmVmException(fmt::format("Bad function signature for: {}", functionName));
}
*function = [wavm, f](Context* context, Args... args) -> R {
UntaggedValue values[] = { args...};
UntaggedValue values[] = {args...};
CALL_WITH_CONTEXT(invokeFunctionUnchecked(wavm->context(), f, &values[0]), context);
};
}
Expand Down
1 change: 1 addition & 0 deletions source/extensions/wasm/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Server::WasmSharedPtr WasmFactory::createWasm(const envoy::config::wasm::v2::Was
context.dispatcher(), context.api());
if (config.singleton()) {
// Return the WASM VM which will be stored as a singleton by the Server.
base_wasm->start();
return base_wasm;
}
auto configuration = std::make_shared<std::string>(config.configuration());
Expand Down
7 changes: 4 additions & 3 deletions test/extensions/filters/http/wasm/wasm_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ class WasmHttpFilterTest : public testing::Test {
}

void setupFilter() {
wasm_->setGeneralContext(std::make_unique<TestFilter>(wasm_.get()));
filter_ = std::make_unique<TestFilter>(wasm_.get());
filter_ = std::make_shared<TestFilter>(wasm_.get());
wasm_->setGeneralContext(
std::static_pointer_cast<Envoy::Extensions::Common::Wasm::Context>(filter_));
}

NiceMock<ThreadLocal::MockInstance> tls_;
NiceMock<Event::MockDispatcher> dispatcher_;
Upstream::MockClusterManager cluster_manager_;
std::shared_ptr<Wasm> wasm_;
std::unique_ptr<TestFilter> filter_;
std::shared_ptr<TestFilter> filter_;
Http::MockStreamDecoderFilterCallbacks decoder_callbacks_;
Http::MockStreamEncoderFilterCallbacks encoder_callbacks_;
envoy::api::v2::core::Metadata metadata_;
Expand Down
2 changes: 1 addition & 1 deletion test/extensions/wasm/wasm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ TEST(WasmTest, DivByZero) {
wasm->setGeneralContext(std::move(context));
wasm->wasmVm()->start(wasm->generalContext());
EXPECT_THROW_WITH_REGEX(wasm->generalContext()->onLog(), Extensions::Common::Wasm::WasmException,
"wavm.integerDivideByZeroOrOverflow.*");
"wavm.integerDivideByZeroOrOverflow.*");
}

} // namespace Wasm
Expand Down

0 comments on commit bcb5fc4

Please sign in to comment.