test(libc): keep exception runtime assertions enabled in Release #1129

Merged
AaravMehta-07 merged 1 commit from upstream-pr/1129 into main 2026-10-08 05:19:44 +00:00
AaravMehta-07 commented 2026-10-07 13:20:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-07T13:20:13Z.


What

Keep the existing exception-runtime assertions active in Release builds by undefining NDEBUG before <cassert> in the test translation unit. No assertions, runtime code, CMake flags or other tests change.

CI configures Release, and GCC compiles this test with -O3 -DNDEBUG. That removes all 57 assert expressions. It also removes the pthread_create, pthread_join and waitpid calls inside them, so the test reports success without running its four exception worker threads or checking its termination/forced-unwind child statuses.

Tested

Linux x86-64 under Ubuntu 26.04/WSL2 (kernel 6.6.87.2), GCC 15.2.0, CMake 4.2.3, Ninja 1.13.2, Python 3.14.4. Vulkan execution tests use Mesa lavapipe.

  • Unchanged Release test passes, but preprocessed output shows the checks reduced to no-ops. strace confirms zero worker threads and zero child waits.
  • With this change, strace confirms four worker threads and three child waits; all existing checks pass. Clean Release exception_runtime passes ten consecutive runs.
  • Mutation check with the same -O3 -DNDEBUG flags: change the first destructor-count expectation from 1 to 0 in temporary test copies. Without this fix the wrong expectation passes (exit 0); with it the test aborts at that assertion (SIGABRT). The submitted assertions are unchanged.
  • Full clean Release build and patched libs target pass. After updating to e79c971f, full CTest runs 396 tests: 373 pass, 22 skip and one unrelated local failure. guest_errors also fails on unmodified e79c971f, at GuestErrors.cpp:30: it expects errno 13 after creating/joining a host thread, but errno is 22 here. A standalone native std::thread program with no AnyPS5 code reproduces 13 -> 22. This is outside this test-only change. Skips are unavailable write tracking and lavapipe subgroup capabilities; they are not counted as executed passes.
  • Supplementary Debug (-O0 -g) and RelWithDebInfo (-O2 -g -DNDEBUG) test-source builds both pass against the Release runtime.
cmake -S /mnt/d/Code/ps5 -B /home/aarav/anyps5-validation/build-exception-final -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DFFMPEG_PREBUILT_DIR=/home/aarav/anyps5-validation/build-baseline/externals/ffmpeg-9ac4cfd195f1
cmake --build /home/aarav/anyps5-validation/build-exception-final --target exception_runtime_tests --parallel 3
ctest --test-dir /home/aarav/anyps5-validation/build-exception-final -R '^exception_runtime$' --output-on-failure --timeout 30 --repeat until-fail:10
cmake --build /home/aarav/anyps5-validation/build-exception-final --parallel 3
cmake --build /home/aarav/anyps5-validation/build-exception-final --target libs --parallel 3
VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json GALLIUM_OVERRIDE_CPU_CAPS=avx ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir /home/aarav/anyps5-validation/build-exception-final --output-on-failure --timeout 120

The FFmpeg directory reuses only the upstream dependency package, not compiled project objects. Windows does not register this Unix-only test. macOS and commercial titles were not tested; no compatibility improvement is claimed.

AI assistance was used during investigation and implementation. The one-line diff was reviewed and validated with the existing tests and independent tracing/mutation checks.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none changed)
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4773249711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1129). Originally posted by [AaravMehta-07](https://github.com/AaravMehta-07) on 2026-10-07T13:20:13Z. --- ### What Keep the existing exception-runtime assertions active in Release builds by undefining `NDEBUG` before `<cassert>` in the test translation unit. No assertions, runtime code, CMake flags or other tests change. CI configures `Release`, and GCC compiles this test with `-O3 -DNDEBUG`. That removes all 57 `assert` expressions. It also removes the `pthread_create`, `pthread_join` and `waitpid` calls inside them, so the test reports success without running its four exception worker threads or checking its termination/forced-unwind child statuses. ### Tested Linux x86-64 under Ubuntu 26.04/WSL2 (kernel 6.6.87.2), GCC 15.2.0, CMake 4.2.3, Ninja 1.13.2, Python 3.14.4. Vulkan execution tests use Mesa lavapipe. - Unchanged Release test passes, but preprocessed output shows the checks reduced to no-ops. `strace` confirms zero worker threads and zero child waits. - With this change, `strace` confirms four worker threads and three child waits; all existing checks pass. Clean Release `exception_runtime` passes ten consecutive runs. - Mutation check with the same `-O3 -DNDEBUG` flags: change the first destructor-count expectation from 1 to 0 in temporary test copies. Without this fix the wrong expectation passes (exit 0); with it the test aborts at that assertion (SIGABRT). The submitted assertions are unchanged. - Full clean Release build and patched `libs` target pass. After updating to `e79c971f`, full CTest runs 396 tests: 373 pass, 22 skip and one unrelated local failure. `guest_errors` also fails on unmodified `e79c971f`, at `GuestErrors.cpp:30`: it expects errno 13 after creating/joining a host thread, but errno is 22 here. A standalone native `std::thread` program with no AnyPS5 code reproduces 13 -> 22. This is outside this test-only change. Skips are unavailable write tracking and lavapipe subgroup capabilities; they are not counted as executed passes. - Supplementary Debug (`-O0 -g`) and RelWithDebInfo (`-O2 -g -DNDEBUG`) test-source builds both pass against the Release runtime. ```sh cmake -S /mnt/d/Code/ps5 -B /home/aarav/anyps5-validation/build-exception-final -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DFFMPEG_PREBUILT_DIR=/home/aarav/anyps5-validation/build-baseline/externals/ffmpeg-9ac4cfd195f1 cmake --build /home/aarav/anyps5-validation/build-exception-final --target exception_runtime_tests --parallel 3 ctest --test-dir /home/aarav/anyps5-validation/build-exception-final -R '^exception_runtime$' --output-on-failure --timeout 30 --repeat until-fail:10 cmake --build /home/aarav/anyps5-validation/build-exception-final --parallel 3 cmake --build /home/aarav/anyps5-validation/build-exception-final --target libs --parallel 3 VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json GALLIUM_OVERRIDE_CPU_CAPS=avx ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir /home/aarav/anyps5-validation/build-exception-final --output-on-failure --timeout 120 ``` The FFmpeg directory reuses only the upstream dependency package, not compiled project objects. Windows does not register this Unix-only test. macOS and commercial titles were not tested; no compatibility improvement is claimed. AI assistance was used during investigation and implementation. The one-line diff was reviewed and validated with the existing tests and independent tracing/mutation checks. ### Checklist - [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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (none changed) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-07 13:55:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T13:55:07Z.


Confirmed independently on Linux (CachyOS, GCC, Release), at object level rather than from the source alone.

CI configures Release (-DCMAKE_BUILD_TYPE=Release, .github/workflows/build.yml:18), so GCC passes -DNDEBUG and the TU's asserts are removed at compile time. Built the registered target on main:

$ nm exception_runtime_tests.dir/__/__/tests/ExceptionRuntime.cpp.o | grep -E 'pthread_create|pthread_join|waitpid'
                 U fork

Only fork survives. The consequences are a little wider than "the assertions do not run":

Site On main (NDEBUG)
CheckThreads pthread_create/pthread_join are the assert operands, so no thread is created — ThreadTest never runs
CheckTerminate, CheckForcedUnwind fork() is a bare statement and survives, but waitpid(child, …) is inside an assert, so both children are forked and never reaped; the WEXITSTATUS checks are gone

So on main the Linux ctest test (exception_runtime, #26) reports success while exercising no threads and leaking two unreaped children per run.

With your one line applied, all three reappear:

$ nm … | grep -E 'pthread_create|pthread_join|waitpid'
                 U pthread_create
                 U pthread_join
                 U waitpid

The mechanism is exactly as you describe, and the fix restores the coverage the test was written for. One note, not a request: the side-effecting calls live inside assert, which is what makes the semantics depend on NDEBUG; moving the pthread_create/waitpid calls out and asserting on their results would make the test robust to the build type by construction.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6039478287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1129#issuecomment-6039478287). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-07T13:55:07Z. --- Confirmed independently on Linux (CachyOS, GCC, Release), at object level rather than from the source alone. CI configures `Release` (`-DCMAKE_BUILD_TYPE=Release`, `.github/workflows/build.yml:18`), so GCC passes `-DNDEBUG` and the TU's asserts are removed at compile time. Built the registered target on `main`: ``` $ nm exception_runtime_tests.dir/__/__/tests/ExceptionRuntime.cpp.o | grep -E 'pthread_create|pthread_join|waitpid' U fork ``` Only `fork` survives. The consequences are a little wider than "the assertions do not run": | Site | On `main` (NDEBUG) | | - | - | | `CheckThreads` | `pthread_create`/`pthread_join` are the assert operands, so **no thread is created** — `ThreadTest` never runs | | `CheckTerminate`, `CheckForcedUnwind` | `fork()` is a bare statement and survives, but `waitpid(child, …)` is inside an assert, so both children are **forked and never reaped**; the `WEXITSTATUS` checks are gone | So on `main` the Linux ctest test (`exception_runtime`, #26) reports success while exercising no threads and leaking two unreaped children per run. With your one line applied, all three reappear: ``` $ nm … | grep -E 'pthread_create|pthread_join|waitpid' U pthread_create U pthread_join U waitpid ``` The mechanism is exactly as you describe, and the fix restores the coverage the test was written for. One note, not a request: the side-effecting calls live *inside* `assert`, which is what makes the semantics depend on NDEBUG; moving the `pthread_create`/`waitpid` calls out and asserting on their results would make the test robust to the build type by construction.
Dextroid17 commented 2026-10-08 02:48:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T02:48:42Z.

Review: COMMENTED


Built it and demonstrated the change is not cosmetic — this one restores a test that could not fail.

The proof, both ways. Build type here is CMAKE_BUILD_TYPE=Release, so NDEBUG is defined and assert expands away. I added a deliberately false assertion to the test and built it twice:

pr-1129   (#undef NDEBUG) + assert(false)  →  rc=134  (Aborted, core dumped)
pr-1129^  (NDEBUG defined) + assert(false) →  rc=0    (ran and passed)

So without the change the file's 54 assert( calls were compiled out entirely: exception_runtime_tests passed in a Release build no matter what the exception runtime did. With it, the assertion fires. That is the whole difference between a test and a green tick, and it is why this is worth more than the two lines it touches.

The placement is the part that has to be right, and it is. #undef NDEBUG sits before #include <cassert>. After the include it would have had no effect, because <cassert> bakes assert's definition at inclusion time — so the two lines are in the only order that works.

After the change the test passes on its merits:

ctest -R ^exception_runtime$    →  1/1 Passed

54 live assertions against the exception runtime, all satisfied. That is a much stronger statement than the same command produced before.

I checked whether other tests share the problem, and none does. Eight files matched a naive assert( search, but a precise one — runtime assert( rather than static_assert( — leaves this file as the only one:

ExceptionRuntime.cpp    runtime asserts = 54   #undef NDEBUG = 1
(8 other matches were all static_assert, which NDEBUG does not touch)

So there is no follow-up list to hand anyone, which is the answer I wanted rather than a list of eight more files.

Nothing to change. A test that cannot fail is worse than a missing test, because it reports coverage that is not there.

This is a comment, not an approval — I have no merge rights here.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5450793736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1129#pullrequestreview-5450793736). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T02:48:42Z. **Review:** COMMENTED --- Built it and demonstrated the change is not cosmetic — this one restores a test that could not fail. **The proof, both ways.** Build type here is `CMAKE_BUILD_TYPE=Release`, so `NDEBUG` is defined and `assert` expands away. I added a deliberately false assertion to the test and built it twice: ``` pr-1129 (#undef NDEBUG) + assert(false) → rc=134 (Aborted, core dumped) pr-1129^ (NDEBUG defined) + assert(false) → rc=0 (ran and passed) ``` So without the change the file's **54** `assert(` calls were compiled out entirely: `exception_runtime_tests` passed in a Release build no matter what the exception runtime did. With it, the assertion fires. That is the whole difference between a test and a green tick, and it is why this is worth more than the two lines it touches. **The placement is the part that has to be right, and it is.** `#undef NDEBUG` sits **before** `#include <cassert>`. After the include it would have had no effect, because `<cassert>` bakes `assert`'s definition at inclusion time — so the two lines are in the only order that works. **After the change the test passes on its merits:** ``` ctest -R ^exception_runtime$ → 1/1 Passed ``` 54 live assertions against the exception runtime, all satisfied. That is a much stronger statement than the same command produced before. **I checked whether other tests share the problem, and none does.** Eight files matched a naive `assert(` search, but a precise one — runtime `assert(` rather than `static_assert(` — leaves this file as the only one: ``` ExceptionRuntime.cpp runtime asserts = 54 #undef NDEBUG = 1 (8 other matches were all static_assert, which NDEBUG does not touch) ``` So there is no follow-up list to hand anyone, which is the answer I wanted rather than a list of eight more files. Nothing to change. A test that cannot fail is worse than a missing test, because it reports coverage that is not there. This is a comment, not an approval — I have no merge rights here. Written with AI assistance.
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!1129
No description provided.