From 1ea9d7fecd164f3a1ad76610a0058d4ec92d8b6d Mon Sep 17 00:00:00 2001 From: Bin Wu Date: Fri, 26 Apr 2019 09:19:45 -0400 Subject: [PATCH 1/2] quiche: Implement http2_reconstruct_object_impl.h. Signed-off-by: Bin Wu --- bazel/external/quiche.BUILD | 35 +++++++++++++++---- bazel/external/quiche.genrule_cmd | 4 ++- .../quiche/platform/http2_string_utils_impl.h | 2 +- .../quiche/platform/quic_logging_impl.h | 7 ++++ .../quic_listeners/quiche/platform/BUILD | 11 ++++-- .../quiche/platform/http2_platform_test.cc | 22 ++++++++++-- .../platform/http2_reconstruct_object_impl.h | 32 +++++++++++++++++ 7 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 test/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h diff --git a/bazel/external/quiche.BUILD b/bazel/external/quiche.BUILD index c28f72848e139..a2c4be080904c 100644 --- a/bazel/external/quiche.BUILD +++ b/bazel/external/quiche.BUILD @@ -29,6 +29,7 @@ load(":genrule_cmd.bzl", "genrule_cmd") load( "@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", + "envoy_external_dep_path", "envoy_select_quiche", ) @@ -48,6 +49,26 @@ genrule( visibility = ["//visibility:private"], ) +cc_library( + name = "http2_platform_reconstruct_object", + testonly = 1, + hdrs = ["quiche/http2/platform/api/http2_reconstruct_object.h"], + visibility = ["//visibility:public"], + deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:http2_platform_reconstruct_object_impl_lib"], +) + +cc_library( + name = "http2_test_tools_random", + testonly = 1, + srcs = ["quiche/http2/test_tools/http2_random.cc"], + hdrs = ["quiche/http2/test_tools/http2_random.h"], + visibility = ["//visibility:public"], + deps = [ + ":http2_platform", + envoy_external_dep_path("ssl"), + ], +) + cc_library( name = "http2_platform", hdrs = [ @@ -63,7 +84,6 @@ cc_library( "quiche/http2/platform/api/http2_string_piece.h", # TODO: uncomment the following files as implementations are added. # "quiche/http2/platform/api/http2_flags.h", - # "quiche/http2/platform/api/http2_reconstruct_object.h", # "quiche/http2/platform/api/http2_test_helpers.h", ] + envoy_select_quiche( [ @@ -277,12 +297,15 @@ cc_library( envoy_cc_test( name = "http2_platform_api_test", - srcs = envoy_select_quiche( - ["quiche/http2/platform/api/http2_string_utils_test.cc"], - "@envoy", - ), + srcs = [ + "quiche/http2/platform/api/http2_string_utils_test.cc", + "quiche/http2/test_tools/http2_random_test.cc", + ], repository = "@envoy", - deps = [":http2_platform"], + deps = [ + ":http2_platform", + ":http2_test_tools_random", + ], ) envoy_cc_test( diff --git a/bazel/external/quiche.genrule_cmd b/bazel/external/quiche.genrule_cmd index a1946703a2929..8a21de914fa49 100644 --- a/bazel/external/quiche.genrule_cmd +++ b/bazel/external/quiche.genrule_cmd @@ -19,6 +19,7 @@ src_base_dir=$$(dirname $$(dirname $$(dirname $(rootpath quic/core/quic_constant # sed commands to apply to each source file. cat <sed_commands # Rewrite include directives for testonly platform impl files. +/^#include/ s!net/http2/platform/impl/http2_reconstruct_object_impl.h!test/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h! /^#include/ s!net/quic/platform/impl/quic_expect_bug_impl.h!test/extensions/quic_listeners/quiche/platform/quic_expect_bug_impl.h! /^#include/ s!net/quic/platform/impl/quic_mock_log_impl.h!test/extensions/quic_listeners/quiche/platform/quic_mock_log_impl.h! /^#include/ s!net/quic/platform/impl/quic_port_utils_impl.h!test/extensions/quic_listeners/quiche/platform/quic_port_utils_impl.h! @@ -31,7 +32,8 @@ cat <sed_commands # Strip "net/third_party" from include directives to other QUICHE files. /^#include/ s!net/third_party/quiche/src/!quiche/! -# Rewrite gtest includes. +# Rewrite gmock & gtest includes. +/^#include/ s!testing/gmock/include/gmock/!gmock/! /^#include/ s!testing/gtest/include/gtest/!gtest/! # Rewrite third_party includes. diff --git a/source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h b/source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h index 1e642a0c9cda1..d4df004f4c51f 100644 --- a/source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h @@ -36,7 +36,7 @@ inline std::string Http2HexDecodeImpl(absl::string_view data) { return absl::HexStringToBytes(data); } -std::string Http2HexDumpImpl(absl::string_view data) { return quiche::HexDump(data); } +inline std::string Http2HexDumpImpl(absl::string_view data) { return quiche::HexDump(data); } inline std::string Http2HexEscapeImpl(absl::string_view data) { return absl::CHexEscape(data); } 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..a2a457ca3b5b6 100644 --- a/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h @@ -59,6 +59,13 @@ #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() diff --git a/test/extensions/quic_listeners/quiche/platform/BUILD b/test/extensions/quic_listeners/quiche/platform/BUILD index 68209c63a4b1a..119bcc7df0727 100644 --- a/test/extensions/quic_listeners/quiche/platform/BUILD +++ b/test/extensions/quic_listeners/quiche/platform/BUILD @@ -16,17 +16,19 @@ envoy_package() envoy_cc_test( name = "http2_platform_test", - srcs = envoy_select_quiche(["http2_platform_test.cc"]), + srcs = ["http2_platform_test.cc"], external_deps = ["quiche_http2_platform"], deps = [ "//test/test_common:logging_lib", "//test/test_common:utility_lib", + "@com_googlesource_quiche//:http2_platform_reconstruct_object", + "@com_googlesource_quiche//:http2_test_tools_random", ], ) envoy_cc_test( name = "quic_platform_test", - srcs = envoy_select_quiche(["quic_platform_test.cc"]), + srcs = ["quic_platform_test.cc"], data = [ "//test/extensions/transport_sockets/tls/test_data:certs", ], @@ -57,6 +59,11 @@ envoy_cc_test( ], ) +envoy_cc_test_library( + name = "http2_platform_reconstruct_object_impl_lib", + hdrs = ["http2_reconstruct_object_impl.h"], +) + envoy_cc_test_library( name = "quic_platform_expect_bug_impl_lib", hdrs = ["quic_expect_bug_impl.h"], diff --git a/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc index 0cd37a1512624..2cf07d3cf210d 100644 --- a/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc +++ b/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc @@ -17,8 +17,10 @@ #include "quiche/http2/platform/api/http2_macros.h" #include "quiche/http2/platform/api/http2_optional.h" #include "quiche/http2/platform/api/http2_ptr_util.h" +#include "quiche/http2/platform/api/http2_reconstruct_object.h" #include "quiche/http2/platform/api/http2_string.h" #include "quiche/http2/platform/api/http2_string_piece.h" +#include "quiche/http2/test_tools/http2_random.h" // Basic tests to validate functioning of the QUICHE http2 platform // implementation. For platform APIs in which the implementation is a simple @@ -77,6 +79,11 @@ TEST(Http2PlatformTest, Http2Log) { HTTP2_DLOG_EVERY_N(ERROR, 2) << "DLOG_EVERY_N(ERROR, 2)"; } +TEST(Http2PlatformTest, Http2MakeUnique) { + auto p = http2::Http2MakeUnique(4); + EXPECT_EQ(4, *p); +} + TEST(Http2PlatformTest, Http2Optional) { http2::Http2Optional opt; EXPECT_FALSE(opt.has_value()); @@ -84,9 +91,18 @@ TEST(Http2PlatformTest, Http2Optional) { EXPECT_TRUE(opt.has_value()); } -TEST(Http2PlatformTest, Http2MakeUnique) { - auto p = http2::Http2MakeUnique(4); - EXPECT_EQ(4, *p); +TEST(Http2PlatformTest, Http2ReconstructObject) { + http2::test::Http2Random rng; + std::string s; + + http2::test::Http2ReconstructObject(&s, &rng, "123"); + EXPECT_EQ("123", s); + + http2::test::Http2ReconstructObject(&s, &rng, "456"); + EXPECT_EQ("456", s); + + http2::test::Http2DefaultReconstructObject(&s, &rng); + EXPECT_EQ("", s); } TEST(Http2PlatformTest, Http2String) { diff --git a/test/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h b/test/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h new file mode 100644 index 0000000000000..974e3fa48b195 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h @@ -0,0 +1,32 @@ +#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 http2 { +namespace test { + +class Http2Random; + +// Reconstruct an object so that it is initialized as when it was first +// constructed. Runs the destructor to handle objects that might own resources, +// and runs the constructor with the provided arguments, if any. +template +void Http2ReconstructObjectImpl(T* ptr, Http2Random* /*rng*/, Args&&... args) { + ptr->~T(); + ::new (ptr) T(std::forward(args)...); +} + +// This version applies default-initialization to the object. +template void Http2DefaultReconstructObjectImpl(T* ptr, Http2Random* /*rng*/) { + ptr->~T(); + ::new (ptr) T; +} + +} // namespace test +} // namespace http2 From 872ffae44afa88317f8e338409ce265920bfac31 Mon Sep 17 00:00:00 2001 From: Bin Wu Date: Sat, 27 Apr 2019 00:01:36 -0400 Subject: [PATCH 2/2] Change envoy_external_dep_path to external_deps for build rule http2_test_tools_random. Signed-off-by: Bin Wu --- bazel/external/quiche.BUILD | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bazel/external/quiche.BUILD b/bazel/external/quiche.BUILD index c0d7b7654bab1..35773afcd316f 100644 --- a/bazel/external/quiche.BUILD +++ b/bazel/external/quiche.BUILD @@ -31,7 +31,6 @@ load( "envoy_cc_library", "envoy_cc_test", "envoy_cc_test_library", - "envoy_external_dep_path", "envoy_select_quiche", ) @@ -64,11 +63,9 @@ envoy_cc_test_library( name = "http2_test_tools_random", srcs = ["quiche/http2/test_tools/http2_random.cc"], hdrs = ["quiche/http2/test_tools/http2_random.h"], + external_deps = ["ssl"], repository = "@envoy", - deps = [ - ":http2_platform", - envoy_external_dep_path("ssl"), - ], + deps = [":http2_platform"], ) envoy_cc_library(