diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 9870202f4bf28..cecdc3b0654a7 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -448,6 +448,7 @@ def envoy_cc_test( deps = [], tags = [], args = [], + copts = [], shard_count = None, coverage = True, local = False, @@ -463,10 +464,11 @@ def envoy_cc_test( deps = deps, repository = repository, tags = test_lib_tags, + copts = copts, ) native.cc_test( name = name, - copts = envoy_copts(repository, test = True), + copts = envoy_copts(repository, test = True) + copts, linkopts = envoy_test_linkopts(), linkstatic = envoy_linkstatic(), malloc = tcmalloc_external_dep(repository), @@ -494,13 +496,14 @@ def envoy_cc_test_infrastructure_library( deps = [], repository = "", tags = [], - include_prefix = None): + include_prefix = None, + copts = []): native.cc_library( name = name, srcs = srcs, hdrs = hdrs, data = data, - copts = envoy_copts(repository, test = True), + copts = envoy_copts(repository, test = True) + copts, testonly = 1, deps = deps + [envoy_external_dep_path(dep) for dep in external_deps] + [ envoy_external_dep_path("googletest"), @@ -523,7 +526,8 @@ def envoy_cc_test_library( deps = [], repository = "", tags = [], - include_prefix = None): + include_prefix = None, + copts = []): deps = deps + [ repository + "//test/test_common:printers_includes", ] @@ -537,6 +541,7 @@ def envoy_cc_test_library( repository, tags, include_prefix, + copts, ) # Envoy test binaries should be specified with this function. diff --git a/bazel/external/quiche.BUILD b/bazel/external/quiche.BUILD index aa9461abf1a3b..c6ff2682670aa 100644 --- a/bazel/external/quiche.BUILD +++ b/bazel/external/quiche.BUILD @@ -28,7 +28,9 @@ licenses(["notice"]) # Apache 2 load(":genrule_cmd.bzl", "genrule_cmd") load( "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_library", "envoy_cc_test", + "envoy_cc_test_library", "envoy_select_quiche", ) @@ -48,7 +50,9 @@ genrule( visibility = ["//visibility:private"], ) -cc_library( +quiche_copt = ["-Wno-unused-parameter"] + +envoy_cc_library( name = "http2_platform", hdrs = [ "quiche/http2/platform/api/http2_arraysize.h", @@ -73,11 +77,12 @@ cc_library( ], "@envoy", ), + repository = "@envoy", visibility = ["//visibility:public"], deps = ["@envoy//source/extensions/quic_listeners/quiche/platform:http2_platform_impl_lib"], ) -cc_library( +envoy_cc_library( name = "spdy_platform", hdrs = [ "quiche/spdy/platform/api/spdy_arraysize.h", @@ -99,26 +104,29 @@ cc_library( ], "@envoy", ), + repository = "@envoy", visibility = ["//visibility:public"], deps = ["@envoy//source/extensions/quic_listeners/quiche/platform:spdy_platform_impl_lib"], ) -cc_library( +envoy_cc_library( name = "spdy_simple_arena_lib", srcs = ["quiche/spdy/core/spdy_simple_arena.cc"], hdrs = ["quiche/spdy/core/spdy_simple_arena.h"], + repository = "@envoy", visibility = ["//visibility:public"], deps = [":spdy_platform"], ) -cc_library( +envoy_cc_library( name = "spdy_platform_unsafe_arena_lib", hdrs = ["quiche/spdy/platform/api/spdy_unsafe_arena.h"], + repository = "@envoy", visibility = ["//visibility:public"], deps = ["@envoy//source/extensions/quic_listeners/quiche/platform:spdy_platform_unsafe_arena_impl_lib"], ) -cc_library( +envoy_cc_library( name = "quic_platform", srcs = ["quiche/quic/platform/api/quic_mutex.cc"] + envoy_select_quiche( [ @@ -138,6 +146,7 @@ cc_library( ], "@envoy", ), + repository = "@envoy", visibility = ["//visibility:public"], deps = [ ":quic_platform_base", @@ -145,62 +154,57 @@ cc_library( ], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_expect_bug", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_expect_bug.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_expect_bug_impl_lib"], ) -cc_library( +envoy_cc_library( name = "quic_platform_export", hdrs = ["quiche/quic/platform/api/quic_export.h"], + repository = "@envoy", visibility = ["//visibility:public"], deps = ["@envoy//source/extensions/quic_listeners/quiche/platform:quic_platform_export_impl_lib"], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_mock_log", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_mock_log.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_mock_log_impl_lib"], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_port_utils", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_port_utils.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_port_utils_impl_lib"], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_test", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_test.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_test_impl_lib"], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_test_output", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_test_output.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_test_output_impl_lib"], ) -cc_library( +envoy_cc_test_library( name = "quic_platform_thread", - testonly = 1, hdrs = ["quiche/quic/platform/api/quic_thread.h"], - visibility = ["//visibility:public"], + repository = "@envoy", deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:quic_platform_thread_impl_lib"], ) -cc_library( +envoy_cc_library( name = "quic_platform_base", hdrs = [ "quiche/quic/platform/api/quic_aligned.h", @@ -246,6 +250,7 @@ cc_library( ], "@envoy", ), + repository = "@envoy", visibility = ["//visibility:public"], deps = [ ":quic_platform_export", @@ -253,22 +258,24 @@ cc_library( ], ) -cc_library( +envoy_cc_library( name = "quic_platform_sleep", hdrs = ["quiche/quic/platform/api/quic_sleep.h"], + repository = "@envoy", visibility = ["//visibility:public"], deps = ["@envoy//source/extensions/quic_listeners/quiche/platform:quic_platform_sleep_impl_lib"], ) -cc_library( +envoy_cc_library( name = "quic_time_lib", srcs = ["quiche/quic/core/quic_time.cc"], hdrs = ["quiche/quic/core/quic_time.h"], + repository = "@envoy", visibility = ["//visibility:public"], deps = [":quic_platform"], ) -cc_library( +envoy_cc_library( name = "quic_buffer_allocator_lib", srcs = [ "quiche/quic/core/quic_buffer_allocator.cc", @@ -278,10 +285,51 @@ cc_library( "quiche/quic/core/quic_buffer_allocator.h", "quiche/quic/core/quic_simple_buffer_allocator.h", ], + repository = "@envoy", visibility = ["//visibility:public"], deps = [":quic_platform_export"], ) +envoy_cc_test_library( + name = "epoll_server_platform", + hdrs = [ + "quiche/epoll_server/platform/api/epoll_address_test_utils.h", + "quiche/epoll_server/platform/api/epoll_bug.h", + "quiche/epoll_server/platform/api/epoll_expect_bug.h", + "quiche/epoll_server/platform/api/epoll_export.h", + "quiche/epoll_server/platform/api/epoll_logging.h", + "quiche/epoll_server/platform/api/epoll_ptr_util.h", + "quiche/epoll_server/platform/api/epoll_test.h", + "quiche/epoll_server/platform/api/epoll_thread.h", + "quiche/epoll_server/platform/api/epoll_time.h", + ], + repository = "@envoy", + deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:epoll_server_platform_impl_lib"], +) + +envoy_cc_test_library( + name = "epoll_server_lib", + srcs = [ + "quiche/epoll_server/fake_simple_epoll_server.cc", + "quiche/epoll_server/simple_epoll_server.cc", + ], + hdrs = [ + "quiche/epoll_server/fake_simple_epoll_server.h", + "quiche/epoll_server/simple_epoll_server.h", + ], + copts = quiche_copt, + repository = "@envoy", + deps = [":epoll_server_platform"], +) + +envoy_cc_test( + name = "epoll_server_test", + srcs = ["quiche/epoll_server/simple_epoll_server_test.cc"], + copts = quiche_copt, + repository = "@envoy", + deps = [":epoll_server_lib"], +) + envoy_cc_test( name = "http2_platform_api_test", srcs = envoy_select_quiche( diff --git a/bazel/external/quiche.genrule_cmd b/bazel/external/quiche.genrule_cmd index 5d3528cca6bc1..9550ef9395bc7 100644 --- a/bazel/external/quiche.genrule_cmd +++ b/bazel/external/quiche.genrule_cmd @@ -29,6 +29,9 @@ cat <sed_commands # Rewrite include directives for platform impl files. /^#include/ s!net/(http2|spdy|quic)/platform/impl/!extensions/quic_listeners/quiche/platform/! +# Rewrite include directives for epoll_server platform impl files. +/^#include/ s!net/tools/epoll_server/platform/impl!test/extensions/quic_listeners/quiche/platform/! + # Strip "net/third_party" from include directives to other QUICHE files. /^#include/ s!net/third_party/quiche/src/!quiche/! diff --git a/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h index 131e6292068d0..942922fedd4d3 100644 --- a/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h @@ -59,16 +59,24 @@ #define CHECK(condition) \ QUIC_LOG_IF_IMPL(FATAL, ABSL_PREDICT_FALSE(!(condition))) << "CHECK failed: " #condition "." +#define CHECK_GT(a, b) CHECK((a) > (b)) +#define CHECK_GE(a, b) CHECK((a) >= (b)) +#define CHECK_LT(a, b) CHECK((a) < (b)) +#define CHECK_LE(a, b) CHECK((a) <= (b)) +#define CHECK_NE(a, b) CHECK((a) != (b)) +#define CHECK_EQ(a, b) CHECK((a) == (b)) + #ifdef NDEBUG // Release build -#define DCHECK(condition) QUIC_COMPILED_OUT_LOG() -#define QUIC_COMPILED_OUT_LOG() QUIC_LOG_IMPL_INTERNAL(false, quic::NullLogStream().stream()) -#define QUIC_DVLOG_IMPL(verbosity) QUIC_COMPILED_OUT_LOG() -#define QUIC_DVLOG_IF_IMPL(verbosity, condition) QUIC_COMPILED_OUT_LOG() -#define QUIC_DLOG_IMPL(severity) QUIC_COMPILED_OUT_LOG() -#define QUIC_DLOG_IF_IMPL(severity, condition) QUIC_COMPILED_OUT_LOG() +#define DCHECK(condition) QUIC_COMPILED_OUT_LOG(condition) +#define QUIC_COMPILED_OUT_LOG(condition) \ + QUIC_LOG_IMPL_INTERNAL(false && (condition), quic::NullLogStream().stream()) +#define QUIC_DVLOG_IMPL(verbosity) QUIC_COMPILED_OUT_LOG(false) +#define QUIC_DVLOG_IF_IMPL(verbosity, condition) QUIC_COMPILED_OUT_LOG(condition) +#define QUIC_DLOG_IMPL(severity) QUIC_COMPILED_OUT_LOG(false) +#define QUIC_DLOG_IF_IMPL(severity, condition) QUIC_COMPILED_OUT_LOG(condition) #define QUIC_DLOG_INFO_IS_ON_IMPL() 0 -#define QUIC_DLOG_EVERY_N_IMPL(severity, n) QUIC_COMPILED_OUT_LOG() +#define QUIC_DLOG_EVERY_N_IMPL(severity, n) QUIC_COMPILED_OUT_LOG(false) #define QUIC_NOTREACHED_IMPL() #else // Debug build @@ -83,6 +91,11 @@ #endif #define DCHECK_GE(a, b) DCHECK((a) >= (b)) +#define DCHECK_GT(a, b) DCHECK((a) > (b)) +#define DCHECK_LT(a, b) DCHECK((a) < (b)) +#define DCHECK_LE(a, b) DCHECK((a) <= (b)) +#define DCHECK_NE(a, b) DCHECK((a) != (b)) +#define DCHECK_EQ(a, b) DCHECK((a) == (b)) #define QUIC_PREDICT_FALSE_IMPL(x) ABSL_PREDICT_FALSE(x) diff --git a/test/extensions/quic_listeners/quiche/platform/BUILD b/test/extensions/quic_listeners/quiche/platform/BUILD index 7c83e36566626..f958acfbb8266 100644 --- a/test/extensions/quic_listeners/quiche/platform/BUILD +++ b/test/extensions/quic_listeners/quiche/platform/BUILD @@ -98,6 +98,29 @@ envoy_cc_test_library( deps = ["//source/common/common:assert_lib"], ) +envoy_cc_test_library( + name = "epoll_server_platform_impl_lib", + hdrs = [ + "epoll_address_test_utils_impl.h", + "epoll_bug_impl.h", + "epoll_expect_bug_impl.h", + "epoll_export_impl.h", + "epoll_logging_impl.h", + "epoll_ptr_util_impl.h", + "epoll_test_impl.h", + "epoll_thread_impl.h", + "epoll_time_impl.h", + ], + external_deps = ["abseil_time"], + deps = [ + ":quic_platform_expect_bug_impl_lib", + ":quic_platform_thread_impl_lib", + "//include/envoy/network:address_interface", + "//source/extensions/quic_listeners/quiche/platform:quic_platform_base_impl_lib", + "//test/test_common:environment_lib", + ], +) + envoy_cc_test_library( name = "quic_platform_test_output_impl_lib", srcs = ["quic_test_output_impl.cc"], diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_address_test_utils_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_address_test_utils_impl.h new file mode 100644 index 0000000000000..9accbd699ae1f --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_address_test_utils_impl.h @@ -0,0 +1,44 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include + +#include + +#include "envoy/network/address.h" + +#include "test/test_common/environment.h" + +namespace epoll_server { + +namespace { + +int addressFamilyUnderTestHelper() { + std::vector versions = + Envoy::TestEnvironment::getIpVersionsForTest(); + if (std::find(versions.begin(), versions.end(), Envoy::Network::Address::IpVersion::v4) != + versions.end()) { + return AF_INET; + } + if (std::find(versions.begin(), versions.end(), Envoy::Network::Address::IpVersion::v6) != + versions.end()) { + return AF_INET6; + } + return -1; +} + +} // namespace + +// Returns the address family to be used for test. Return v4 if the environment +// supports v4 only or both v4 and v6. Otherwise return v6 or an invalid value. +int AddressFamilyUnderTestImpl() { + static const int version = addressFamilyUnderTestHelper(); + return version; +} + +} // namespace epoll_server diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_bug_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_bug_impl.h new file mode 100644 index 0000000000000..7ecd3252466fe --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_bug_impl.h @@ -0,0 +1,11 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "extensions/quic_listeners/quiche/platform/quic_bug_tracker_impl.h" + +#define EPOLL_BUG_IMPL QUIC_BUG_IMPL diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_expect_bug_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_expect_bug_impl.h new file mode 100644 index 0000000000000..9748ecab32c00 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_expect_bug_impl.h @@ -0,0 +1,11 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "test/extensions/quic_listeners/quiche/platform/quic_expect_bug_impl.h" + +#define EXPECT_EPOLL_BUG_IMPL EXPECT_QUIC_BUG_IMPL diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_export_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_export_impl.h new file mode 100644 index 0000000000000..65d77158aafe4 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_export_impl.h @@ -0,0 +1,10 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#define EPOLL_EXPORT +#define EPOLL_EXPORT_PRIVATE diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_logging_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_logging_impl.h new file mode 100644 index 0000000000000..36ca6d4f79aeb --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_logging_impl.h @@ -0,0 +1,20 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "extensions/quic_listeners/quiche/platform/quic_logging_impl.h" + +namespace epoll_server { + +#define EPOLL_LOG_IMPL(severity) QUIC_LOG_IMPL(severity) +#define EPOLL_VLOG_IMPL(verbosity) QUIC_VLOG_IMPL(verbosity) + +#define EPOLL_PLOG_IMPL(severity) QUIC_PLOG_IMPL(severity) + +#define EPOLL_DVLOG_IMPL(verbosity) QUIC_DVLOG_IMPL(verbosity) + +} // namespace epoll_server diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_ptr_util_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_ptr_util_impl.h new file mode 100644 index 0000000000000..12da8b11d3cc7 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_ptr_util_impl.h @@ -0,0 +1,17 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include + +namespace epoll_server { + +template std::unique_ptr EpollMakeUniqueImpl(Args&&... args) { + return std::make_unique(std::forward(args)...); +} + +} // namespace epoll_server diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_test_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_test_impl.h new file mode 100644 index 0000000000000..f0f25ed3b111f --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_test_impl.h @@ -0,0 +1,12 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using EpollTestImpl = ::testing::Test; diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_thread_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_thread_impl.h new file mode 100644 index 0000000000000..be5b5271b77ce --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_thread_impl.h @@ -0,0 +1,15 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "test/extensions/quic_listeners/quiche/platform/quic_thread_impl.h" + +namespace epoll_server { + +using EpollThreadImpl = quic::QuicThreadImpl; + +} // namespace epoll_server diff --git a/test/extensions/quic_listeners/quiche/platform/epoll_time_impl.h b/test/extensions/quic_listeners/quiche/platform/epoll_time_impl.h new file mode 100644 index 0000000000000..123ceb744938b --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/epoll_time_impl.h @@ -0,0 +1,15 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This file is part of the QUICHE platform implementation, and is not to be +// consumed or referenced directly by other Envoy code. It serves purely as a +// porting layer for QUICHE. + +#include "absl/time/clock.h" + +namespace epoll_server { + +inline int64_t WallTimeNowInUsecImpl() { return absl::GetCurrentTimeNanos() / 1000; } + +} // namespace epoll_server