test(libc): cover multi-cycle getopt argument permutation #16434

Closed
ahmadmuj wants to merge 1 commit from upstream-pr/16434 into main
ahmadmuj commented 2026-11-06 17:32:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T17:32:56Z.


What

Add a standalone regression for stable getopt_long permutation with two operands and four option/value words. This requires two rotation cycles; existing cases exercise one cycle.

The fixture checks r, r, -1, argument pointer identity, optind values 5, 7, 5, the option index, final null optarg, all eight final pointers, and unchanged strings. It uses distinct writable strings, a final null argv slot, guest environment restoration, and a separate test process.

The contract is FreeBSD 11.4 getopt_long.c at 8c639945a44588f6cfdddfb057bb5aad88735da0, already cited by the library's debt entry. No production defect or console behavior is claimed. Production and the existing fixture stay unchanged.

Tested

CPU only: Intel Core i7-13700K, Ubuntu 24.04, x86-64 WSL2, kernel 6.18.33.2-microsoft-standard-WSL2, GCC 13.3.0, Release.
Base: 9fb6149d12d51e8dc769943c828f2f23635acb4d. Head: 1db991429d152a634407efe0c3ea509381f0ed9e.

Fresh main edf71e7244ee064ff43f70eb1b9657379aa3cf37 changes only Zlib files. A merge preview is clean; it is not an integration test.

Separate source snapshots match every tracked file of those revisions. Configure, build and test use a clean environment with GIT_CEILING_DIRECTORIES set above the snapshots. Generated revision metadata is empty because these snapshots have no Git metadata; archive comparisons establish the pins. Dependencies match the pinned submodules.

Commands ($src and $build select each revision's isolated paths):

cmake -S "$src" -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DFFMPEG_PREBUILT_DIR=/home/ahmad/work/anyps5/builds/main/externals/ffmpeg-9ac4cfd195f1
cmake --build "$build" --target guest_getopt_tests -j 8
ctest --test-dir "$build" -R '^guest_getopt$' -V --timeout 20
cmake --build "$build" --target guest_getopt_tests guest_getopt_permutation_cycles_tests -j 8
ctest --test-dir "$build" -R '^guest_getopt(_permutation_cycles)?$' -V --timeout 20
python3 tools/check_conventions.py --base origin/main
python3 tools/public_headers_manifest.py
python3 core/libs/tests/test_public_headers.py --audit-only
python3 tools/pr_overlap.py --branch fix/anyps5-getopt-permutation-cycles-regression --repo boykopovar/AnyPS5

The first target/test pair runs on main. Both targets run on head; head configuration also enables CMAKE_EXPORT_COMPILE_COMMANDS.

  • Main: existing test passes. Head: both tests pass.
  • Mutation in the isolated head snapshot: change production Gcd(nonOptions, options) to 1. The old test still passes; the new test fails at stable pointer order.
  • Restore production, rebuild, rerun both: pass. All ten recorded source, module and executable hashes match baseline. Both test executables stay byte-identical during the mutation.
  • Loader trace confirms the actual libSceLibcInternal, libc, and libkernel modules from this build.
  • Each test finishes below 0.02 seconds; CTest timeout is 20 seconds.
  • Conventions and public-header checks pass.
  • Branch overlap exits 2. Manual checks clear #5021, #13486, #13778, #14837, #15581, #15711 and #15715: each changes separate sources or targets. #13782, #16343 and #16356 append separate CMake targets at the same location. These are text insertion conflicts, with no shared fixture, test, function or export. Both blocks can be retained when resolving them.

Windows, full-suite CI, games, consoles and GPUs are not tested. Full CI needs a maintainer to start it.

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 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5191995416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16434). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T17:32:56Z. --- ### What Add a standalone regression for stable `getopt_long` permutation with two operands and four option/value words. This requires two rotation cycles; existing cases exercise one cycle. The fixture checks `r, r, -1`, argument pointer identity, `optind` values `5, 7, 5`, the option index, final null `optarg`, all eight final pointers, and unchanged strings. It uses distinct writable strings, a final null argv slot, guest environment restoration, and a separate test process. The contract is FreeBSD 11.4 [getopt_long.c at 8c639945a44588f6cfdddfb057bb5aad88735da0](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdlib/getopt_long.c#L149-L184), already cited by the library's debt entry. No production defect or console behavior is claimed. Production and the existing fixture stay unchanged. ### Tested CPU only: Intel Core i7-13700K, Ubuntu 24.04, x86-64 WSL2, kernel `6.18.33.2-microsoft-standard-WSL2`, GCC 13.3.0, Release. Base: `9fb6149d12d51e8dc769943c828f2f23635acb4d`. Head: `1db991429d152a634407efe0c3ea509381f0ed9e`. Fresh main `edf71e7244ee064ff43f70eb1b9657379aa3cf37` changes only Zlib files. A merge preview is clean; it is not an integration test. Separate source snapshots match every tracked file of those revisions. Configure, build and test use a clean environment with `GIT_CEILING_DIRECTORIES` set above the snapshots. Generated revision metadata is empty because these snapshots have no Git metadata; archive comparisons establish the pins. Dependencies match the pinned submodules. Commands (`$src` and `$build` select each revision's isolated paths): ```sh cmake -S "$src" -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DFFMPEG_PREBUILT_DIR=/home/ahmad/work/anyps5/builds/main/externals/ffmpeg-9ac4cfd195f1 cmake --build "$build" --target guest_getopt_tests -j 8 ctest --test-dir "$build" -R '^guest_getopt$' -V --timeout 20 cmake --build "$build" --target guest_getopt_tests guest_getopt_permutation_cycles_tests -j 8 ctest --test-dir "$build" -R '^guest_getopt(_permutation_cycles)?$' -V --timeout 20 python3 tools/check_conventions.py --base origin/main python3 tools/public_headers_manifest.py python3 core/libs/tests/test_public_headers.py --audit-only python3 tools/pr_overlap.py --branch fix/anyps5-getopt-permutation-cycles-regression --repo boykopovar/AnyPS5 ``` The first target/test pair runs on main. Both targets run on head; head configuration also enables `CMAKE_EXPORT_COMPILE_COMMANDS`. - Main: existing test passes. Head: both tests pass. - Mutation in the isolated head snapshot: change production `Gcd(nonOptions, options)` to `1`. The old test still passes; the new test fails at `stable pointer order`. - Restore production, rebuild, rerun both: pass. All ten recorded source, module and executable hashes match baseline. Both test executables stay byte-identical during the mutation. - Loader trace confirms the actual `libSceLibcInternal`, `libc`, and `libkernel` modules from this build. - Each test finishes below 0.02 seconds; CTest timeout is 20 seconds. - Conventions and public-header checks pass. - Branch overlap exits 2. Manual checks clear #5021, #13486, #13778, #14837, #15581, #15711 and #15715: each changes separate sources or targets. #13782, #16343 and #16356 append separate CMake targets at the same location. These are text insertion conflicts, with no shared fixture, test, function or export. Both blocks can be retained when resolving them. Windows, full-suite CI, games, consoles and GPUs are not tested. Full CI needs a maintainer to start it. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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) - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->

Pull request closed

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!16434
No description provided.