format src and tests with clang-format

This commit is contained in:
nmzik
2026-07-31 11:36:12 +02:00
parent 68be13345a
commit d8a4c83cc7
81 changed files with 19582 additions and 21405 deletions
+41 -24
View File
@@ -7,8 +7,8 @@
namespace {
using Owners = std::vector<uint32_t>;
using Table = Libs::Graphics::MultiLevelPageTable<Owners>;
using Owners = std::vector<uint32_t>;
using Table = Libs::Graphics::MultiLevelPageTable<Owners>;
using OwnerIndex = Libs::Graphics::MultiRangePageOwnerIndex<uint32_t>;
void Check(bool value, const char* text) {
@@ -24,23 +24,26 @@ void TestMultiOwnerAndExactErase() {
owners.push_back(11);
owners.push_back(22);
Check(table.Find(17) != nullptr && table.Find(17)->size() == 2, "both page owners are retained");
Check(table.Find(17) != nullptr && table.Find(17)->size() == 2,
"both page owners are retained");
Check(Libs::Graphics::EraseExact(owners, 11U), "registered owner is erased");
Check(owners.size() == 1 && owners.front() == 22, "erasing one owner preserves its neighbor");
Check(!Libs::Graphics::EraseExact(owners, 33U), "missing owner is reported without mutation");
}
void TestCrossBucketRange() {
Table::PageRange range{};
constexpr uint64_t bucket_boundary = uint64_t{Table::kBucketEntries} << Table::kPageBits;
Table::PageRange range {};
constexpr uint64_t bucket_boundary = uint64_t {Table::kBucketEntries} << Table::kPageBits;
Check(Table::TryGetPageRange(bucket_boundary - 1, 2, range), "cross-bucket range is valid");
Check(range.first == Table::kBucketEntries - 1 && range.last_exclusive == Table::kBucketEntries + 1,
Check(range.first == Table::kBucketEntries - 1 &&
range.last_exclusive == Table::kBucketEntries + 1,
"cross-bucket range covers both pages");
Table table;
table[range.first].push_back(1);
table[range.last_exclusive - 1].push_back(2);
Check(table.AllocatedBucketCount() == 2, "pages across the L1 boundary use distinct sparse buckets");
Check(table.AllocatedBucketCount() == 2,
"pages across the L1 boundary use distinct sparse buckets");
}
void TestQueriesDoNotAllocate() {
@@ -55,27 +58,34 @@ void TestQueriesDoNotAllocate() {
}
void TestAddressSpaceBoundaries() {
Table::PageRange range{};
Check(Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 1, range), "last guest byte is valid");
Table::PageRange range {};
Check(Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 1, range),
"last guest byte is valid");
Check(range.first == Table::kPageCount - 1 && range.last_exclusive == Table::kPageCount,
"last guest byte maps to the final page");
Check(!Table::TryGetPageRange(0, 0, range), "empty ranges are rejected");
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize, 1, range), "first out-of-range byte is rejected");
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 2, range), "crossing the address-space end is rejected");
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize, 1, range),
"first out-of-range byte is rejected");
Check(!Table::TryGetPageRange(Table::kAddressSpaceSize - 1, 2, range),
"crossing the address-space end is rejected");
Check(!Table::TryGetPageRange(UINT64_MAX - 1, 4, range), "wrapping input is rejected");
Table table;
table.GetOrCreate(Table::kPageCount - 1).push_back(99);
Check(table.Find(Table::kPageCount - 1) != nullptr && table.Find(Table::kPageCount - 1)->front() == 99,
Check(table.Find(Table::kPageCount - 1) != nullptr &&
table.Find(Table::kPageCount - 1)->front() == 99,
"final page supports allocating and nonallocating access");
}
void TestMultiRangeRegistrationDeduplicatesPages() {
OwnerIndex index;
// Depth and stencil-like planes overlap tracking pages and share one 1 MiB bucket.
Check(index.Register(7, {{0x101000, 0x2800}, {0x102000, 0x3000}}), "multi-range owner registers");
Check(index.CoarseMembershipCount(1) == 1, "one owner is inserted once in a shared 1 MiB bucket");
Check(index.TrackingMembershipCount(0x102) == 1, "overlapping planes insert one 4 KiB membership");
Check(index.Register(7, {{0x101000, 0x2800}, {0x102000, 0x3000}}),
"multi-range owner registers");
Check(index.CoarseMembershipCount(1) == 1,
"one owner is inserted once in a shared 1 MiB bucket");
Check(index.TrackingMembershipCount(0x102) == 1,
"overlapping planes insert one 4 KiB membership");
Check(!index.Register(7, {{0x101000, 0x1000}}), "duplicate owner registration hard-fails");
const auto owners = index.Query(0x100000, 0x10000);
@@ -83,9 +93,10 @@ void TestMultiRangeRegistrationDeduplicatesPages() {
}
void TestSharedPageUnregisterLifecycle() {
OwnerIndex index;
const std::vector<OwnerIndex::ByteRange> ranges{{0x202000, 0x2000}};
Check(index.Register(11, ranges) && index.Register(22, ranges), "two owners register on identical pages");
OwnerIndex index;
const std::vector<OwnerIndex::ByteRange> ranges {{0x202000, 0x2000}};
Check(index.Register(11, ranges) && index.Register(22, ranges),
"two owners register on identical pages");
Check(index.CoarseMembershipCount(2) == 2 && index.TrackingMembershipCount(0x202) == 2,
"coarse and tracking pages retain both owners");
@@ -97,7 +108,8 @@ void TestSharedPageUnregisterLifecycle() {
Check(!index.Unregister(11, releases), "missing membership hard-fails without mutation");
Check(index.Unregister(22, releases), "final owner unregisters");
Check(releases.size() == 1 && releases.front().address == 0x202000 && releases.front().size == 0x2000,
Check(releases.size() == 1 && releases.front().address == 0x202000 &&
releases.front().size == 0x2000,
"adjacent final-owner tracking pages return one contiguous release");
}
@@ -105,14 +117,19 @@ void TestStrictByteFilteringAndPredicate() {
OwnerIndex index;
Check(index.Register(31, {{0x300100, 0x100}}), "first byte-disjoint owner registers");
Check(index.Register(32, {{0x300800, 0x100}}), "second byte-disjoint owner registers");
Check(index.TrackingMembershipCount(0x300) == 2, "byte-disjoint owners share one tracking page");
Check(index.TrackingMembershipCount(0x300) == 2,
"byte-disjoint owners share one tracking page");
Check(index.Query(0x300400, 0x40).empty(), "page hit without byte overlap is filtered out");
const auto page_candidates = index.QueryCandidates(0x300400, 0x40);
Check(page_candidates.size() == 2, "fault candidate query retains byte-disjoint owners on the touched page");
Check(page_candidates.size() == 2,
"fault candidate query retains byte-disjoint owners on the touched page");
const auto first = index.Query(0x300180, 0x10);
Check(first.size() == 1 && first.front() == 31, "strict byte overlap selects only the matching owner");
const auto predicate_filtered = index.Query(0x300000, 0x1000, [](uint32_t owner) { return owner == 32; });
Check(predicate_filtered.size() == 1 && predicate_filtered.front() == 32, "supplied predicate filters query owners");
Check(first.size() == 1 && first.front() == 31,
"strict byte overlap selects only the matching owner");
const auto predicate_filtered =
index.Query(0x300000, 0x1000, [](uint32_t owner) { return owner == 32; });
Check(predicate_filtered.size() == 1 && predicate_filtered.front() == 32,
"supplied predicate filters query owners");
}
} // namespace