diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 21:11:25 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 21:11:25 +0100 |
| commit | 92da70ad6b56d3eccbd04a8bebb9fc5745c9f704 (patch) | |
| tree | f9b52b3f22cf00c569df8cef1e650936c5229441 /runtime/test/descriptor_table_test.cpp | |
| parent | 342d5672cc61327eb713a407b6a08748e1f06d38 (diff) | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Merge remote-tracking branch 'origin/main' into bindless-per-queue-retire
# Conflicts:
# runtime/src/vulkan_backend.h
Diffstat (limited to 'runtime/test/descriptor_table_test.cpp')
| -rw-r--r-- | runtime/test/descriptor_table_test.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/test/descriptor_table_test.cpp b/runtime/test/descriptor_table_test.cpp index 456abcc98..1d03dff27 100644 --- a/runtime/test/descriptor_table_test.cpp +++ b/runtime/test/descriptor_table_test.cpp | |||
| @@ -408,7 +408,49 @@ int test_erase_moves_no_other_entry() { | |||
| 408 | return 0; | 408 | return 0; |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | int test_unresolvable_hash_collision() { | ||
| 412 | DescriptorTable table(32); | ||
| 413 | std::array<DescriptorKey, 9> keys{}; | ||
| 414 | for (std::uint32_t i = 0; i < keys.size(); ++i) { | ||
| 415 | keys[i][0] = i; | ||
| 416 | // Invert the final FNV multiplication to make every complete hash zero. | ||
| 417 | std::uint32_t prefix = kFnvOffsetBasis; | ||
| 418 | for (int word = 0; word < 7; ++word) prefix = (prefix ^ keys[i][word]) * kFnvPrime; | ||
| 419 | keys[i][7] = prefix; | ||
| 420 | EXPECT(hash_descriptor_key(keys[i]) == 0); | ||
| 421 | } | ||
| 422 | for (std::uint32_t i = 0; i < 8; ++i) table.insert(keys[i], i + 1); | ||
| 423 | const auto before = table.build_gpu_buffer(); | ||
| 424 | bool rejected = false; | ||
| 425 | try { table.insert(keys[8], 9); } | ||
| 426 | catch (const std::length_error&) { rejected = true; } | ||
| 427 | EXPECT(rejected && table.size() == 8 && table.capacity() == 32); | ||
| 428 | EXPECT(table.build_gpu_buffer() == before); | ||
| 429 | for (std::uint32_t i = 0; i < 8; ++i) EXPECT(table.lookup(keys[i]) == i + 1); | ||
| 430 | EXPECT(table.insert_or_update(keys[0].data(), 99) == DescriptorTable::InsertResult::replaced); | ||
| 431 | EXPECT(table.lookup(keys[0]) == 99); | ||
| 432 | EXPECT(table.erase(keys[0])); | ||
| 433 | EXPECT(table.insert(keys[8], 9) && table.lookup(keys[8]) == 9); | ||
| 434 | return 0; | ||
| 435 | } | ||
| 436 | |||
| 437 | int test_capacity_overflow() { | ||
| 438 | for (std::uint32_t requested : {0x80000001u, 0xffffffffu}) { | ||
| 439 | bool rejected = false; | ||
| 440 | try { DescriptorTable table(requested); } | ||
| 441 | catch (const std::length_error&) { rejected = true; } | ||
| 442 | EXPECT(rejected); | ||
| 443 | } | ||
| 444 | for (std::uint32_t requested : {0u, 1u, 16u, 17u, 31u, 32u}) { | ||
| 445 | DescriptorTable table(requested); | ||
| 446 | EXPECT(table.capacity() == (requested <= 16 ? 16 : 32)); | ||
| 447 | } | ||
| 448 | return 0; | ||
| 449 | } | ||
| 450 | |||
| 411 | int main() { | 451 | int main() { |
| 452 | EXPECT(test_unresolvable_hash_collision() == 0); | ||
| 453 | EXPECT(test_capacity_overflow() == 0); | ||
| 412 | EXPECT(test_fnv1a_hash_matches_contract() == 0); | 454 | EXPECT(test_fnv1a_hash_matches_contract() == 0); |
| 413 | EXPECT(test_ssharp_key_padding() == 0); | 455 | EXPECT(test_ssharp_key_padding() == 0); |
| 414 | EXPECT(test_basic_insertion_and_lookup() == 0); | 456 | EXPECT(test_basic_insertion_and_lookup() == 0); |