Skip to content

Commit

Permalink
test: convert test for a missing import from WAT to WASM format. (env…
Browse files Browse the repository at this point in the history
…oyproxy#59)

This is needed, since not all runtimes support WAT format.

Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored Apr 22, 2019
1 parent ea56a23 commit a7687ea
Show file tree
Hide file tree
Showing 5 changed files with 7,251 additions and 22 deletions.
26 changes: 5 additions & 21 deletions test/extensions/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,9 @@ TEST(WasmFactoryTest, MissingImport) {
ASSERT_NE(factory, nullptr);
envoy::config::wasm::v2::WasmConfig config;
config.mutable_vm_config()->set_vm("envoy.wasm.vm.wavm");
config.mutable_vm_config()->mutable_code()->set_inline_string(
"(module\n"
" (type $0 (func (param i32 i32 i32)))\n"
" (type $1 (func))\n"
" (import \"env\" \"missing\" (func $missing (param i32 i32 i32)))\n"
" (export \"memory\" (memory $2))\n"
" (export \"main\" (func $main))\n"
" (memory $2 17)\n"
" (data $2 (i32.const 1048576) \"Hello, world!\")\n"
""
" (func $main (type $1)\n"
" i32.const 1\n"
" i32.const 1048576\n"
" i32.const 13\n"
" call $missing\n"
" )\n"
" )");
config.mutable_vm_config()->mutable_code()->set_filename(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/wasm/test_data/missing_cpp.wasm"));
config.set_singleton(true);

Upstream::MockClusterManager cluster_manager;
Event::MockDispatcher dispatcher;
ThreadLocal::MockInstance tls;
Expand All @@ -117,9 +101,9 @@ TEST(WasmFactoryTest, MissingImport) {
Server::Configuration::WasmFactoryContextImpl context(cluster_manager, dispatcher, tls, *api,
scope);
Server::WasmSharedPtr wasm;
EXPECT_THROW_WITH_MESSAGE(
wasm = factory->createWasm(config, context), Extensions::Common::Wasm::WasmException,
"Failed to load WASM module due to a missing import: env.missing func (i32, i32, i32)->()");
EXPECT_THROW_WITH_REGEX(wasm = factory->createWasm(config, context),
Extensions::Common::Wasm::WasmException,
"Failed to load WASM module due to a missing import: env._missing.*");
}

} // namespace Wasm
Expand Down
9 changes: 8 additions & 1 deletion test/extensions/wasm/test_data/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
NO_CONTEXT = true

all: logging_cpp.wasm logging_rust.wasm bad_signature_cpp.wasm segv_cpp.wasm emscripten_cpp.wasm asm2wasm_cpp.wasm stats_cpp.wasm
all: logging_cpp.wasm logging_rust.wasm bad_signature_cpp.wasm segv_cpp.wasm emscripten_cpp.wasm asm2wasm_cpp.wasm stats_cpp.wasm missing_cpp.wasm

include ../../../../api/wasm/cpp/Makefile.base_lite
include ../../../../api/wasm/rust/Makefile.base

missing_cpp.wasm missing_cpp.wat: missing_cpp.cc ${CPP_API}/proxy_wasm_intrinsics.h ${CPP_API}/proxy_wasm_intrinsics.js
em++ -s WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s LEGALIZE_JS_FFI=0 -s EMIT_EMSCRIPTEN_METADATA=1 --std=c++17 -O3 -g3 -DEMSCRIPTEN_PROTOBUF_LITE=1 -I${CPP_API} -I${CPP_API}/google/protobuf -I/usr/local/include --js-library ${CPP_API}/proxy_wasm_intrinsics.js missing_cpp.cc ${CPP_API}/proxy_wasm_intrinsics_lite.pb.cc ${CPP_API}/struct_lite.pb.cc ${CPP_CONTEXT_LIB} ${CPP_API}/libprotobuf-lite.bc -o missing_cpp.js
wavm-disas missing_cpp.wasm missing_cpp.wat
wavm-compile missing_cpp.wasm missing_cpp.wasm
rm -f missing_cpp.js missing_cpp.wast
chmod 644 missing_cpp.wat
6 changes: 6 additions & 0 deletions test/extensions/wasm/test_data/missing_cpp.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// NOLINT(namespace-envoy)
#include "proxy_wasm_intrinsics.h"

extern "C" void missing();

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onStart() { missing(); }
Binary file added test/extensions/wasm/test_data/missing_cpp.wasm
Binary file not shown.
Loading

0 comments on commit a7687ea

Please sign in to comment.