Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions test/extensions/access_loggers/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class TestFactoryContext : public NiceMock<Server::Configuration::MockServerFact
Stats::Scope& scope_;
};

class WasmAccessLogConfigTest : public testing::TestWithParam<std::string> {};
class WasmAccessLogConfigTest
: public testing::TestWithParam<std::tuple<std::string, std::string>> {};

INSTANTIATE_TEST_SUITE_P(Runtimes, WasmAccessLogConfigTest,
Envoy::Extensions::Common::Wasm::runtime_values);
Envoy::Extensions::Common::Wasm::runtime_and_cpp_values,
Envoy::Extensions::Common::Wasm::wasmTestParamsToString);

TEST_P(WasmAccessLogConfigTest, CreateWasmFromEmpty) {
auto factory =
Expand All @@ -56,22 +58,16 @@ TEST_P(WasmAccessLogConfigTest, CreateWasmFromEmpty) {
}

TEST_P(WasmAccessLogConfigTest, CreateWasmFromWASM) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
auto factory =
Registry::FactoryRegistry<Server::Configuration::AccessLogInstanceFactory>::getFactory(
"envoy.access_loggers.wasm");
ASSERT_NE(factory, nullptr);

envoy::extensions::access_loggers::wasm::v3::WasmAccessLog config;
config.mutable_config()->mutable_vm_config()->set_runtime(
absl::StrCat("envoy.wasm.runtime.", GetParam()));
absl::StrCat("envoy.wasm.runtime.", std::get<0>(GetParam())));
std::string code;
if (GetParam() != "null") {
if (std::get<0>(GetParam()) != "null") {
code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/access_loggers/wasm/test_data/test_cpp.wasm"));
} else {
Expand Down
59 changes: 6 additions & 53 deletions test/extensions/bootstrap/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace Wasm {

using Extensions::Bootstrap::Wasm::WasmServicePtr;

class WasmFactoryTest : public testing::TestWithParam<std::string> {
class WasmFactoryTest : public testing::TestWithParam<std::tuple<std::string, std::string>> {
protected:
WasmFactoryTest() {
config_.mutable_config()->mutable_vm_config()->set_runtime(
absl::StrCat("envoy.wasm.runtime.", GetParam()));
if (GetParam() != "null") {
absl::StrCat("envoy.wasm.runtime.", std::get<0>(GetParam())));
if (std::get<0>(GetParam()) != "null") {
config_.mutable_config()->mutable_vm_config()->mutable_code()->mutable_local()->set_filename(
TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/start_cpp.wasm"));
Expand Down Expand Up @@ -69,15 +69,10 @@ class WasmFactoryTest : public testing::TestWithParam<std::string> {
};

INSTANTIATE_TEST_SUITE_P(Runtimes, WasmFactoryTest,
Envoy::Extensions::Common::Wasm::runtime_values);
Envoy::Extensions::Common::Wasm::runtime_and_cpp_values,
Envoy::Extensions::Common::Wasm::wasmTestParamsToString);

TEST_P(WasmFactoryTest, CreateWasmFromWasm) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
auto factory = std::make_unique<Bootstrap::Wasm::WasmFactory>();
auto empty_config = factory->createEmptyConfigProto();

Expand All @@ -90,12 +85,6 @@ TEST_P(WasmFactoryTest, CreateWasmFromWasm) {
}

TEST_P(WasmFactoryTest, CreateWasmFromWasmPerThread) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
config_.set_singleton(false);
initializeWithConfig(config_);

Expand All @@ -105,13 +94,7 @@ TEST_P(WasmFactoryTest, CreateWasmFromWasmPerThread) {
}

TEST_P(WasmFactoryTest, MissingImport) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
if (GetParam() == "null") {
if (std::get<0>(GetParam()) == "null") {
return;
}
config_.mutable_config()->mutable_vm_config()->mutable_code()->mutable_local()->set_filename(
Expand All @@ -122,12 +105,6 @@ TEST_P(WasmFactoryTest, MissingImport) {
}

TEST_P(WasmFactoryTest, UnspecifiedRuntime) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
config_.mutable_config()->mutable_vm_config()->set_runtime("");

EXPECT_THROW_WITH_REGEX(
Expand All @@ -136,25 +113,13 @@ TEST_P(WasmFactoryTest, UnspecifiedRuntime) {
}

TEST_P(WasmFactoryTest, UnknownRuntime) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
config_.mutable_config()->mutable_vm_config()->set_runtime("envoy.wasm.runtime.invalid");

EXPECT_THROW_WITH_MESSAGE(initializeWithConfig(config_), Extensions::Common::Wasm::WasmException,
"Unable to create Wasm service test");
}

TEST_P(WasmFactoryTest, StartFailed) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
ProtobufWkt::StringValue plugin_configuration;
plugin_configuration.set_value("bad");
config_.mutable_config()->mutable_vm_config()->mutable_configuration()->PackFrom(
Expand All @@ -165,12 +130,6 @@ TEST_P(WasmFactoryTest, StartFailed) {
}

TEST_P(WasmFactoryTest, StartFailedOpen) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
ProtobufWkt::StringValue plugin_configuration;
plugin_configuration.set_value("bad");
config_.mutable_config()->mutable_vm_config()->mutable_configuration()->PackFrom(
Expand All @@ -182,12 +141,6 @@ TEST_P(WasmFactoryTest, StartFailedOpen) {
}

TEST_P(WasmFactoryTest, ConfigureFailed) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
ProtobufWkt::StringValue plugin_configuration;
plugin_configuration.set_value("bad");
config_.mutable_config()->mutable_configuration()->PackFrom(plugin_configuration);
Expand Down
13 changes: 4 additions & 9 deletions test/extensions/bootstrap/wasm/wasm_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Extensions {
namespace Wasm {
namespace {

class WasmIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam<std::string> {
class WasmIntegrationTest : public HttpIntegrationTest,
public testing::TestWithParam<std::tuple<std::string, std::string>> {
public:
WasmIntegrationTest()
: HttpIntegrationTest(Http::CodecType::HTTP1, Network::Address::IpVersion::v4) {}
Expand Down Expand Up @@ -58,7 +59,7 @@ name: envoy.filters.http.wasm
local:
filename: {}
)EOF",
GetParam(), httpwasm));
std::get<0>(GetParam()), httpwasm));
HttpIntegrationTest::initialize();
}

Expand All @@ -68,17 +69,11 @@ name: envoy.filters.http.wasm
};

INSTANTIATE_TEST_SUITE_P(Runtimes, WasmIntegrationTest,
Envoy::Extensions::Common::Wasm::sandbox_runtime_values,
Envoy::Extensions::Common::Wasm::sandbox_runtime_and_cpp_values,
Envoy::Extensions::Common::Wasm::wasmTestParamsToString);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WasmIntegrationTest);

TEST_P(WasmIntegrationTest, FilterMakesCallInConfigureTime) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
initialize();
ASSERT_TRUE(fake_upstreams_.back()->waitForHttpConnection(*dispatcher_, wasm_connection_));

Expand Down
69 changes: 12 additions & 57 deletions test/extensions/bootstrap/wasm/wasm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,24 @@ class WasmTestBase {
std::shared_ptr<Extensions::Common::Wasm::Wasm> wasm_;
};

class WasmTest : public WasmTestBase, public testing::TestWithParam<std::string> {
class WasmTest : public WasmTestBase,
public testing::TestWithParam<std::tuple<std::string, std::string>> {
public:
void createWasm() { WasmTestBase::createWasm(GetParam()); }
void createWasm() { WasmTestBase::createWasm(std::get<0>(GetParam())); }
};

INSTANTIATE_TEST_SUITE_P(Runtimes, WasmTest,
Envoy::Extensions::Common::Wasm::sandbox_runtime_values);
Envoy::Extensions::Common::Wasm::sandbox_runtime_and_cpp_values,
Envoy::Extensions::Common::Wasm::wasmTestParamsToString);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WasmTest);

class WasmNullTest : public WasmTestBase, public testing::TestWithParam<std::string> {
class WasmNullTest : public WasmTestBase,
public testing::TestWithParam<std::tuple<std::string, std::string>> {
public:
void createWasm() {
WasmTestBase::createWasm(GetParam());
WasmTestBase::createWasm(std::get<0>(GetParam()));
const auto code =
GetParam() != "null"
std::get<0>(GetParam()) != "null"
? TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/stats_cpp.wasm"))
: "WasmStatsCpp";
Expand All @@ -109,7 +112,8 @@ class WasmNullTest : public WasmTestBase, public testing::TestWithParam<std::str
}
};

INSTANTIATE_TEST_SUITE_P(Runtimes, WasmNullTest, Envoy::Extensions::Common::Wasm::runtime_values);
INSTANTIATE_TEST_SUITE_P(Runtimes, WasmNullTest,
Envoy::Extensions::Common::Wasm::runtime_and_cpp_values);

class WasmTestMatrix : public WasmTestBase,
public testing::TestWithParam<std::tuple<std::string, std::string>> {
Expand All @@ -130,8 +134,7 @@ class WasmTestMatrix : public WasmTestBase,
};

INSTANTIATE_TEST_SUITE_P(RuntimesAndLanguages, WasmTestMatrix,
testing::Combine(Envoy::Extensions::Common::Wasm::sandbox_runtime_values,
Envoy::Extensions::Common::Wasm::language_values));
Envoy::Extensions::Common::Wasm::sandbox_runtime_and_language_values);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WasmTestMatrix);

TEST_P(WasmTestMatrix, LoggingWithEnvVars) {
Expand Down Expand Up @@ -170,12 +173,6 @@ TEST_P(WasmTestMatrix, LoggingWithEnvVars) {
}

TEST_P(WasmTest, BadSignature) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/bad_signature_cpp.wasm"));
Expand All @@ -186,12 +183,6 @@ TEST_P(WasmTest, BadSignature) {
}

TEST_P(WasmTest, Segv) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/segv_cpp.wasm"));
Expand All @@ -205,12 +196,6 @@ TEST_P(WasmTest, Segv) {
}

TEST_P(WasmTest, DivByZero) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/segv_cpp.wasm"));
Expand All @@ -224,12 +209,6 @@ TEST_P(WasmTest, DivByZero) {
}

TEST_P(WasmTest, IntrinsicGlobals) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/emscripten_cpp.wasm"));
Expand All @@ -249,12 +228,6 @@ TEST_P(WasmTest, IntrinsicGlobals) {
// change this behavior by providing non-trapping instructions, but in the mean time we support the
// default Emscripten behavior.
TEST_P(WasmTest, Asm2Wasm) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute(
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/asm2wasm_cpp.wasm"));
Expand All @@ -267,12 +240,6 @@ TEST_P(WasmTest, Asm2Wasm) {
}

TEST_P(WasmNullTest, Stats) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
auto context = static_cast<TestContext*>(wasm_->start(plugin_));

Expand All @@ -292,12 +259,6 @@ TEST_P(WasmNullTest, Stats) {
}

TEST_P(WasmNullTest, StatsHigherLevel) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
auto context = static_cast<TestContext*>(wasm_->start(plugin_));

Expand All @@ -323,12 +284,6 @@ TEST_P(WasmNullTest, StatsHigherLevel) {
}

TEST_P(WasmNullTest, StatsHighLevel) {
#if !defined(__x86_64__)
// TODO(PiotrSikora): Emscripten ships binaries only for x86_64.
if (GetParam() != "null") {
return;
}
#endif
createWasm();
auto context = static_cast<TestContext*>(wasm_->start(plugin_));

Expand Down
Loading