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
30 changes: 24 additions & 6 deletions bazel/external/quiche.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ genrule(

quiche_copt = ["-Wno-unused-parameter"]

envoy_cc_test_library(
name = "http2_platform_reconstruct_object",
hdrs = ["quiche/http2/platform/api/http2_reconstruct_object.h"],
repository = "@envoy",
deps = ["@envoy//test/extensions/quic_listeners/quiche/platform:http2_platform_reconstruct_object_impl_lib"],
)

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_cc_library(
name = "http2_platform",
hdrs = [
Expand All @@ -67,7 +83,6 @@ envoy_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(
[
Expand Down Expand Up @@ -332,12 +347,15 @@ envoy_cc_test(

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(
Expand Down
4 changes: 3 additions & 1 deletion bazel/external/quiche.genrule_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ src_base_dir=$$(dirname $$(dirname $$(dirname $(rootpath quic/core/quic_constant
# sed commands to apply to each source file.
cat <<EOF >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!
Expand All @@ -35,7 +36,8 @@ cat <<EOF >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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
11 changes: 9 additions & 2 deletions test/extensions/quic_listeners/quiche/platform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,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",
],
Expand Down Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,16 +79,30 @@ TEST(Http2PlatformTest, Http2Log) {
HTTP2_DLOG_EVERY_N(ERROR, 2) << "DLOG_EVERY_N(ERROR, 2)";
}

TEST(Http2PlatformTest, Http2MakeUnique) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why adding this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not adding this test, I just moved it up to sort the tests by name alphabetically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right. It was there. Thanks for doing this!

auto p = http2::Http2MakeUnique<int>(4);
EXPECT_EQ(4, *p);
}

TEST(Http2PlatformTest, Http2Optional) {
http2::Http2Optional<int> opt;
EXPECT_FALSE(opt.has_value());
opt = 3;
EXPECT_TRUE(opt.has_value());
}

TEST(Http2PlatformTest, Http2MakeUnique) {
auto p = http2::Http2MakeUnique<int>(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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <utility>

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 <class T, class... Args>
void Http2ReconstructObjectImpl(T* ptr, Http2Random* /*rng*/, Args&&... args) {
ptr->~T();
::new (ptr) T(std::forward<Args>(args)...);
}

// This version applies default-initialization to the object.
template <class T> void Http2DefaultReconstructObjectImpl(T* ptr, Http2Random* /*rng*/) {
ptr->~T();
::new (ptr) T;
}

} // namespace test
} // namespace http2