Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Transition some benchmarks over to take advantage of envoy_cc_benchmark_binary and envoy_benchmark_test #10409

Merged
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
10 changes: 8 additions & 2 deletions test/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_benchmark_test",
"envoy_cc_benchmark_binary",
"envoy_cc_fuzz_test",
"envoy_cc_test",
"envoy_cc_test_binary",
"envoy_package",
)

Expand Down Expand Up @@ -209,7 +210,7 @@ envoy_cc_test(
deps = ["//source/common/common:callback_impl_lib"],
)

envoy_cc_test_binary(
envoy_cc_benchmark_binary(
name = "utility_speed_test",
srcs = ["utility_speed_test.cc"],
external_deps = [
Expand All @@ -222,6 +223,11 @@ envoy_cc_test_binary(
],
)

envoy_benchmark_test(
name = "utility_speed_test_benchmark_test",
benchmark_binary = "utility_speed_test",
)

envoy_cc_test(
name = "lock_guard_test",
srcs = ["lock_guard_test.cc"],
Expand Down
13 changes: 2 additions & 11 deletions test/common/common/utility_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ static void BM_IntervalSetInsert17(benchmark::State& state) {
interval_set.insert(3, 6);
interval_set.insert(3, 20);
interval_set.insert(3, 22);
interval_set.insert(-2, 23);
interval_set.insert(-3, 24);
interval_set.insert(23, 9223372036854775806UL);
interval_set.insert(24, 9223372036854775805UL);
Comment on lines +249 to +250
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being changed?

Copy link
Contributor Author

@antoniovicente antoniovicente Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #9540
size_t is an unsigned type. -2 ends up being interpreted as 9223372036854775806UL

interval set requires insert arguments to be sorted in value, so interval_set.insert(-2, 23), also known as interval_set.insert(9223372036854775806UL, 23) triggers an ASSERT failure in debug modes.

}
}
BENCHMARK(BM_IntervalSetInsert17);
Expand Down Expand Up @@ -275,12 +275,3 @@ static void BM_IntervalSet50ToVector(benchmark::State& state) {
}
BENCHMARK(BM_IntervalSet50ToVector);
} // namespace Envoy

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
17 changes: 14 additions & 3 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_benchmark_test",
"envoy_cc_benchmark_binary",
"envoy_cc_fuzz_test",
"envoy_cc_test",
"envoy_cc_test_binary",
"envoy_cc_test_library",
"envoy_package",
"envoy_proto_library",
Expand Down Expand Up @@ -106,7 +107,7 @@ envoy_cc_test(
],
)

envoy_cc_test_binary(
envoy_cc_benchmark_binary(
name = "codes_speed_test",
srcs = ["codes_speed_test.cc"],
external_deps = [
Expand All @@ -119,6 +120,11 @@ envoy_cc_test_binary(
],
)

envoy_benchmark_test(
name = "codes_speed_test_benchmark_test",
benchmark_binary = "codes_speed_test",
)

envoy_cc_test_library(
name = "common_lib",
srcs = ["common.cc"],
Expand Down Expand Up @@ -259,7 +265,7 @@ envoy_cc_test(
],
)

envoy_cc_test_binary(
envoy_cc_benchmark_binary(
name = "header_map_impl_speed_test",
srcs = ["header_map_impl_speed_test.cc"],
external_deps = [
Expand All @@ -270,6 +276,11 @@ envoy_cc_test_binary(
],
)

envoy_benchmark_test(
name = "header_map_impl_speed_test_benchmark_test",
benchmark_binary = "header_map_impl_speed_test",
)

envoy_proto_library(
name = "header_map_impl_fuzz_proto",
srcs = ["header_map_impl_fuzz.proto"],
Expand Down
10 changes: 0 additions & 10 deletions test/common/http/codes_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,3 @@ static void BM_ResponseTimingRealSymtab(benchmark::State& state) {
}
}
BENCHMARK(BM_ResponseTimingRealSymtab);

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
10 changes: 0 additions & 10 deletions test/common/http/header_map_impl_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,3 @@ BENCHMARK(HeaderMapImplPopulate);

} // namespace Http
} // namespace Envoy

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
9 changes: 8 additions & 1 deletion test/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_benchmark_test",
"envoy_cc_benchmark_binary",
"envoy_cc_test",
"envoy_cc_test_binary",
"envoy_cc_test_library",
Expand Down Expand Up @@ -42,7 +44,7 @@ envoy_cc_test(
],
)

envoy_cc_test_binary(
envoy_cc_benchmark_binary(
name = "address_impl_speed_test",
srcs = ["address_impl_speed_test.cc"],
external_deps = [
Expand All @@ -53,6 +55,11 @@ envoy_cc_test_binary(
],
)

envoy_benchmark_test(
name = "address_impl_speed_test_benchmark_test",
benchmark_binary = "address_impl_speed_test",
)

envoy_cc_test(
name = "cidr_range_test",
srcs = ["cidr_range_test.cc"],
Expand Down
10 changes: 0 additions & 10 deletions test/common/network/address_impl_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ BENCHMARK(Ipv6InstanceCreate);
} // namespace Address
} // namespace Network
} // namespace Envoy

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
20 changes: 19 additions & 1 deletion test/extensions/extensions_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//bazel:envoy_build_system.bzl", "envoy_cc_mock", "envoy_cc_test", "envoy_cc_test_binary", "envoy_cc_test_library")
load("//bazel:envoy_build_system.bzl", "envoy_benchmark_test", "envoy_cc_benchmark_binary", "envoy_cc_mock", "envoy_cc_test", "envoy_cc_test_binary", "envoy_cc_test_library")
load("@envoy_build_config//:extensions_build_config.bzl", "EXTENSIONS")

# All extension tests should use this version of envoy_cc_test(). It allows compiling out
Expand Down Expand Up @@ -39,3 +39,21 @@ def envoy_extension_cc_test_binary(
return

envoy_cc_test_binary(name, **kwargs)

def envoy_extension_cc_benchmark_binary(
name,
extension_name,
**kwargs):
if not extension_name in EXTENSIONS:
return

envoy_cc_benchmark_binary(name, **kwargs)

def envoy_extension_benchmark_test(
name,
extension_name,
**kwargs):
if not extension_name in EXTENSIONS:
return

envoy_benchmark_test(name, **kwargs)
15 changes: 13 additions & 2 deletions test/extensions/filters/listener/tls_inspector/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_cc_test",
"envoy_cc_test_binary",
"envoy_package",
)
load(
"//test/extensions:extensions_build_system.bzl",
"envoy_extension_benchmark_test",
"envoy_extension_cc_benchmark_binary",
)

envoy_package()

Expand All @@ -24,9 +28,10 @@ envoy_cc_test(
],
)

envoy_cc_test_binary(
envoy_extension_cc_benchmark_binary(
name = "tls_inspector_benchmark",
srcs = ["tls_inspector_benchmark.cc"],
extension_name = "envoy.filters.listener.tls_inspector",
external_deps = [
"benchmark",
],
Expand All @@ -41,6 +46,12 @@ envoy_cc_test_binary(
],
)

envoy_extension_benchmark_test(
name = "tls_inspector_benchmark_test",
benchmark_binary = "tls_inspector_benchmark",
extension_name = "envoy.filters.listener.tls_inspector",
)

envoy_cc_library(
name = "tls_utility_lib",
srcs = ["tls_utility.cc"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void BM_TlsInspector(benchmark::State& state) {
for (auto _ : state) {
Filter filter(cfg);
filter.onAccept(cb);
dispatcher.file_event_callback_(Event::FileReadyType::Read);
RELEASE_ASSERT(dispatcher.file_event_callback_ == nullptr, "");
RELEASE_ASSERT(socket.detectedTransportProtocol() == "tls", "");
RELEASE_ASSERT(socket.requestedServerName() == "example.com", "");
RELEASE_ASSERT(socket.requestedApplicationProtocols().size() == 2 &&
Expand All @@ -99,16 +99,3 @@ BENCHMARK(BM_TlsInspector)->Unit(benchmark::kMicrosecond);
} // namespace ListenerFilters
} // namespace Extensions
} // namespace Envoy

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
Envoy::Thread::MutexBasicLockable lock;
Envoy::Logger::Context logging_context(spdlog::level::warn,
Envoy::Logger::Logger::DEFAULT_LOG_FORMAT, lock, false);

benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
19 changes: 16 additions & 3 deletions test/extensions/filters/network/redis_proxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ load(
)
load(
"//test/extensions:extensions_build_system.bzl",
"envoy_extension_benchmark_test",
"envoy_extension_cc_benchmark_binary",
"envoy_extension_cc_test",
"envoy_extension_cc_test_binary",
)

envoy_package()
Expand Down Expand Up @@ -102,7 +103,7 @@ envoy_extension_cc_test(
],
)

envoy_extension_cc_test_binary(
envoy_extension_cc_benchmark_binary(
name = "command_lookup_speed_test",
srcs = ["command_lookup_speed_test.cc"],
extension_name = "envoy.filters.network.redis_proxy",
Expand All @@ -119,6 +120,12 @@ envoy_extension_cc_test_binary(
],
)

envoy_extension_benchmark_test(
name = "command_lookup_speed_test_benchmark_test",
benchmark_binary = "command_lookup_speed_test",
extension_name = "envoy.filters.network.redis_proxy",
)

envoy_extension_cc_test(
name = "router_impl_test",
srcs = ["router_impl_test.cc"],
Expand All @@ -144,7 +151,7 @@ envoy_extension_cc_test(
],
)

envoy_extension_cc_test_binary(
envoy_extension_cc_benchmark_binary(
name = "command_split_speed_test",
srcs = ["command_split_speed_test.cc"],
extension_name = "envoy.filters.network.redis_proxy",
Expand All @@ -161,3 +168,9 @@ envoy_extension_cc_test_binary(
"//test/test_common:simulated_time_system_lib",
],
)

envoy_extension_benchmark_test(
name = "command_split_speed_test_benchmark_test",
benchmark_binary = "command_split_speed_test",
extension_name = "envoy.filters.network.redis_proxy",
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,3 @@ static void BM_MakeRequests(benchmark::State& state) {
}
}
BENCHMARK(BM_MakeRequests);

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CommandSplitSpeedTest {
void createShared(Common::Redis::RespValueSharedPtr request) {
for (uint64_t i = 1; i < request->asArray().size(); i += 2) {
auto single_set = std::make_shared<const Common::Redis::RespValue>(
request, Common::Redis::Utility::SetRequest::instance(), i, i + 2);
request, Common::Redis::Utility::SetRequest::instance(), i, i + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

@antoniovicente antoniovicente Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #9541
This + 2 causes array out of bound access, see stack trace below.
createVariant and createLocalCompositeArray benchmarks also in this file have very similar code but use i+1 instead of i+2. I think this was an existing error in the benchmark which lay dormant since there were no tests for it.

[2020-03-17 02:43:10.078][15][critical][assert] [bazel-out/k8-fastbuild/bin/source/extensions/filters/network/common/redis/virtual_includes/codec_interface/extensions/filters/network/common/redis/codec.h:67] assert failure: end < base_array->asArray().size().
AddressSanitizer:DEADLYSIGNAL

ERROR: AddressSanitizer: ABRT on unknown address 0x14e380000000f (pc 0x7f840d1d0081 bp 0x7ffe76012050 sp 0x7ffe76011910 T0)
#0 0x7f840d1d0080 in __libc_signal_restore_set /build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/internal-signals.h:84 (discriminator 3)
#1 0x7f840d1d0080 in __GI_raise /build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:48 (discriminator 3)
#2 0x7f840d1bb534 in __GI_abort /build/glibc-G5rUEF/glibc-2.29/stdlib/abort.c:79 (discriminator 6)
#3 0x5696cc2 in Envoy::Extensions::NetworkFilters::Common::Redis::RespValue::CompositeArray::CompositeArray(std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue, Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const&, unsigned long, unsigned long) ??:?
#4 0x5695334 in Envoy::Extensions::NetworkFilters::Common::Redis::RespValue::RespValue(std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue, Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const&, unsigned long, unsigned long) ??:?
#5 0x573ba54 in std::__1::__compressed_pair_elem<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const, 1, false>::__compressed_pair_elem<std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&, 0ul, 1ul, 2ul, 3ul>(std::__1::piecewise_construct_t, std::__1::tuple<std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&>, std::__1::__tuple_indices<0ul, 1ul, 2ul, 3ul>) ??:?
#6 0x5739f4d in std::__1::__compressed_pair<std::__1::allocator<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>, Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>::__compressed_pair<std::__1::allocator<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>&, std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&>(std::__1::piecewise_construct_t, std::__1::tuple<std::__1::allocator<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>&>, std::__1::tuple<std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&>) ??:?
#7 0x5738b73 in std::__1::__shared_ptr_emplace<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const, std::__1::allocator<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const> >::__shared_ptr_emplace<std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long>(std::__1::allocator<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>, std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&) ??:?
#8 0x5737abc in std::__1::shared_ptr<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const> std::__1::shared_ptr<Envoy::Extensions::NetworkFilters::Common::Redis::RespValue const>::make_shared<std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long>(std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue&, Envoy::Extensions::NetworkFilters::Common::Redis::Utility::SetRequest const&, unsigned long&, unsigned long&&) ??:?
#9 0x573748b in ZNSt3__111make_sharedIKN5Envoy10Extensions14NetworkFilters6Common5Redis9RespValueEJRNS_10shared_ptrIS6_EERKNS5_7Utility10SetRequestERmmEEENS_9enable_ifIXntsr8is_arrayIT_EE5valueENS8_ISH_EEE4typeEDpOT0 command_split_speed_test.cc:?
#10 0x5736b35 in Envoy::Extensions::NetworkFilters::RedisProxy::CommandSplitSpeedTest::createShared(std::__1::shared_ptrEnvoy::Extensions::NetworkFilters::Common::Redis::RespValue) ??:?
#11 0x5684672 in BM_Split_CreateShared(benchmark::State&) command_split_speed_test.cc:?
#12 0xc3a56f1 in benchmark::internal::FunctionBenchmark::Run(benchmark::State&) ??:?
#13 0xc409255 in benchmark::internal::BenchmarkInstance::Run(unsigned long, int, benchmark::internal::ThreadTimer*, benchmark::internal::ThreadManager*) const ??:?
#14 0xc3dd535 in benchmark::internal::(anonymous namespace)::RunInThread(benchmark::internal::BenchmarkInstance const*, unsigned long, int, benchmark::internal::ThreadManager*) benchmark_runner.cc:?
#15 0xc3da56e in benchmark::internal::(anonymous namespace)::BenchmarkRunner::DoNIterations() benchmark_runner.cc:?
#16 0xc3d8900 in benchmark::internal::(anonymous namespace)::BenchmarkRunner::DoOneRepetition(long) benchmark_runner.cc:?
#17 0xc3d7bba in benchmark::internal::(anonymous namespace)::BenchmarkRunner::BenchmarkRunner(benchmark::internal::BenchmarkInstance const&, std::__1::vector<benchmark::BenchmarkReporter::Run, std::__1::allocatorbenchmark::BenchmarkReporter::Run >) benchmark_runner.cc:?
#18 0xc3d6568 in benchmark::internal::RunBenchmark(benchmark::internal::BenchmarkInstance const&, std::__1::vector<benchmark::BenchmarkReporter::Run, std::__1::allocatorbenchmark::BenchmarkReporter::Run >
) ??:?
#19 0xc381a17 in benchmark::internal::(anonymous namespace)::RunBenchmarks(std::__1::vector<benchmark::internal::BenchmarkInstance, std::__1::allocatorbenchmark::internal::BenchmarkInstance > const&, benchmark::BenchmarkReporter*, benchmark::BenchmarkReporter*) benchmark.cc:?
#20 0xc37fd94 in benchmark::RunSpecifiedBenchmarks(benchmark::BenchmarkReporter*, benchmark::BenchmarkReporter*) ??:?
#21 0xc37ee42 in benchmark::RunSpecifiedBenchmarks() ??:?
#22 0xbf76923 in main ??:?
#23 0x7f840d1bcbba in __libc_start_main /build/glibc-G5rUEF/glibc-2.29/csu/../csu/libc-start.c:308
#24 0x55da029 in _start ??:?

AddressSanitizer can not provide additional info.

}
}

Expand Down Expand Up @@ -130,13 +130,3 @@ static void BM_Split_CreateVariant(benchmark::State& state) {
state.counters["use_count"] = request.use_count();
}
BENCHMARK(BM_Split_CreateVariant)->Ranges({{1, 100}, {64, 8 << 14}});

// Boilerplate main(), which discovers benchmarks in the same file and runs them.
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);

if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}