test(agc): replace the nothrow allocation forms in the test hooks #21336

Merged
chitters2004 merged 2 commits from upstream-pr/21336 into main 2026-11-27 22:57:02 +00:00
chitters2004 commented 2026-11-16 05:21:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-16T05:21:37Z.


What

Five AGC test files replace the global operator new and operator delete so they can count allocations or make one fail: tests/AllocationFailure.cpp (linked into agc_buffer_pool_tests, agc_reference_storage_tests, agc_snapshot_copy_failure_tests, agc_pipeline_cache_allocation_tests, agc_command_batch_failure_tests and agc_pipeline_queue_failure_tests), tests/DescriptorCacheFailure.cpp, tests/DepthSurfaceReuse.cpp (in agc_driver_graphics_tests, glibc only), tests/ShaderMemory.cpp and tests/execution/DrawAllocations.cpp. They route new to malloc and every delete to free. All but DrawAllocations.cpp leave operator new(std::size_t, const std::nothrow_t&) in place, and ShaderMemory.cpp replaces that one but not the matching nothrow delete.

std::stable_sort takes its temporary buffer through the nothrow new and gives it back through the sized delete. Without a sanitizer the library's nothrow new calls the replaced new, so both sides end in malloc and free. Under AddressSanitizer the nothrow new is the sanitizer's own and allocates from its heap, so the replaced delete hands that block to free and the run aborts with alloc-dealloc-mismatch (operator new vs free). #16753's retention test is the first to reach this under ASan, through the std::stable_sort in PlanVertexCopies.

Each set now also replaces the nothrow forms. The counting sets in DepthSurfaceReuse.cpp and ShaderMemory.cpp route the nothrow new through their counting new, so the census counts it. The failure-injection sets in AllocationFailure.cpp and DescriptorCacheFailure.cpp call malloc directly, so their countdowns still fail the same allocations. No set replaces an aligned delete, so the aligned forms stay paired with the sanitizer's. agc_reference_storage_tests and the depth surface reuse tests now start with a std::stable_sort over 1,024 elements, enough to take the temporary buffer.

Tested

Linux, GCC 13. Negative control, without the fix: tests/ReferenceStorage.cpp with the new sort check, Graphics/src/ReferenceStorage.cpp and tests/AllocationFailure.cpp, built from main with -fsanitize=address, abort in the new check with AddressSanitizer: alloc-dealloc-mismatch (operator new vs free). The stack goes through std::__stable_sort. With the fix the same build prints reference storage tests passed under ASan and without a sanitizer. Fork CI on this head (run 43803755473): the Linux lavapipe gate and Windows pass. Under ASan, 24 of 25 pass, among them agc_reference_storage with its new sort check and the agc_buffer_pool tests, with no alloc-dealloc-mismatch. The one failure is agc_graphics_profile_draw, which stops at its check that guest heap memory lies below 1 << 40, as it does on main under ASan (listed by #21121). That stop comes before the depth surface reuse tests, so their new sort check runs only in the non-ASan jobs. The test changes need no GPU: the depth surface reuse tests run on a mock device.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (test hooks only; the touched tests use mock devices)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5331544949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21336). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-11-16T05:21:37Z. --- ### What Five AGC test files replace the global `operator new` and `operator delete` so they can count allocations or make one fail: `tests/AllocationFailure.cpp` (linked into `agc_buffer_pool_tests`, `agc_reference_storage_tests`, `agc_snapshot_copy_failure_tests`, `agc_pipeline_cache_allocation_tests`, `agc_command_batch_failure_tests` and `agc_pipeline_queue_failure_tests`), `tests/DescriptorCacheFailure.cpp`, `tests/DepthSurfaceReuse.cpp` (in `agc_driver_graphics_tests`, glibc only), `tests/ShaderMemory.cpp` and `tests/execution/DrawAllocations.cpp`. They route `new` to `malloc` and every `delete` to `free`. All but `DrawAllocations.cpp` leave `operator new(std::size_t, const std::nothrow_t&)` in place, and `ShaderMemory.cpp` replaces that one but not the matching nothrow `delete`. `std::stable_sort` takes its temporary buffer through the nothrow `new` and gives it back through the sized `delete`. Without a sanitizer the library's nothrow `new` calls the replaced `new`, so both sides end in `malloc` and `free`. Under AddressSanitizer the nothrow `new` is the sanitizer's own and allocates from its heap, so the replaced `delete` hands that block to `free` and the run aborts with `alloc-dealloc-mismatch (operator new vs free)`. #16753's retention test is the first to reach this under ASan, through the `std::stable_sort` in `PlanVertexCopies`. Each set now also replaces the nothrow forms. The counting sets in `DepthSurfaceReuse.cpp` and `ShaderMemory.cpp` route the nothrow `new` through their counting `new`, so the census counts it. The failure-injection sets in `AllocationFailure.cpp` and `DescriptorCacheFailure.cpp` call `malloc` directly, so their countdowns still fail the same allocations. No set replaces an aligned `delete`, so the aligned forms stay paired with the sanitizer's. `agc_reference_storage_tests` and the depth surface reuse tests now start with a `std::stable_sort` over 1,024 elements, enough to take the temporary buffer. ### Tested Linux, GCC 13. Negative control, without the fix: `tests/ReferenceStorage.cpp` with the new sort check, `Graphics/src/ReferenceStorage.cpp` and `tests/AllocationFailure.cpp`, built from `main` with `-fsanitize=address`, abort in the new check with `AddressSanitizer: alloc-dealloc-mismatch (operator new vs free)`. The stack goes through `std::__stable_sort`. With the fix the same build prints `reference storage tests passed` under ASan and without a sanitizer. Fork CI on this head ([run 43803755473](https://github.com/chitters2004/AnyPS5/actions/runs/43803755473)): the Linux lavapipe gate and Windows pass. Under ASan, 24 of 25 pass, among them `agc_reference_storage` with its new sort check and the `agc_buffer_pool` tests, with no `alloc-dealloc-mismatch`. The one failure is `agc_graphics_profile_draw`, which stops at its check that guest heap memory lies below 1 << 40, as it does on `main` under ASan (listed by #21121). That stop comes before the depth surface reuse tests, so their new sort check runs only in the non-ASan jobs. The test changes need no GPU: the depth surface reuse tests run on a mock device. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (test hooks only; the touched tests use mock devices) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-16 05:43:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T05:43:20Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code and supplied CI report support merging.

What I ran

Reviewed head c8906fceb8c6e54e29be9595b066698d65a1bf38 using the prepared review materials and the pinned repository reader. No commands or tests were run.

Results

Check Result Note
Changed code review passed All five changed files read
Tests in this review not run CI results below are author reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests were not run in this review. The author reports Linux GCC 13 negative-control and fixed ASan runs, plus fork CI results; these were not independently verified. No changed files were excluded: all five files listed as reviewed in the manifest were read. review/files.json was not available as a review document.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5915518198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21336#pullrequestreview-5915518198). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T05:43:20Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code and supplied CI report support merging. ## What I ran Reviewed head `c8906fceb8c6e54e29be9595b066698d65a1bf38` using the prepared `review` materials and the pinned repository reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All five changed files read | | Tests in this review | not run | CI results below are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests were not run in this review. The author reports Linux GCC 13 negative-control and fixed ASan runs, plus fork CI results; these were not independently verified. No changed files were excluded: all five files listed as reviewed in the manifest were read. `review/files.json` was not available as a review document. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!21336
No description provided.