-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Harden binary fuse filter #5202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SirTyson
wants to merge
3
commits into
stellar:master
Choose a base branch
from
SirTyson:harden-binary-fuse-filter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+308
−46
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright 2026 Stellar Development Foundation and contributors. Licensed | ||
| // under the Apache License, Version 2.0. See the COPYING file at the root | ||
| // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| #include "test/CovMark.h" | ||
|
|
||
| #ifdef BUILD_TESTS | ||
| namespace stellar | ||
| { | ||
| CovMarks gCovMarks; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright 2026 Stellar Development Foundation and contributors. Licensed | ||
| // under the Apache License, Version 2.0. See the COPYING file at the root | ||
| // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| // Coverage marks: a lightweight mechanism for tests to assert that specific | ||
| // internal code paths were actually executed. Inspired by the "coverage marks" | ||
| // pattern from Ferrous Systems. | ||
| // | ||
| // Usage in production code: | ||
| // COVMARK_HIT(SOME_RARE_PATH); | ||
| // | ||
| // Usage in test code: | ||
| // COVMARK_CHECK_HIT_IN_CURR_SCOPE(SOME_RARE_PATH); | ||
| // // ... code that should trigger SOME_RARE_PATH ... | ||
| // | ||
| // The check-hit guard records the counter on construction and verifies it | ||
| // increased by scope exit. If the marked path was not hit, the test fails. | ||
|
|
||
| #include <array> | ||
| #include <atomic> | ||
| #include <cstdint> | ||
SirTyson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <exception> | ||
| #include <stdexcept> | ||
|
|
||
| #ifdef BUILD_TESTS | ||
| #include <fmt/format.h> | ||
| #endif | ||
|
|
||
| namespace stellar | ||
| { | ||
|
|
||
| // Each coverage mark is an enum value. Add new marks before COVMARK_COUNT. | ||
| enum CovMark : std::size_t | ||
| { | ||
| BINARY_FUSE_POPULATE_ERROR_RETRY = 0, | ||
| BINARY_FUSE_POPULATE_PEELING_FAILURE_RETRY, | ||
| BINARY_FUSE_DUPLICATE_REMOVAL, | ||
| COVMARK_COUNT // must be last | ||
| }; | ||
|
|
||
| #ifdef BUILD_TESTS | ||
|
|
||
| class CovMarks | ||
| { | ||
| std::array<std::atomic<std::uint64_t>, CovMark::COVMARK_COUNT> mCounters{}; | ||
|
|
||
| public: | ||
| void | ||
| hit(CovMark mark) | ||
| { | ||
| mCounters[mark].fetch_add(1, std::memory_order_relaxed); | ||
| } | ||
|
|
||
| std::uint64_t | ||
| get(CovMark mark) const | ||
| { | ||
| return mCounters[mark].load(std::memory_order_relaxed); | ||
| } | ||
|
|
||
| void | ||
| reset() | ||
| { | ||
| for (auto& c : mCounters) | ||
| { | ||
| c.store(0, std::memory_order_relaxed); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| extern CovMarks gCovMarks; | ||
|
|
||
| class CovMarkGuard | ||
| { | ||
| CovMark mMark; | ||
| std::uint64_t mValueOnEntry; | ||
| char const* mFile; | ||
| int mLine; | ||
| char const* mName; | ||
|
|
||
| public: | ||
| CovMarkGuard(CovMark mark, char const* file, int line, char const* name) | ||
| : mMark(mark) | ||
| , mValueOnEntry(gCovMarks.get(mark)) | ||
| , mFile(file) | ||
| , mLine(line) | ||
| , mName(name) | ||
| { | ||
| } | ||
|
|
||
| ~CovMarkGuard() noexcept(false) | ||
| { | ||
| if (std::uncaught_exceptions() == 0) | ||
| { | ||
| auto valueOnExit = gCovMarks.get(mMark); | ||
| if (valueOnExit <= mValueOnEntry) | ||
| { | ||
| throw std::runtime_error( | ||
| fmt::format("{}:{}: coverage mark '{}' was not hit during " | ||
| "this scope", | ||
| mFile, mLine, mName)); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define COVMARK_HIT(covmark) \ | ||
| ::stellar::gCovMarks.hit(::stellar::CovMark::covmark) | ||
|
|
||
| #define COVMARK_CHECK_HIT_IN_CURR_SCOPE(covmark) \ | ||
| ::stellar::CovMarkGuard _covMarkGuard_##covmark( \ | ||
| ::stellar::CovMark::covmark, __FILE__, __LINE__, #covmark) | ||
|
|
||
| #else // !BUILD_TESTS | ||
|
|
||
| #define COVMARK_HIT(covmark) ((void)0) | ||
| #define COVMARK_CHECK_HIT_IN_CURR_SCOPE(covmark) ((void)0) | ||
|
|
||
| #endif // BUILD_TESTS | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.