From db600fd0370750d315417a47dfaaaabc5d79aecd Mon Sep 17 00:00:00 2001 From: Michael Warres Date: Mon, 21 Jan 2019 11:24:01 -0500 Subject: [PATCH] Misc additions for stubbing out QUICHE platform impls. - Add QUICHE spdy_platform and quic_platform build rules. - Prune not yet implemented platform implementation files, to reduce noise. - For partially complete platform implementation files, add "TODO: implement" comments to individual items that still need to be implemented. - Add unit tests for platform APIs that have already been implemented. Signed-off-by: Michael Warres --- bazel/external/quiche.BUILD | 96 +++++++++++++++++-- bazel/repositories.bzl | 30 +++++- .../quic_listeners/quiche/platform/BUILD | 60 ++++++++++-- .../platform/http2_reconstruct_object_impl.h | 32 ------- .../quiche/platform/http2_string_utils_impl.h | 54 ----------- .../quiche/platform/http2_test_helpers_impl.h | 24 ----- .../quiche/platform/quic_aligned_impl.h | 14 +++ .../quiche/platform/quic_arraysize_impl.h | 11 +++ .../quiche/platform/quic_containers_impl.h | 45 +++++++++ .../quiche/platform/quic_endian_impl.h | 31 ++++++ .../quic_estimate_memory_usage_impl.h | 16 ++++ .../quiche/platform/quic_export_impl.h | 10 ++ .../quiche/platform/quic_fallthrough_impl.h | 11 +++ .../quiche/platform/quic_flag_utils_impl.h | 31 ++++++ .../quiche/platform/quic_iovec_impl.h | 9 ++ .../quiche/platform/quic_string_impl.h | 15 +++ .../quiche/platform/quic_string_piece_impl.h | 15 +++ .../quiche/platform/spdy_arraysize_impl.h | 11 +++ .../quiche/platform/spdy_containers_impl.h | 46 +++++++++ .../platform/spdy_endianness_util_impl.h | 29 ++++++ .../spdy_estimate_memory_usage_impl.h | 16 ++++ .../quiche/platform/spdy_export_impl.h | 10 ++ .../quiche/platform/spdy_macros_impl.h | 15 +++ .../quiche/platform/spdy_ptr_util_impl.h | 23 +++++ .../quiche/platform/spdy_string_impl.h | 15 +++ .../quiche/platform/spdy_string_piece_impl.h | 15 +++ ...racker_impl.h => spdy_test_helpers_impl.h} | 5 +- ...log_impl.h => spdy_test_utils_prod_impl.h} | 5 +- ..._flags_impl.h => spdy_unsafe_arena_impl.h} | 6 +- .../quic_listeners/quiche/platform/BUILD | 40 ++++++++ .../quiche/platform/http2_platform_test.cc | 66 +++++++++++++ .../quiche/platform/quic_platform_test.cc | 83 ++++++++++++++++ .../quiche/platform/spdy_platform_test.cc | 77 +++++++++++++++ 33 files changed, 830 insertions(+), 136 deletions(-) delete mode 100644 source/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h delete mode 100644 source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h delete mode 100644 source/extensions/quic_listeners/quiche/platform/http2_test_helpers_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_aligned_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_arraysize_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_containers_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_endian_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_estimate_memory_usage_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_export_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_fallthrough_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_flag_utils_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_iovec_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_string_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/quic_string_piece_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_arraysize_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_containers_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_endianness_util_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_estimate_memory_usage_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_export_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_macros_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_ptr_util_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_string_impl.h create mode 100644 source/extensions/quic_listeners/quiche/platform/spdy_string_piece_impl.h rename source/extensions/quic_listeners/quiche/platform/{http2_bug_tracker_impl.h => spdy_test_helpers_impl.h} (69%) rename source/extensions/quic_listeners/quiche/platform/{http2_mock_log_impl.h => spdy_test_utils_prod_impl.h} (61%) rename source/extensions/quic_listeners/quiche/platform/{http2_flags_impl.h => spdy_unsafe_arena_impl.h} (72%) create mode 100644 test/extensions/quic_listeners/quiche/platform/BUILD create mode 100644 test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc create mode 100644 test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc create mode 100644 test/extensions/quic_listeners/quiche/platform/spdy_platform_test.cc diff --git a/bazel/external/quiche.BUILD b/bazel/external/quiche.BUILD index d2c138a742a3e..74664b86d77d2 100644 --- a/bazel/external/quiche.BUILD +++ b/bazel/external/quiche.BUILD @@ -62,24 +62,108 @@ cc_library( name = "http2_platform", hdrs = [ "quiche/http2/platform/api/http2_arraysize.h", - "quiche/http2/platform/api/http2_bug_tracker.h", "quiche/http2/platform/api/http2_containers.h", "quiche/http2/platform/api/http2_estimate_memory_usage.h", "quiche/http2/platform/api/http2_export.h", "quiche/http2/platform/api/http2_flag_utils.h", - "quiche/http2/platform/api/http2_flags.h", "quiche/http2/platform/api/http2_macros.h", - "quiche/http2/platform/api/http2_mock_log.h", "quiche/http2/platform/api/http2_optional.h", "quiche/http2/platform/api/http2_ptr_util.h", - "quiche/http2/platform/api/http2_reconstruct_object.h", "quiche/http2/platform/api/http2_string.h", "quiche/http2/platform/api/http2_string_piece.h", - "quiche/http2/platform/api/http2_string_utils.h", - "quiche/http2/platform/api/http2_test_helpers.h", + # TODO: uncomment the following files as implementations are added. + # "quiche/http2/platform/api/http2_bug_tracker.h", + # "quiche/http2/platform/api/http2_flags.h", + # "quiche/http2/platform/api/http2_mock_log.h", + # "quiche/http2/platform/api/http2_reconstruct_object.h", + # "quiche/http2/platform/api/http2_string_utils.h", + # "quiche/http2/platform/api/http2_test_helpers.h", ], visibility = ["//visibility:public"], deps = [ "@envoy//source/extensions/quic_listeners/quiche/platform:http2_platform_impl_lib", ], ) + +cc_library( + name = "spdy_platform", + hdrs = [ + "quiche/spdy/platform/api/spdy_arraysize.h", + "quiche/spdy/platform/api/spdy_containers.h", + "quiche/spdy/platform/api/spdy_endianness_util.h", + "quiche/spdy/platform/api/spdy_estimate_memory_usage.h", + "quiche/spdy/platform/api/spdy_export.h", + "quiche/spdy/platform/api/spdy_ptr_util.h", + "quiche/spdy/platform/api/spdy_string.h", + "quiche/spdy/platform/api/spdy_string_piece.h", + # TODO: uncomment the following files as implementations are added. + # "quiche/spdy/platform/api/spdy_flags.h", + # "quiche/spdy/platform/api/spdy_mem_slice.h", + # "quiche/spdy/platform/api/spdy_string_utils.h", + ], + visibility = ["//visibility:public"], + deps = [ + "@envoy//source/extensions/quic_listeners/quiche/platform:spdy_platform_impl_lib", + ], +) + +cc_library( + name = "quic_platform", + hdrs = [ + "quiche/quic/platform/api/quic_aligned.h", + "quiche/quic/platform/api/quic_arraysize.h", + "quiche/quic/platform/api/quic_containers.h", + "quiche/quic/platform/api/quic_endian.h", + "quiche/quic/platform/api/quic_estimate_memory_usage.h", + "quiche/quic/platform/api/quic_export.h", + "quiche/quic/platform/api/quic_fallthrough.h", + "quiche/quic/platform/api/quic_flag_utils.h", + "quiche/quic/platform/api/quic_iovec.h", + "quiche/quic/platform/api/quic_string.h", + "quiche/quic/platform/api/quic_string_piece.h", + # TODO: uncomment the following files as implementations are added. + # "quiche/quic/platform/api/quic_bug_tracker.h", + # "quiche/quic/platform/api/quic_client_stats.h", + # "quiche/quic/platform/api/quic_clock.h", + # "quiche/quic/platform/api/quic_expect_bug.h", + # "quiche/quic/platform/api/quic_exported_stats.h", + # "quiche/quic/platform/api/quic_file_utils.h", + # "quiche/quic/platform/api/quic_flags.h", + # "quiche/quic/platform/api/quic_fuzzed_data_provider.h", + # "quiche/quic/platform/api/quic_goog_cc_sender.h", + # "quiche/quic/platform/api/quic_hostname_utils.h", + # "quiche/quic/platform/api/quic_interval.h", + # "quiche/quic/platform/api/quic_ip_address_family.h", + # "quiche/quic/platform/api/quic_ip_address.h", + # "quiche/quic/platform/api/quic_logging.h", + # "quiche/quic/platform/api/quic_lru_cache.h", + # "quiche/quic/platform/api/quic_map_util.h", + # "quiche/quic/platform/api/quic_mem_slice.h", + # "quiche/quic/platform/api/quic_mem_slice_span.h", + # "quiche/quic/platform/api/quic_mem_slice_storage.h", + # "quiche/quic/platform/api/quic_mock_log.h", + # "quiche/quic/platform/api/quic_mutex.h", + # "quiche/quic/platform/api/quic_pcc_sender.h", + # "quiche/quic/platform/api/quic_prefetch.h", + # "quiche/quic/platform/api/quic_ptr_util.h", + # "quiche/quic/platform/api/quic_reference_counted.h", + # "quiche/quic/platform/api/quic_server_stats.h", + # "quiche/quic/platform/api/quic_singleton.h", + # "quiche/quic/platform/api/quic_sleep.h", + # "quiche/quic/platform/api/quic_socket_address.h", + # "quiche/quic/platform/api/quic_stack_trace.h", + # "quiche/quic/platform/api/quic_str_cat.h", + # "quiche/quic/platform/api/quic_string_utils.h", + # "quiche/quic/platform/api/quic_test.h", + # "quiche/quic/platform/api/quic_test_loopback.h", + # "quiche/quic/platform/api/quic_test_mem_slice_vector.h", + # "quiche/quic/platform/api/quic_test_output.h", + # "quiche/quic/platform/api/quic_text_utils.h", + # "quiche/quic/platform/api/quic_thread.h", + # "quiche/quic/platform/api/quic_uint128.h", + ], + visibility = ["//visibility:public"], + deps = [ + "@envoy//source/extensions/quic_listeners/quiche/platform:quic_platform_impl_lib", + ], +) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 6e5dc73d41d02..c3c8bb2535ea6 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -489,6 +489,26 @@ def _com_google_absl(): name = "abseil_flat_hash_set", actual = "@com_google_absl//absl/container:flat_hash_set", ) + native.bind( + name = "abseil_hash", + actual = "@com_google_absl//absl/hash:hash", + ) + native.bind( + name = "abseil_inlined_vector", + actual = "@com_google_absl//absl/container:inlined_vector", + ) + native.bind( + name = "abseil_memory", + actual = "@com_google_absl//absl/memory:memory", + ) + native.bind( + name = "abseil_node_hash_map", + actual = "@com_google_absl//absl/container:node_hash_map", + ) + native.bind( + name = "abseil_node_hash_set", + actual = "@com_google_absl//absl/container:node_hash_set", + ) native.bind( name = "abseil_strings", actual = "@com_google_absl//absl/strings:strings", @@ -557,12 +577,18 @@ def _com_googlesource_quiche(): build_file = "@envoy//bazel/external:quiche.BUILD", ) - # TODO: add bindings for quiche_quic_platform and quiche_spdy_platform once - # those build targets have been defined. native.bind( name = "quiche_http2_platform", actual = "@com_googlesource_quiche//:http2_platform", ) + native.bind( + name = "quiche_spdy_platform", + actual = "@com_googlesource_quiche//:spdy_platform", + ) + native.bind( + name = "quiche_quic_platform", + actual = "@com_googlesource_quiche//:quic_platform", + ) def _com_github_grpc_grpc(): _repository_impl("com_github_grpc_grpc") diff --git a/source/extensions/quic_listeners/quiche/platform/BUILD b/source/extensions/quic_listeners/quiche/platform/BUILD index 693bbeae24433..8ac141695b53a 100644 --- a/source/extensions/quic_listeners/quiche/platform/BUILD +++ b/source/extensions/quic_listeners/quiche/platform/BUILD @@ -14,28 +14,21 @@ envoy_package() # tests. In a monorepo, this would be enforced via visibility attribute, but # Bazel does not support limiting visibility to specific external dependencies. -# TODO: add build targets for quic_platform_impl_lib and spdy_platform_impl_lib, -# as _impl.* files for those are added. +# TODO: add build target for quic_platform_impl_lib envoy_cc_library( name = "http2_platform_impl_lib", hdrs = [ "http2_arraysize_impl.h", - "http2_bug_tracker_impl.h", "http2_containers_impl.h", "http2_estimate_memory_usage_impl.h", "http2_export_impl.h", "http2_flag_utils_impl.h", - "http2_flags_impl.h", "http2_macros_impl.h", - "http2_mock_log_impl.h", "http2_optional_impl.h", "http2_ptr_util_impl.h", - "http2_reconstruct_object_impl.h", "http2_string_impl.h", "http2_string_piece_impl.h", - "http2_string_utils_impl.h", - "http2_test_helpers_impl.h", ], external_deps = [ "abseil_base", @@ -43,3 +36,54 @@ envoy_cc_library( ], visibility = ["//visibility:public"], ) + +envoy_cc_library( + name = "quic_platform_impl_lib", + hdrs = [ + "quic_aligned_impl.h", + "quic_arraysize_impl.h", + "quic_containers_impl.h", + "quic_endian_impl.h", + "quic_estimate_memory_usage_impl.h", + "quic_export_impl.h", + "quic_fallthrough_impl.h", + "quic_flag_utils_impl.h", + "quic_iovec_impl.h", + "quic_string_impl.h", + "quic_string_piece_impl.h", + ], + external_deps = [ + "abseil_base", + "abseil_hash", + "abseil_inlined_vector", + "abseil_memory", + "abseil_node_hash_map", + "abseil_node_hash_set", + ], + visibility = ["//visibility:public"], +) + +envoy_cc_library( + name = "spdy_platform_impl_lib", + hdrs = [ + "spdy_arraysize_impl.h", + "spdy_containers_impl.h", + "spdy_endianness_util_impl.h", + "spdy_estimate_memory_usage_impl.h", + "spdy_export_impl.h", + "spdy_macros_impl.h", + "spdy_ptr_util_impl.h", + "spdy_string_impl.h", + "spdy_string_piece_impl.h", + "spdy_test_helpers_impl.h", + "spdy_test_utils_prod_impl.h", + "spdy_unsafe_arena_impl.h", + ], + external_deps = [ + "abseil_base", + "abseil_hash", + "abseil_inlined_vector", + "abseil_memory", + ], + visibility = ["//visibility:public"], +) diff --git a/source/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h b/source/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h deleted file mode 100644 index 2ee229d3874e5..0000000000000 --- a/source/extensions/quic_listeners/quiche/platform/http2_reconstruct_object_impl.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -// 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. - -// TODO: implement - -namespace http2 { -namespace test { - -class Http2Random; - -void MarkMemoryUninitialized(void* /*ptr*/, size_t /*num_bytes*/) {} -void MarkMemoryUninitialized(void* /*ptr*/, size_t /*num_bytes*/, Http2Random* /*rng*/) {} - -template void MarkObjectUninitialized(T* /*ptr*/) {} -template void MarkObjectUninitialized(T* /*ptr*/, Http2Random* /*rng*/) {} - -template void MarkArrayUninitialized(T (&/*array*/)[N]) {} -template void MarkArrayUninitialized(T (&/*array*/)[N], Http2Random* /*rng*/) {} - -template -void Http2ReconstructObjectImpl(T* /*ptr*/, Http2Random* /*rng*/, Args&&... /*args*/) {} -template void Http2DefaultReconstructObjectImpl(T* /*ptr*/, Http2Random* /*rng*/) {} - -} // namespace test -} // namespace http2 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 deleted file mode 100644 index 4465d50e109b2..0000000000000 --- a/source/extensions/quic_listeners/quiche/platform/http2_string_utils_impl.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include - -// The following includes should be: -// -// #include "extensions/quic_listeners/quiche/platform/http2_string_impl.h" -// #include "extensions/quic_listeners/quiche/platform/http2_string_piece_impl.h" -// -// However, for some reason, bazel.clang_tidy cannot resolve the files when specified this way. -// TODO(mpw): fix includes to use full paths. -#include "http2_string_impl.h" -#include "http2_string_piece_impl.h" - -// 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. - -// TODO: implement - -namespace http2 { - -template inline Http2StringImpl Http2StrCatImpl(const Args&... /*args*/) { - return Http2StringImpl(); -} - -template -inline void Http2StrAppendImpl(Http2StringImpl* /*output*/, const Args&... /*args*/) {} - -template inline Http2StringImpl Http2StringPrintfImpl(const Args&... /*args*/) { - return Http2StringImpl(); -} - -inline Http2StringImpl Http2HexEncodeImpl(const void* /*bytes*/, size_t /*size*/) { - return Http2StringImpl(); -} - -inline Http2StringImpl Http2HexDecodeImpl(Http2StringPieceImpl /*data*/) { - return Http2StringImpl(); -} - -inline Http2StringImpl Http2HexDumpImpl(Http2StringPieceImpl /*data*/) { return Http2StringImpl(); } - -inline Http2StringImpl Http2HexEscapeImpl(Http2StringPieceImpl /*data*/) { - return Http2StringImpl(); -} - -template inline Http2StringImpl Http2HexImpl(Number /*number*/) { - return Http2StringImpl(); -} - -} // namespace http2 diff --git a/source/extensions/quic_listeners/quiche/platform/http2_test_helpers_impl.h b/source/extensions/quic_listeners/quiche/platform/http2_test_helpers_impl.h deleted file mode 100644 index 85d72e33ce0b6..0000000000000 --- a/source/extensions/quic_listeners/quiche/platform/http2_test_helpers_impl.h +++ /dev/null @@ -1,24 +0,0 @@ -#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. - -// TODO: implement - -#define VERIFY_AND_RETURN_SUCCESS(expression) 0 -#define VERIFY_TRUE(condition) 0 -#define VERIFY_FALSE(condition) 0 -#define VERIFY_THAT(value, matcher) 0 -#define VERIFY_EQ(val1, val2) 0 -#define VERIFY_NE(val1, val2) 0 -#define VERIFY_GT(val1, val2) 0 -#define VERIFY_LT(val1, val2) 0 -#define VERIFY_GE(val1, val2) 0 -#define VERIFY_LE(val1, val2) 0 -#define VERIFY_DOUBLE_EQ(val1, val2) 0 -#define VERIFY_OK(statement) 0 -#define VERIFY_OK_AND_ASSIGN(var, expression) 0 -#define VERIFY_SUCCESS(expr) 0 diff --git a/source/extensions/quic_listeners/quiche/platform/quic_aligned_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_aligned_impl.h new file mode 100644 index 0000000000000..73659ace0e63c --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_aligned_impl.h @@ -0,0 +1,14 @@ +#pragma once + +#include "absl/base/optimization.h" + +// 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 QUIC_ALIGN_OF_IMPL alignof +#define QUIC_ALIGNED_IMPL(X) __attribute__((aligned(X))) +#define QUIC_CACHELINE_ALIGNED_IMPL ABSL_CACHELINE_ALIGNED +#define QUIC_CACHELINE_SIZE_IMPL ABSL_CACHELINE_SIZE diff --git a/source/extensions/quic_listeners/quiche/platform/quic_arraysize_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_arraysize_impl.h new file mode 100644 index 0000000000000..7ed9e03411064 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_arraysize_impl.h @@ -0,0 +1,11 @@ +#pragma once + +#include "absl/base/macros.h" + +// 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 QUIC_ARRAYSIZE_IMPL(array) ABSL_ARRAYSIZE(array) diff --git a/source/extensions/quic_listeners/quiche/platform/quic_containers_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_containers_impl.h new file mode 100644 index 0000000000000..8d1a08953a42b --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_containers_impl.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/container/inlined_vector.h" +#include "absl/container/node_hash_map.h" +#include "absl/container/node_hash_set.h" + +// 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. + +namespace quic { + +template using QuicDefaultHasherImpl = absl::Hash; + +template +using QuicUnorderedMapImpl = absl::node_hash_map; + +template using QuicUnorderedSetImpl = absl::node_hash_set; + +// TODO: implement +template class QuicLinkedHashMapImpl {}; + +// TODO: implement +template class QuicSmallMapImpl {}; + +// TODO: implement +template class QuicIntervalSetImpl; + +template using QuicQueueImpl = std::queue; + +template using QuicDequeImpl = std::deque; + +template > +using QuicInlinedVectorImpl = absl::InlinedVector; + +} // namespace quic diff --git a/source/extensions/quic_listeners/quiche/platform/quic_endian_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_endian_impl.h new file mode 100644 index 0000000000000..02e5356830bf0 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_endian_impl.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include + +// 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. + +namespace quic { + +class QuicEndianImpl { +public: + static uint16_t HostToNet16(uint16_t x) { return htons(x); } + static uint32_t HostToNet32(uint32_t x) { return htonl(x); } + // TODO: implement + static uint64_t HostToNet64(uint64_t /*x*/) { return 0; } + + static uint16_t NetToHost16(uint16_t x) { return ntohs(x); } + static uint32_t NetToHost32(uint32_t x) { return ntohl(x); } + // TODO: implement + static uint64_t NetToHost64(uint64_t /*x*/) { return 0; } + + // TODO: implement + static bool HostIsLittleEndian() { return false; } +}; + +} // namespace quic diff --git a/source/extensions/quic_listeners/quiche/platform/quic_estimate_memory_usage_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_estimate_memory_usage_impl.h new file mode 100644 index 0000000000000..e65815ee381be --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_estimate_memory_usage_impl.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +// 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. + +namespace quic { + +// Dummy implementation. +template size_t QuicEstimateMemoryUsageImpl(const T& /*object*/) { return 0; } + +} // namespace quic diff --git a/source/extensions/quic_listeners/quiche/platform/quic_export_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_export_impl.h new file mode 100644 index 0000000000000..e3da61c839ec5 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_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 QUIC_EXPORT +#define QUIC_EXPORT_PRIVATE diff --git a/source/extensions/quic_listeners/quiche/platform/quic_fallthrough_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_fallthrough_impl.h new file mode 100644 index 0000000000000..aa9d6bc36a188 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_fallthrough_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 "absl/base/macros.h" + +#define QUIC_FALLTHROUGH_INTENDED_IMPL ABSL_FALLTHROUGH_INTENDED diff --git a/source/extensions/quic_listeners/quiche/platform/quic_flag_utils_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_flag_utils_impl.h new file mode 100644 index 0000000000000..aed1ac88a6249 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_flag_utils_impl.h @@ -0,0 +1,31 @@ +#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 QUIC_RELOADABLE_FLAG_COUNT_IMPL(flag) \ + do { \ + } while (0) + +#define QUIC_RELOADABLE_FLAG_COUNT_N_IMPL(flag, instance, total) \ + do { \ + } while (0) + +#define QUIC_RESTART_FLAG_COUNT_IMPL(flag) \ + do { \ + } while (0) + +#define QUIC_RESTART_FLAG_COUNT_N_IMPL(flag, instance, total) \ + do { \ + } while (0) + +#define QUIC_CODE_COUNT_IMPL(name) \ + do { \ + } while (0) + +#define QUIC_CODE_COUNT_N_IMPL(name, instance, total) \ + do { \ + } while (0) diff --git a/source/extensions/quic_listeners/quiche/platform/quic_iovec_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_iovec_impl.h new file mode 100644 index 0000000000000..141f144c71352 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_iovec_impl.h @@ -0,0 +1,9 @@ +#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 diff --git a/source/extensions/quic_listeners/quiche/platform/quic_string_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_string_impl.h new file mode 100644 index 0000000000000..9370a02b1eb05 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_string_impl.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +// 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. + +namespace quic { + +using QuicStringImpl = std::string; + +} // namespace quic diff --git a/source/extensions/quic_listeners/quiche/platform/quic_string_piece_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_string_piece_impl.h new file mode 100644 index 0000000000000..a9033cd90fdb3 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/quic_string_piece_impl.h @@ -0,0 +1,15 @@ +#pragma once + +#include "absl/strings/string_view.h" + +// 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. + +namespace quic { + +using QuicStringPieceImpl = absl::string_view; + +} // namespace quic diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_arraysize_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_arraysize_impl.h new file mode 100644 index 0000000000000..2fb131122d70c --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_arraysize_impl.h @@ -0,0 +1,11 @@ +#pragma once + +#include "absl/base/macros.h" + +// 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 SPDY_ARRAYSIZE_IMPL(x) ABSL_ARRAYSIZE(x) diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_containers_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_containers_impl.h new file mode 100644 index 0000000000000..00c145d8381ad --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_containers_impl.h @@ -0,0 +1,46 @@ +#pragma once + +#include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" +#include "absl/container/inlined_vector.h" +#include "absl/hash/hash.h" + +// The following includes should be: +// +// #include "extensions/quic_listeners/quiche/platform/spdy_string_impl.h" +// #include "extensions/quic_listeners/quiche/platform/spdy_string_piece_impl.h" +// +// However, for some reason, bazel.clang_tidy cannot resolve the files when specified this way. +// TODO(mpw): fix includes to use full paths. +#include "spdy_string_impl.h" +#include "spdy_string_piece_impl.h" + +// 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. + +namespace spdy { + +template using SpdyHashImpl = absl::Hash; + +template > +using SpdyHashMapImpl = absl::flat_hash_map; + +template +using SpdyHashSetImpl = absl::flat_hash_set; + +// TODO: implement +template class SpdyLinkedHashMapImpl {}; + +template > +using SpdyInlinedVectorImpl = absl::InlinedVector; + +using SpdyStringPieceHashImpl = absl::Hash; + +inline size_t SpdyHashStringPairImpl(SpdyStringPieceImpl a, SpdyStringPieceImpl b) { + return absl::Hash>()(std::make_pair(a, b)); +} + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_endianness_util_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_endianness_util_impl.h new file mode 100644 index 0000000000000..f72c476b34f80 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_endianness_util_impl.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include + +// 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. + +namespace spdy { + +inline uint16_t SpdyNetToHost16Impl(uint16_t x) { return ntohs(x); } + +inline uint32_t SpdyNetToHost32Impl(uint32_t x) { return ntohl(x); } + +// TODO: implement +inline uint64_t SpdyNetToHost64Impl(uint64_t /*x*/) { return 0; } + +inline uint16_t SpdyHostToNet16Impl(uint16_t x) { return htons(x); } + +inline uint32_t SpdyHostToNet32Impl(uint32_t x) { return htonl(x); } + +// TODO: implement +inline uint64_t SpdyHostToNet64Impl(uint64_t /*x*/) { return 0; } + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_estimate_memory_usage_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_estimate_memory_usage_impl.h new file mode 100644 index 0000000000000..e8643b35f9cdf --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_estimate_memory_usage_impl.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +// 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. + +namespace spdy { + +// Dummy implementation. +template size_t SpdyEstimateMemoryUsageImpl(const T& /*object*/) { return 0; } + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_export_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_export_impl.h new file mode 100644 index 0000000000000..1b1c46a816964 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_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 SPDY_EXPORT +#define SPDY_EXPORT_PRIVATE diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_macros_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_macros_impl.h new file mode 100644 index 0000000000000..1cec4845b1e15 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_macros_impl.h @@ -0,0 +1,15 @@ +#pragma once + +#include "absl/base/attributes.h" + +// 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 SPDY_MUST_USE_RESULT_IMPL ABSL_MUST_USE_RESULT +#define SPDY_UNUSED_IMPL ABSL_ATTRIBUTE_UNUSED + +// TODO: implement +#define SPDY_DVLOG_IF_IMPL 0 diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_ptr_util_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_ptr_util_impl.h new file mode 100644 index 0000000000000..5613f12f5cff8 --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_ptr_util_impl.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "absl/memory/memory.h" + +// 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. + +namespace spdy { + +template std::unique_ptr SpdyMakeUniqueImpl(Args&&... args) { + return std::make_unique(std::forward(args)...); +} + +template std::unique_ptr SpdyWrapUniqueImpl(T* ptr) { + return absl::WrapUnique(ptr); +} + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_string_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_string_impl.h new file mode 100644 index 0000000000000..a1d5f9500d56e --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_string_impl.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +// 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. + +namespace spdy { + +using SpdyStringImpl = std::string; + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/spdy_string_piece_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_string_piece_impl.h new file mode 100644 index 0000000000000..46e9695bb7c0f --- /dev/null +++ b/source/extensions/quic_listeners/quiche/platform/spdy_string_piece_impl.h @@ -0,0 +1,15 @@ +#pragma once + +#include "absl/strings/string_view.h" + +// 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. + +namespace spdy { + +using SpdyStringPieceImpl = absl::string_view; + +} // namespace spdy diff --git a/source/extensions/quic_listeners/quiche/platform/http2_bug_tracker_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_test_helpers_impl.h similarity index 69% rename from source/extensions/quic_listeners/quiche/platform/http2_bug_tracker_impl.h rename to source/extensions/quic_listeners/quiche/platform/spdy_test_helpers_impl.h index e346ce2b7f266..fa0676be84e3b 100644 --- a/source/extensions/quic_listeners/quiche/platform/http2_bug_tracker_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/spdy_test_helpers_impl.h @@ -7,7 +7,4 @@ // porting layer for QUICHE. // TODO: implement - -#define HTTP2_BUG_IMPL 0 -#define HTTP2_BUG_IF_IMPL 0 -#define FLAGS_http2_always_log_bugs_for_tests_IMPL 0 +#define EXPECT_SPDY_BUG_IMPL 0 diff --git a/source/extensions/quic_listeners/quiche/platform/http2_mock_log_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_test_utils_prod_impl.h similarity index 61% rename from source/extensions/quic_listeners/quiche/platform/http2_mock_log_impl.h rename to source/extensions/quic_listeners/quiche/platform/spdy_test_utils_prod_impl.h index 1a5518165e586..70a00ad152175 100644 --- a/source/extensions/quic_listeners/quiche/platform/http2_mock_log_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/spdy_test_utils_prod_impl.h @@ -7,7 +7,4 @@ // porting layer for QUICHE. // TODO: implement - -#define CREATE_HTTP2_MOCK_LOG_IMPL(log) 0 -#define EXPECT_HTTP2_LOG_CALL_IMPL(log) 0 -#define EXPECT_HTTP2_LOG_CALL_CONTAINS_IMPL(log, level, content) 0 +#define SPDY_FRIEND_TEST_IMPL 0 diff --git a/source/extensions/quic_listeners/quiche/platform/http2_flags_impl.h b/source/extensions/quic_listeners/quiche/platform/spdy_unsafe_arena_impl.h similarity index 72% rename from source/extensions/quic_listeners/quiche/platform/http2_flags_impl.h rename to source/extensions/quic_listeners/quiche/platform/spdy_unsafe_arena_impl.h index d7c503ed95953..8db8e4a20bd44 100644 --- a/source/extensions/quic_listeners/quiche/platform/http2_flags_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/spdy_unsafe_arena_impl.h @@ -6,7 +6,9 @@ // consumed or referenced directly by other Envoy code. It serves purely as a // porting layer for QUICHE. +namespace spdy { + // TODO: implement +class SpdyUnsafeArenaImpl {}; -#define GetHttp2ReloadableFlagImpl(flag) 0 -#define SetHttp2ReloadableFlagImpl(flag, value) 0 +} // namespace spdy diff --git a/test/extensions/quic_listeners/quiche/platform/BUILD b/test/extensions/quic_listeners/quiche/platform/BUILD new file mode 100644 index 0000000000000..0c456774f7359 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/BUILD @@ -0,0 +1,40 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_fuzz_test", + "envoy_cc_test", + "envoy_cc_test_binary", + "envoy_cc_test_library", + "envoy_package", + "envoy_proto_library", +) + +envoy_package() + +envoy_cc_test( + name = "http2_platform_test", + srcs = ["http2_platform_test.cc"], + external_deps = ["quiche_http2_platform"], + deps = [ + "//test/test_common:utility_lib", + ], +) + +envoy_cc_test( + name = "quic_platform_test", + srcs = ["quic_platform_test.cc"], + external_deps = ["quiche_quic_platform"], + deps = [ + "//test/test_common:utility_lib", + ], +) + +envoy_cc_test( + name = "spdy_platform_test", + srcs = ["spdy_platform_test.cc"], + external_deps = ["quiche_spdy_platform"], + deps = [ + "//test/test_common:utility_lib", + ], +) diff --git a/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc new file mode 100644 index 0000000000000..788c0c53921ec --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/http2_platform_test.cc @@ -0,0 +1,66 @@ +#include + +#include "gtest/gtest.h" +#include "quiche/http2/platform/api/http2_arraysize.h" +#include "quiche/http2/platform/api/http2_containers.h" +#include "quiche/http2/platform/api/http2_estimate_memory_usage.h" +#include "quiche/http2/platform/api/http2_optional.h" +#include "quiche/http2/platform/api/http2_ptr_util.h" +#include "quiche/http2/platform/api/http2_string.h" +#include "quiche/http2/platform/api/http2_string_piece.h" + +// Basic tests to validate functioning of the QUICHE http2 platform +// implementation. For platform APIs in which the implementation is a simple +// typedef/passthrough to a std:: or absl:: construct, the tests are kept +// minimal, and serve primarily to verify the APIs compile and link without +// issue. + +namespace Envoy { +namespace Extensions { +namespace QuicListeners { +namespace Quiche { + +TEST(Http2PlatformTest, Http2Arraysize) { + int array[] = {0, 1, 2, 3, 4}; + EXPECT_EQ(5, HTTP2_ARRAYSIZE(array)); +} + +TEST(Http2PlatformTest, Http2Deque) { + http2::Http2Deque deque; + deque.push_back(10); + EXPECT_EQ(10, deque.back()); +} + +TEST(Http2PlatformTest, Http2EstimateMemoryUsage) { + http2::Http2String s = "foo"; + // Stubbed out to always return 0. + EXPECT_EQ(0, http2::Http2EstimateMemoryUsage(s)); +} + +TEST(Http2PlatformTest, Http2Optional) { + http2::Http2Optional opt; + EXPECT_FALSE(opt.has_value()); + opt = 3; + EXPECT_TRUE(opt.has_value()); +} + +TEST(Http2PlatformTest, Http2MakeUnique) { + auto p = http2::Http2MakeUnique(4); + EXPECT_EQ(4, *p); +} + +TEST(Http2PlatformTest, Http2String) { + http2::Http2String s = "foo"; + EXPECT_EQ('o', s[1]); +} + +TEST(Http2PlatformTest, Http2StringPiece) { + http2::Http2String s = "bar"; + http2::Http2StringPiece sp(s); + EXPECT_EQ('b', sp[0]); +} + +} // namespace Quiche +} // namespace QuicListeners +} // namespace Extensions +} // namespace Envoy diff --git a/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc new file mode 100644 index 0000000000000..97eaea162914f --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc @@ -0,0 +1,83 @@ +#include "gtest/gtest.h" +#include "quiche/quic/platform/api/quic_aligned.h" +#include "quiche/quic/platform/api/quic_arraysize.h" +#include "quiche/quic/platform/api/quic_containers.h" +#include "quiche/quic/platform/api/quic_endian.h" +#include "quiche/quic/platform/api/quic_estimate_memory_usage.h" +#include "quiche/quic/platform/api/quic_string.h" +#include "quiche/quic/platform/api/quic_string_piece.h" + +// Basic tests to validate functioning of the QUICHE quic platform +// implementation. For platform APIs in which the implementation is a simple +// typedef/passthrough to a std:: or absl:: construct, the tests are kept +// minimal, and serve primarily to verify the APIs compile and link without +// issue. + +namespace Envoy { +namespace Extensions { +namespace QuicListeners { +namespace Quiche { + +TEST(QuicPlatformTest, QuicAlignOf) { EXPECT_LT(0, QUIC_ALIGN_OF(int)); } + +TEST(QuicPlatformTest, QuicArraysize) { + int array[] = {0, 1, 2, 3, 4}; + EXPECT_EQ(5, QUIC_ARRAYSIZE(array)); +} + +TEST(QuicPlatformTest, QuicUnorderedMap) { + quic::QuicUnorderedMap umap; + umap.insert({"foo", 2}); + EXPECT_EQ(2, umap["foo"]); +} + +TEST(QuicPlatformTest, QuicUnorderedSet) { + quic::QuicUnorderedSet uset({"foo", "bar"}); + EXPECT_EQ(1, uset.count("bar")); + EXPECT_EQ(0, uset.count("qux")); +} + +TEST(QuicPlatformTest, QuicQueue) { + quic::QuicQueue queue; + queue.push(10); + EXPECT_EQ(10, queue.back()); +} + +TEST(QuicPlatformTest, QuicDeque) { + quic::QuicDeque deque; + deque.push_back(10); + EXPECT_EQ(10, deque.back()); +} + +TEST(QuicPlatformTest, QuicInlinedVector) { + quic::QuicInlinedVector vec; + vec.push_back(3); + EXPECT_EQ(3, vec[0]); +} + +TEST(QuicPlatformTest, QuicEndian) { + EXPECT_EQ(0x1234, quic::QuicEndian::NetToHost16(quic::QuicEndian::HostToNet16(0x1234))); + EXPECT_EQ(0x12345678, quic::QuicEndian::NetToHost32(quic::QuicEndian::HostToNet32(0x12345678))); +} + +TEST(QuicPlatformTest, QuicEstimateMemoryUsage) { + quic::QuicString s = "foo"; + // Stubbed out to always return 0. + EXPECT_EQ(0, quic::QuicEstimateMemoryUsage(s)); +} + +TEST(QuicPlatformTest, QuicString) { + quic::QuicString s = "foo"; + EXPECT_EQ('o', s[1]); +} + +TEST(QuicPlatformTest, QuicStringPiece) { + quic::QuicString s = "bar"; + quic::QuicStringPiece sp(s); + EXPECT_EQ('b', sp[0]); +} + +} // namespace Quiche +} // namespace QuicListeners +} // namespace Extensions +} // namespace Envoy diff --git a/test/extensions/quic_listeners/quiche/platform/spdy_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/spdy_platform_test.cc new file mode 100644 index 0000000000000..6567398a89769 --- /dev/null +++ b/test/extensions/quic_listeners/quiche/platform/spdy_platform_test.cc @@ -0,0 +1,77 @@ +#include + +#include "gtest/gtest.h" +#include "quiche/spdy/platform/api/spdy_arraysize.h" +#include "quiche/spdy/platform/api/spdy_containers.h" +#include "quiche/spdy/platform/api/spdy_endianness_util.h" +#include "quiche/spdy/platform/api/spdy_estimate_memory_usage.h" +#include "quiche/spdy/platform/api/spdy_ptr_util.h" +#include "quiche/spdy/platform/api/spdy_string.h" +#include "quiche/spdy/platform/api/spdy_string_piece.h" + +// Basic tests to validate functioning of the QUICHE spdy platform +// implementation. For platform APIs in which the implementation is a simple +// typedef/passthrough to a std:: or absl:: construct, the tests are kept +// minimal, and serve primarily to verofy the APIs compile and link without +// issue. + +namespace Envoy { +namespace Extensions { +namespace QuicListeners { +namespace Quiche { + +TEST(SpdyPlatformTest, SpdyArraysize) { + int array[] = {0, 1, 2, 3, 4}; + EXPECT_EQ(5, SPDY_ARRAYSIZE(array)); +} + +TEST(SpdyPlatformTest, SpdyHashMap) { + spdy::SpdyHashMap hmap; + hmap.insert({"foo", 2}); + EXPECT_EQ(2, hmap["foo"]); +} + +TEST(SpdyPlatformTest, SpdyHashSet) { + spdy::SpdyHashSet, + std::equal_to> + hset({"foo", "bar"}); + EXPECT_EQ(1, hset.count("bar")); + EXPECT_EQ(0, hset.count("qux")); +} + +TEST(SpdyPlatformTest, SpdyEndianness) { + EXPECT_EQ(0x1234, spdy::SpdyNetToHost16(spdy::SpdyHostToNet16(0x1234))); + EXPECT_EQ(0x12345678, spdy::SpdyNetToHost32(spdy::SpdyHostToNet32(0x12345678))); +} + +TEST(SpdyPlatformTest, SpdyEstimateMemoryUsage) { + spdy::SpdyString s = "foo"; + // Stubbed out to always return 0. + EXPECT_EQ(0, spdy::SpdyEstimateMemoryUsage(s)); +} + +TEST(SpdyPlatformTest, SpdyMakeUnique) { + auto p = spdy::SpdyMakeUnique(4); + EXPECT_EQ(4, *p); +} + +TEST(SpdyPlatformTest, SpdyWrapUnique) { + auto p = spdy::SpdyWrapUnique(new int(6)); + EXPECT_EQ(6, *p); +} + +TEST(SpdyPlatformTest, SpdyString) { + spdy::SpdyString s = "foo"; + EXPECT_EQ('o', s[1]); +} + +TEST(SpdyPlatformTest, SpdyStringPiece) { + spdy::SpdyString s = "bar"; + spdy::SpdyStringPiece sp(s); + EXPECT_EQ('b', sp[0]); +} + +} // namespace Quiche +} // namespace QuicListeners +} // namespace Extensions +} // namespace Envoy