Add QuicheCodeCountReader platform API and verify BalsaFrame defect code counters Adds a test-only QUICHE platform API, `QuicheCodeCountReader`, for reading back `QUICHE_CODE_COUNT` increments in unit tests. Changes: - The platform API provides: - `IsSupported()`: returns true on platforms that record `QUICHE_CODE_COUNT` (e.g., GFE), and false on platforms where it is a no-op (Chromium, Envoy, and the default platform implementation). - `Delta(name)`: returns the number of times `QUICHE_CODE_COUNT(name)` fired since reader construction or since the previous query for that counter. Embedders can provide `quiche_platform_impl/quiche_code_count_reader_impl.h` or forward to `quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h`. PiperOrigin-RevId: 1013202795
diff --git a/build/source_list.bzl b/build/source_list.bzl index 112345b..19884fc 100644 --- a/build/source_list.bzl +++ b/build/source_list.bzl
@@ -793,6 +793,7 @@ "quic/tools/web_transport_only_backend.cc", ] quiche_test_support_hdrs = [ + "common/platform/api/quiche_code_count_reader.h", "common/platform/api/quiche_expect_bug.h", "common/platform/api/quiche_fuzztest.h", "common/platform/api/quiche_test.h", @@ -1570,6 +1571,7 @@ "common/platform/default/quiche_platform_impl/quiche_file_utils_impl.cc", ] default_platform_impl_test_support_hdrs = [ + "common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h", "common/platform/default/quiche_platform_impl/quiche_expect_bug_impl.h", "common/platform/default/quiche_platform_impl/quiche_fuzztest_impl.h", "common/platform/default/quiche_platform_impl/quiche_test_impl.h",
diff --git a/build/source_list.gni b/build/source_list.gni index 6bd751a..1bece2a 100644 --- a/build/source_list.gni +++ b/build/source_list.gni
@@ -793,6 +793,7 @@ "src/quiche/quic/tools/web_transport_only_backend.cc", ] quiche_test_support_hdrs = [ + "src/quiche/common/platform/api/quiche_code_count_reader.h", "src/quiche/common/platform/api/quiche_expect_bug.h", "src/quiche/common/platform/api/quiche_fuzztest.h", "src/quiche/common/platform/api/quiche_test.h", @@ -1576,6 +1577,7 @@ "src/quiche/common/platform/default/quiche_platform_impl/quiche_file_utils_impl.cc", ] default_platform_impl_test_support_hdrs = [ + "src/quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h", "src/quiche/common/platform/default/quiche_platform_impl/quiche_expect_bug_impl.h", "src/quiche/common/platform/default/quiche_platform_impl/quiche_fuzztest_impl.h", "src/quiche/common/platform/default/quiche_platform_impl/quiche_test_impl.h",
diff --git a/build/source_list.json b/build/source_list.json index ac4184e..145389c 100644 --- a/build/source_list.json +++ b/build/source_list.json
@@ -792,6 +792,7 @@ "quiche/quic/tools/web_transport_only_backend.cc" ], "quiche_test_support_hdrs": [ + "quiche/common/platform/api/quiche_code_count_reader.h", "quiche/common/platform/api/quiche_expect_bug.h", "quiche/common/platform/api/quiche_fuzztest.h", "quiche/common/platform/api/quiche_test.h", @@ -1575,6 +1576,7 @@ "quiche/common/platform/default/quiche_platform_impl/quiche_file_utils_impl.cc" ], "default_platform_impl_test_support_hdrs": [ + "quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h", "quiche/common/platform/default/quiche_platform_impl/quiche_expect_bug_impl.h", "quiche/common/platform/default/quiche_platform_impl/quiche_fuzztest_impl.h", "quiche/common/platform/default/quiche_platform_impl/quiche_test_impl.h",
diff --git a/quiche/common/platform/api/quiche_code_count_reader.h b/quiche/common/platform/api/quiche_code_count_reader.h new file mode 100644 index 0000000..46428b0 --- /dev/null +++ b/quiche/common/platform/api/quiche_code_count_reader.h
@@ -0,0 +1,46 @@ +// Copyright 2026 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_CODE_COUNT_READER_H_ +#define QUICHE_COMMON_PLATFORM_API_QUICHE_CODE_COUNT_READER_H_ + +#include <cstdint> + +#include "quiche_platform_impl/quiche_code_count_reader_impl.h" + +#include "absl/strings/string_view.h" +#include "quiche/common/platform/api/quiche_export.h" + +namespace quiche::test { + +// Test-only helper for verifying that QUICHE_CODE_COUNT(name) was hit. +// +// QUICHE_CODE_COUNT is a no-op on many platforms (e.g. Chromium, Envoy and the +// default platform implementation). On those platforms IsSupported() returns +// false, and Delta() must not be called. Tests should check IsSupported() +// before querying code counts. +class QUICHE_NO_EXPORT QuicheCodeCountReader { + public: + QuicheCodeCountReader() = default; + QuicheCodeCountReader(const QuicheCodeCountReader&) = delete; + QuicheCodeCountReader& operator=(const QuicheCodeCountReader&) = delete; + + // Returns true if the platform records QUICHE_CODE_COUNT invocations and the + // values returned by Delta() are meaningful. + static bool IsSupported() { return QuicheCodeCountReaderImpl::IsSupported(); } + + // Returns the number of times QUICHE_CODE_COUNT(name) (or QUICHE_CODE_COUNT_N + // when passed the full name such as "name_1_of_2") has fired since this + // reader was constructed, or since the previous call to Delta() with the + // same `name`, whichever is later. Returns 0 if the code point was never hit. + // Must not be called when IsSupported() returns false. + int64_t Delta(absl::string_view name) { return impl_.Delta(name); } + + private: + QuicheCodeCountReaderImpl impl_; +}; + +} // namespace quiche::test + +#endif // QUICHE_COMMON_PLATFORM_API_QUICHE_CODE_COUNT_READER_H_
diff --git a/quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h b/quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h new file mode 100644 index 0000000..ca9585d --- /dev/null +++ b/quiche/common/platform/default/quiche_platform_impl/quiche_code_count_reader_impl.h
@@ -0,0 +1,30 @@ +// Copyright 2026 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_CODE_COUNT_READER_IMPL_H_ +#define QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_CODE_COUNT_READER_IMPL_H_ + +#include <cstdint> + +#include "absl/strings/string_view.h" +#include "quiche/common/platform/api/quiche_export.h" + +namespace quiche::test { + +// The default platform implements QUICHE_CODE_COUNT as a no-op, so there is +// nothing to read back. +class QUICHE_NO_EXPORT QuicheCodeCountReaderImpl { + public: + QuicheCodeCountReaderImpl() = default; + QuicheCodeCountReaderImpl(const QuicheCodeCountReaderImpl&) = delete; + QuicheCodeCountReaderImpl& operator=(const QuicheCodeCountReaderImpl&) = + delete; + + static bool IsSupported() { return false; } + int64_t Delta(absl::string_view /*name*/) { return 0; } +}; + +} // namespace quiche::test + +#endif // QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_CODE_COUNT_READER_IMPL_H_