feat(libSceNpCommon): implement sce::np::Time #12859

Merged
hypermoist merged 6 commits from upstream-pr/12859 into main 2026-11-01 02:24:45 +00:00
hypermoist commented 2026-10-29 12:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-29T12:59:05Z.


What

Implements all 35 exports of sce::np::Time from libSceNpCommon.sprx of firmware 13.60 (read from disassembly, not measured on a console):

  • 6 were NotImplemented stubs with placeholder int (void) declarations;
  • 29 are exported by the module but were missing from AnyPS5.

sce::np::Time is a wrapper around a single 64-bit SceRtcTick, so Api.hpp declares using NpTime = RtcTick;. The code sits in Runtime.cpp next to sceNpRtcConvertToPosixTime, which it uses.

  • Clocks: GetUserClock, GetNetworkClock and GetDebugNetworkClock(Time*) call sceRtcGetCurrentTick, …NetworkTick and …DebugNetworkTick on the time. On failure they set it to 0 and return the error; otherwise they return 0.
  • Date-time:
    • SetDateTime(const DateTime&) runs sceRtcGetTick on a copy of the date-time.
    • GetDateTime(DateTime*) runs sceRtcSetTick and copies the date-time out only on success.
    • ConvertToPosixTime(long*) forwards to sceNpRtcConvertToPosixTime.
    • Each returns the error or 0.
  • Arithmetic:
    • AddMicroSeconds, AddSeconds, AddMinutes, AddHours and AddDays(long) call the matching sceRtcTickAdd* on the time in place and return it.
    • So do operator+(const Time&) and operator+(const SceRtcTick&), through sceRtcTickAddTicks.
    • AddHours and AddDays pass their 64-bit count to the 32-bit libSceRtc parameter, so only the low 32 bits count, as in the module.
  • FormatRFC3339(char*, size_t, int): a size below 0x80 returns 0x80558008 without formatting. Otherwise it calls sceRtcFormatRFC3339 and, on success, terminates the last byte.
  • Timeouts: IsTimedoutSinceMicroSeconds(const Time& since, long, long*), its (unsigned, unsigned*) form and IsTimedoutSinceSeconds(const Time&, long, long*). Each:
    • reports a timeout when now < since, when the timeout is negative, or when the elapsed time reaches the timeout;
    • writes the time left, or 0, through the optional pointer;
    • the seconds form compares in microseconds and divides the remainder by 10⁶.
  • Comparisons: the 18 ==, !=, <, <=, >, >= operators, for Time/Time, SceRtcTick/Time and Time/SceRtcTick, compare the ticks unsigned.

Gap (debt entry): where the module asserts and calls sceNpPanic after a failed libSceRtc add, the Add* helpers and operator+ throw std::invalid_argument. The debt file drops the six "signature unknown" entries.

Tested

Linux (CachyOS, GCC 16.2, Release): ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed. GuestNpCommonRtc.cpp now covers, against this tree's libSceRtc:

  • the user clock;
  • a date-time round trip and the POSIX conversion;
  • every Add*, including the 32-bit AddHours count, and both operator+;
  • comparisons across the sign bit;
  • each timeout form at its boundary;
  • the RFC 3339 size check and terminator.

Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran the exports under unicorn (x86-64 emulation on a PC, not a console).

  • Pure functions, differential: 16,200 cases.
    • The 18 comparisons get 400 tick pairs each, including equal and adjacent ticks, 0, 2^63 and 2^64 - 1.
    • The three timeout forms get 3,000 cases each: now before, at and after since, and timeouts at, around and far from the elapsed time (negative, 2^63, and the 32-bit edges for the unsigned form), with and without the out pointer.
    • Recorded: the result and the time left.
    • Replaying the same cases through this implementation gives 0 mismatches. 30 corrupted expectations give 30 mismatches.
  • Rtc wrappers: the module's libSceRtc imports were bound to recording handlers that return 0, a positive value and an error. The module behaves as described above in each case:
    • the arguments it passes, including AddHours passing the untruncated 64-bit count;
    • which results it maps to 0;
    • zeroing the clock on failure, and copying the date-time only on success;
    • skipping the call for a short RFC 3339 buffer and terminating the last byte on success.

The generator and harness are np_time_make_cases.py / np_time_replay.cpp in https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output.

Windows not built. Not run on a console.

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. Removing its stubs touches lines next to the stubs #12818, #12823, #12836, #12839 and #12852 remove, so whichever lands later needs a trivial rebase; I will do it on this side. It merges cleanly with #11601.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5068442344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12859). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-29T12:59:05Z. --- ### What Implements all 35 exports of `sce::np::Time` from `libSceNpCommon.sprx` of firmware 13.60 (read from disassembly, not measured on a console): - 6 were `NotImplemented` stubs with placeholder `int (void)` declarations; - 29 are exported by the module but were missing from AnyPS5. `sce::np::Time` is a wrapper around a single 64-bit `SceRtcTick`, so `Api.hpp` declares `using NpTime = RtcTick;`. The code sits in `Runtime.cpp` next to `sceNpRtcConvertToPosixTime`, which it uses. - **Clocks:** `GetUserClock`, `GetNetworkClock` and `GetDebugNetworkClock(Time*)` call `sceRtcGetCurrentTick`, `…NetworkTick` and `…DebugNetworkTick` on the time. On failure they set it to 0 and return the error; otherwise they return 0. - **Date-time:** - `SetDateTime(const DateTime&)` runs `sceRtcGetTick` on a copy of the date-time. - `GetDateTime(DateTime*)` runs `sceRtcSetTick` and copies the date-time out only on success. - `ConvertToPosixTime(long*)` forwards to `sceNpRtcConvertToPosixTime`. - Each returns the error or 0. - **Arithmetic:** - `AddMicroSeconds`, `AddSeconds`, `AddMinutes`, `AddHours` and `AddDays(long)` call the matching `sceRtcTickAdd*` on the time in place and return it. - So do `operator+(const Time&)` and `operator+(const SceRtcTick&)`, through `sceRtcTickAddTicks`. - `AddHours` and `AddDays` pass their 64-bit count to the 32-bit libSceRtc parameter, so only the low 32 bits count, as in the module. - **`FormatRFC3339(char*, size_t, int)`:** a size below 0x80 returns `0x80558008` without formatting. Otherwise it calls `sceRtcFormatRFC3339` and, on success, terminates the last byte. - **Timeouts:** `IsTimedoutSinceMicroSeconds(const Time& since, long, long*)`, its `(unsigned, unsigned*)` form and `IsTimedoutSinceSeconds(const Time&, long, long*)`. Each: - reports a timeout when `now < since`, when the timeout is negative, or when the elapsed time reaches the timeout; - writes the time left, or 0, through the optional pointer; - the seconds form compares in microseconds and divides the remainder by 10⁶. - **Comparisons:** the 18 `==`, `!=`, `<`, `<=`, `>`, `>=` operators, for `Time`/`Time`, `SceRtcTick`/`Time` and `Time`/`SceRtcTick`, compare the ticks unsigned. **Gap (debt entry):** where the module asserts and calls `sceNpPanic` after a failed libSceRtc add, the `Add*` helpers and `operator+` throw `std::invalid_argument`. The debt file drops the six "signature unknown" entries. ### Tested Linux (CachyOS, GCC 16.2, Release): `ctest --test-dir build -R 'np_common|public_headers' --output-on-failure`, 70/70 passed. `GuestNpCommonRtc.cpp` now covers, against this tree's libSceRtc: - the user clock; - a date-time round trip and the POSIX conversion; - every `Add*`, including the 32-bit `AddHours` count, and both `operator+`; - comparisons across the sign bit; - each timeout form at its boundary; - the RFC 3339 size check and terminator. **Comparison against the firmware code:** I relinked the 13.60 module with this repo's relinker and ran the exports under unicorn (x86-64 emulation on a PC, not a console). - **Pure functions, differential:** 16,200 cases. - The 18 comparisons get 400 tick pairs each, including equal and adjacent ticks, 0, `2^63` and `2^64 - 1`. - The three timeout forms get 3,000 cases each: `now` before, at and after `since`, and timeouts at, around and far from the elapsed time (negative, `2^63`, and the 32-bit edges for the `unsigned` form), with and without the out pointer. - Recorded: the result and the time left. - Replaying the same cases through this implementation gives **0 mismatches**. 30 corrupted expectations give 30 mismatches. - **Rtc wrappers:** the module's libSceRtc imports were bound to recording handlers that return 0, a positive value and an error. The module behaves as described above in each case: - the arguments it passes, including `AddHours` passing the untruncated 64-bit count; - which results it maps to 0; - zeroing the clock on failure, and copying the date-time only on success; - skipping the call for a short RFC 3339 buffer and terminating the last byte on success. The generator and harness are `np_time_make_cases.py` / `np_time_replay.cpp` in https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output. Windows not built. Not run on a console. ### 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. Removing its stubs touches lines next to the stubs #12818, #12823, #12836, #12839 and #12852 remove, so whichever lands later needs a trivial rebase; I will do it on this side. It merges cleanly with #11601. - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rooklz commented 2026-10-29 13:35:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T13:35:37Z.

Review: COMMENTED


Reviewed head bedde4268f on macOS 26 arm64 (Apple clang, C++20). The submodules aren't initialised here, so I couldn't build the full tree. Instead I built a standalone harness: this PR's Runtime.cpp block from sceNpRtcConvertToPosixTime to sceNpRtcFormatRFC3339 copied verbatim, this tree's libSceRtc/Export.cpp unchanged (it needs three small link shims: process params, title ID, NotImplemented) and GuestNpCommonRtc.cpp unchanged. Built with ASan+UBSan, it passes.

Checked:

  • git merge-tree against main 95137178d0 is clean, git diff --check is clean, and check_conventions --base upstream/main passes.
  • pr_overlap (1419 probed) reports only the stub-neighbour conflicts the body already lists: #12818, #12823, #12836, #12839, #12852. No other PR exports the same functions. #12866 has dropped its sce::np::Time operators (head 9533395d76), so the duplicate exports are gone.

Mutation testing: 46 single-line mutants of the new functions. The current test kills 12 and 34 survive:

  • every comparison operator except the few the test calls; for example ne(Time,Time) → ==, gt(Time,Time) → >=, a 32-bit eq, and a signed lt(Time,Tick) all pass;
  • GetNetworkClock/GetDebugNetworkClock reading the wrong clock;
  • now < since dropped from all three timeout forms;
  • the unsigned form truncating elapsed to 32 bits before comparing;
  • IsTimedoutSinceSeconds accepting a negative timeout, using < at the boundary, or comparing whole seconds;
  • AddDays not reaching the 32-bit count (only AddHours has that row).

The diff below adds rows only, about 50 lines in GuestNpCommonRtc.cpp. It runs every operator in all three forms over four pairs, including two ticks that are equal in their low 32 bits, plus clock, timeout, AddDays and invalid-date rows. It passes on this head and kills all 36 killable mutants. The 10 that still survive can't be distinguished on this tree:

  • this libSceRtc's getters and adds fail only on null pointers, so the paths for a failed clock, a failed add and a failed GetDateTime copy can't be reached;
  • it never returns positive values, so the positive-passthrough mutants match the original;
  • AddDays/AddHours without the cast narrow implicitly to the same int32_t;
  • one mutant was a no-op.

Please check against your unicorn differential:

  • IsTimedoutSinceSeconds(later, start, 1ll << 58): timeout * 1000000 wraps to 0 in uint64, so this head reports a timeout with 0 left. That row is what catches the whole-seconds mutant. If the module doesn't multiply with wrapping, drop the row or fix the expectation.
  • GetNetworkClock/GetDebugNetworkClock after sceRtcSetCurrent{Network,DebugNetwork}Tick: this tests this tree's libSceRtc together with your wrappers, not just the wrappers.
Test diff
--- a/core/libs/tests/GuestNpCommonRtc.cpp
+++ b/core/libs/tests/GuestNpCommonRtc.cpp
@@ -1,5 +1,6 @@
 #include "prx/libSceNpCommon/include/Api.hpp"
 #include "SceTypes.hpp"
+#include "prx/libSceRtc/include/Rtc.hpp"
 #include <cstdint>
 #include <cstdio>
 #include <cstdlib>
@@ -78,6 +79,56 @@
     CHECK(_ZNK3sce2np4Time13FormatRFC3339EPcmi(&epoch, text, sizeof(text) - 1, 0) == bufferTooSmall && text[0] == 'x');
     CHECK(_ZNK3sce2np4Time13FormatRFC3339EPcmi(&epoch, text, sizeof(text), 0) == 0 && std::strcmp(text, "1970-01-01T00:00:00.00Z") == 0
           && text[sizeof(text) - 1] == '\0');
+    const NpTime wrapLow{0};
+    const NpTime wrapHigh{~0ull};
+    CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_lPl(&wrapLow, &wrapHigh, 10, &remaining) && remaining == 0);
+    remainingShort = 7;
+    CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_jPj(&wrapLow, &wrapHigh, 10, &remainingShort) && remainingShort == 0);
+    CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&wrapLow, &wrapHigh, 10, &remaining) && remaining == 0);
+    const NpTime pastShort{unixEpochTick + 0x100000001ull};
+    CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_jPj(&pastShort, &start, 10, &remainingShort) && remainingShort == 0);
+    remaining = -1;
+    CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&later, &start, -1, &remaining) && remaining == 0);
+    const NpTime threeSeconds{unixEpochTick + 3000000};
+    CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&threeSeconds, &start, 3, &remaining) && remaining == 0);
+    CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&later, &start, 1ll << 58, &remaining) && remaining == 0);
+
+    time = epoch;
+    CHECK(_ZN3sce2np4Time7AddDaysEl(&time, 0x100000001ll) == &time && time.tick == unixEpochTick + 86400000000ull);
+
+    const RtcTick networkSet{unixEpochTick + 1000000000000ull};
+    const RtcTick debugSet{unixEpochTick + 2000000000000ull};
+    CHECK(sceRtcSetCurrentNetworkTick(&networkSet) == 0 && sceRtcSetCurrentDebugNetworkTick(&debugSet) == 0);
+    NpTime clock{0};
+    CHECK(_ZN3sce2np4Time15GetNetworkClockEPS1_(&clock) == 0 && clock.tick >= networkSet.tick && clock.tick < debugSet.tick);
+    CHECK(_ZN3sce2np4Time20GetDebugNetworkClockEPS1_(&clock) == 0 && clock.tick >= debugSet.tick);
+
+    const RtcDateTime badDay{1970, 2, 30, 0, 0, 0, 0};
+    time = epoch;
+    CHECK(_ZN3sce2np4Time11SetDateTimeERKNS0_8DateTimeE(&time, &badDay) < 0 && time.tick == unixEpochTick);
+
+    using Compare = bool (APS5_VABI*)(const NpTime*, const NpTime*);
+    const Compare same[] = {_ZN3sce2npeqERKNS0_4TimeES3_, _ZN3sce2npneERKNS0_4TimeES3_, _ZN3sce2npltERKNS0_4TimeES3_,
+                            _ZN3sce2npleERKNS0_4TimeES3_, _ZN3sce2npgtERKNS0_4TimeES3_, _ZN3sce2npgeERKNS0_4TimeES3_};
+    const Compare tickFirst[] = {_ZN3sce2npeqERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE,
+                                 _ZN3sce2npltERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npleERK10SceRtcTickRKNS0_4TimeE,
+                                 _ZN3sce2npgtERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npgeERK10SceRtcTickRKNS0_4TimeE};
+    const Compare timeFirst[] = {_ZN3sce2npeqERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npneERKNS0_4TimeERK10SceRtcTick,
+                                 _ZN3sce2npltERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npleERKNS0_4TimeERK10SceRtcTick,
+                                 _ZN3sce2npgtERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npgeERKNS0_4TimeERK10SceRtcTick};
+    const NpTime aliasLow{5 + 0x100000000ull};
+    const struct { const NpTime* lhs; const NpTime* rhs; bool expected[6]; } pairs[] = {
+        {&low, &high, {false, true, true, true, false, false}},
+        {&high, &low, {false, true, false, false, true, true}},
+        {&low, &step, {true, false, false, true, false, true}},
+        {&low, &aliasLow, {false, true, true, true, false, false}},
+    };
+    const Compare* const formSets[] = {same, tickFirst, timeFirst};
+    for (const Compare* forms : formSets) {
+        for (const auto& pair : pairs) {
+            for (int op = 0; op < 6; ++op) CHECK(forms[op](pair.lhs, pair.rhs) == pair.expected[op]);
+        }
+    }
     std::puts("NP common RTC tests passed");
     return 0;
 }

Nits (optional):

  • NP_TIME_RFC3339_SIZE duplicates the existing NP_RFC3339_BUFFER_MIN (0x80) in the same file. Time::FormatRFC3339 is the body of sceNpRtcFormatRFC3339 with the arguments reordered. If the module does the same thing, return sceNpRtcFormatRFC3339(text, size, self, timeZoneMinutes); would remove the copy.
  • The rows mutate the process-wide Network and DebugNetwork clocks. That's fine in this test binary, which is the only one in its process, but they need to stay after the GetUserClock row.

AI-assisted: yes (review, harness and mutation run).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5698560953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12859#pullrequestreview-5698560953). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T13:35:37Z. **Review:** COMMENTED --- Reviewed head `bedde4268f` on macOS 26 arm64 (Apple clang, C++20). The submodules aren't initialised here, so I couldn't build the full tree. Instead I built a standalone harness: this PR's `Runtime.cpp` block from `sceNpRtcConvertToPosixTime` to `sceNpRtcFormatRFC3339` copied verbatim, this tree's `libSceRtc/Export.cpp` unchanged (it needs three small link shims: process params, title ID, NotImplemented) and `GuestNpCommonRtc.cpp` unchanged. Built with ASan+UBSan, it **passes**. Checked: - `git merge-tree` against main `95137178d0` is clean, `git diff --check` is clean, and `check_conventions --base upstream/main` passes. - `pr_overlap` (1419 probed) reports only the stub-neighbour conflicts the body already lists: #12818, #12823, #12836, #12839, #12852. No other PR exports the same functions. #12866 has dropped its `sce::np::Time` operators (head `9533395d76`), so the duplicate exports are gone. **Mutation testing:** 46 single-line mutants of the new functions. The current test kills 12 and **34 survive**: - every comparison operator except the few the test calls; for example `ne`(Time,Time) → `==`, `gt`(Time,Time) → `>=`, a 32-bit `eq`, and a signed `lt`(Time,Tick) all pass; - `GetNetworkClock`/`GetDebugNetworkClock` reading the wrong clock; - `now < since` dropped from all three timeout forms; - the `unsigned` form truncating `elapsed` to 32 bits before comparing; - `IsTimedoutSinceSeconds` accepting a negative timeout, using `<` at the boundary, or comparing whole seconds; - `AddDays` not reaching the 32-bit count (only `AddHours` has that row). The diff below adds rows only, about 50 lines in `GuestNpCommonRtc.cpp`. It runs every operator in all three forms over four pairs, including two ticks that are equal in their low 32 bits, plus clock, timeout, `AddDays` and invalid-date rows. It passes on this head and kills all **36 killable mutants**. The 10 that still survive can't be distinguished on this tree: - this libSceRtc's getters and adds fail only on null pointers, so the paths for a failed clock, a failed add and a failed `GetDateTime` copy can't be reached; - it never returns positive values, so the positive-passthrough mutants match the original; - `AddDays`/`AddHours` without the cast narrow implicitly to the same `int32_t`; - one mutant was a no-op. Please check against your unicorn differential: - `IsTimedoutSinceSeconds(later, start, 1ll << 58)`: `timeout * 1000000` wraps to 0 in uint64, so this head reports a timeout with 0 left. That row is what catches the whole-seconds mutant. If the module doesn't multiply with wrapping, drop the row or fix the expectation. - `GetNetworkClock`/`GetDebugNetworkClock` after `sceRtcSetCurrent{Network,DebugNetwork}Tick`: this tests this tree's libSceRtc together with your wrappers, not just the wrappers. <details><summary>Test diff</summary> ```diff --- a/core/libs/tests/GuestNpCommonRtc.cpp +++ b/core/libs/tests/GuestNpCommonRtc.cpp @@ -1,5 +1,6 @@ #include "prx/libSceNpCommon/include/Api.hpp" #include "SceTypes.hpp" +#include "prx/libSceRtc/include/Rtc.hpp" #include <cstdint> #include <cstdio> #include <cstdlib> @@ -78,6 +79,56 @@ CHECK(_ZNK3sce2np4Time13FormatRFC3339EPcmi(&epoch, text, sizeof(text) - 1, 0) == bufferTooSmall && text[0] == 'x'); CHECK(_ZNK3sce2np4Time13FormatRFC3339EPcmi(&epoch, text, sizeof(text), 0) == 0 && std::strcmp(text, "1970-01-01T00:00:00.00Z") == 0 && text[sizeof(text) - 1] == '\0'); + const NpTime wrapLow{0}; + const NpTime wrapHigh{~0ull}; + CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_lPl(&wrapLow, &wrapHigh, 10, &remaining) && remaining == 0); + remainingShort = 7; + CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_jPj(&wrapLow, &wrapHigh, 10, &remainingShort) && remainingShort == 0); + CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&wrapLow, &wrapHigh, 10, &remaining) && remaining == 0); + const NpTime pastShort{unixEpochTick + 0x100000001ull}; + CHECK(_ZNK3sce2np4Time27IsTimedoutSinceMicroSecondsERKS1_jPj(&pastShort, &start, 10, &remainingShort) && remainingShort == 0); + remaining = -1; + CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&later, &start, -1, &remaining) && remaining == 0); + const NpTime threeSeconds{unixEpochTick + 3000000}; + CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&threeSeconds, &start, 3, &remaining) && remaining == 0); + CHECK(_ZNK3sce2np4Time22IsTimedoutSinceSecondsERKS1_lPl(&later, &start, 1ll << 58, &remaining) && remaining == 0); + + time = epoch; + CHECK(_ZN3sce2np4Time7AddDaysEl(&time, 0x100000001ll) == &time && time.tick == unixEpochTick + 86400000000ull); + + const RtcTick networkSet{unixEpochTick + 1000000000000ull}; + const RtcTick debugSet{unixEpochTick + 2000000000000ull}; + CHECK(sceRtcSetCurrentNetworkTick(&networkSet) == 0 && sceRtcSetCurrentDebugNetworkTick(&debugSet) == 0); + NpTime clock{0}; + CHECK(_ZN3sce2np4Time15GetNetworkClockEPS1_(&clock) == 0 && clock.tick >= networkSet.tick && clock.tick < debugSet.tick); + CHECK(_ZN3sce2np4Time20GetDebugNetworkClockEPS1_(&clock) == 0 && clock.tick >= debugSet.tick); + + const RtcDateTime badDay{1970, 2, 30, 0, 0, 0, 0}; + time = epoch; + CHECK(_ZN3sce2np4Time11SetDateTimeERKNS0_8DateTimeE(&time, &badDay) < 0 && time.tick == unixEpochTick); + + using Compare = bool (APS5_VABI*)(const NpTime*, const NpTime*); + const Compare same[] = {_ZN3sce2npeqERKNS0_4TimeES3_, _ZN3sce2npneERKNS0_4TimeES3_, _ZN3sce2npltERKNS0_4TimeES3_, + _ZN3sce2npleERKNS0_4TimeES3_, _ZN3sce2npgtERKNS0_4TimeES3_, _ZN3sce2npgeERKNS0_4TimeES3_}; + const Compare tickFirst[] = {_ZN3sce2npeqERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npneERK10SceRtcTickRKNS0_4TimeE, + _ZN3sce2npltERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npleERK10SceRtcTickRKNS0_4TimeE, + _ZN3sce2npgtERK10SceRtcTickRKNS0_4TimeE, _ZN3sce2npgeERK10SceRtcTickRKNS0_4TimeE}; + const Compare timeFirst[] = {_ZN3sce2npeqERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npneERKNS0_4TimeERK10SceRtcTick, + _ZN3sce2npltERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npleERKNS0_4TimeERK10SceRtcTick, + _ZN3sce2npgtERKNS0_4TimeERK10SceRtcTick, _ZN3sce2npgeERKNS0_4TimeERK10SceRtcTick}; + const NpTime aliasLow{5 + 0x100000000ull}; + const struct { const NpTime* lhs; const NpTime* rhs; bool expected[6]; } pairs[] = { + {&low, &high, {false, true, true, true, false, false}}, + {&high, &low, {false, true, false, false, true, true}}, + {&low, &step, {true, false, false, true, false, true}}, + {&low, &aliasLow, {false, true, true, true, false, false}}, + }; + const Compare* const formSets[] = {same, tickFirst, timeFirst}; + for (const Compare* forms : formSets) { + for (const auto& pair : pairs) { + for (int op = 0; op < 6; ++op) CHECK(forms[op](pair.lhs, pair.rhs) == pair.expected[op]); + } + } std::puts("NP common RTC tests passed"); return 0; } ``` </details> Nits (optional): - `NP_TIME_RFC3339_SIZE` duplicates the existing `NP_RFC3339_BUFFER_MIN` (0x80) in the same file. `Time::FormatRFC3339` is the body of `sceNpRtcFormatRFC3339` with the arguments reordered. If the module does the same thing, `return sceNpRtcFormatRFC3339(text, size, self, timeZoneMinutes);` would remove the copy. - The rows mutate the process-wide Network and DebugNetwork clocks. That's fine in this test binary, which is the only one in its process, but they need to stay after the `GetUserClock` row. AI-assisted: yes (review, harness and mutation run).
rooklz commented 2026-10-29 15:18:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T15:18:44Z.

Review: APPROVED


Re-reviewed head a70c6808bc on macOS 26 arm64 (Apple clang, C++20). I used the same standalone harness as last time, rebuilt from this head: the Runtime.cpp block from sceNpRtcConvertToPosixTime to sceNpRtcFormatRFC3339 copied verbatim with its helpers and constants, this tree's libSceRtc/Export.cpp unchanged plus three link shims (process params, title ID, NotImplemented), and GuestNpCommonRtc.cpp unchanged. Built with ASan+UBSan, it passes.

Checked:

  • The new test lines match the rows I posted exactly (51/51). Thanks for checking the 1 << 58 wrap and the clock NIDs against the module.
  • Time::FormatRFC3339 now forwards to sceNpRtcFormatRFC3339. Both use the same 0x80 minimum, return the same error, and terminate at size - 1, so behaviour doesn't change. The duplicate constant is gone.
  • git diff --check is clean, git merge-tree against main bb04a4f1ea is clean, check_conventions --base upstream/main passes, and CI shows 5 pass and 5 skipped.

Mutation testing: 85 single-line mutants. These cover all 18 comparison operators (each operator swapped, compared as 32-bit, compared as signed), both clock getters, all three timeout forms (negative timeout, now < since, boundary, 32-bit elapsed, whole seconds), the AddDays/AddHours narrowing, the FormatRFC3339 size forwarding, operator+, and Set/GetDateTime. 76 are killed, including all 34 survivors from my first review. The 9 survivors:

  • 6 are equivalent: eq/ne compared as signed.
  • 1 is equivalent: in the unsigned form, elapsed >= timeout gives the same remaining time (0) at the boundary.
  • 2 narrow AddDays/AddHours to 16 bits. 0x100000001 has the same low 16 bits as 1, so the test can't tell them apart. This is optional: a 0x10001 row would catch them. I'm not asking for it, since the 32-bit narrowing is what the module does and the test already pins it.
Optional rows (pass on this head, kill both 16-bit mutants)
    time = epoch;
    CHECK(_ZN3sce2np4Time7AddDaysEl(&time, 0x10001) == &time && time.tick == unixEpochTick + 0x10001ull * 86400000000ull);
    time = epoch;
    CHECK(_ZN3sce2np4Time8AddHoursEl(&time, 0x10001) == &time && time.tick == unixEpochTick + 0x10001ull * 3600000000ull);

LGTM.

AI-assisted: yes (review, harness and mutation run).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5700217466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12859#pullrequestreview-5700217466). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T15:18:44Z. **Review:** APPROVED --- Re-reviewed head `a70c6808bc` on macOS 26 arm64 (Apple clang, C++20). I used the same standalone harness as last time, rebuilt from this head: the `Runtime.cpp` block from `sceNpRtcConvertToPosixTime` to `sceNpRtcFormatRFC3339` copied verbatim with its helpers and constants, this tree's `libSceRtc/Export.cpp` unchanged plus three link shims (process params, title ID, NotImplemented), and `GuestNpCommonRtc.cpp` unchanged. Built with ASan+UBSan, it **passes**. Checked: - The new test lines match the rows I posted exactly (51/51). Thanks for checking the `1 << 58` wrap and the clock NIDs against the module. - `Time::FormatRFC3339` now forwards to `sceNpRtcFormatRFC3339`. Both use the same 0x80 minimum, return the same error, and terminate at `size - 1`, so behaviour doesn't change. The duplicate constant is gone. - `git diff --check` is clean, `git merge-tree` against main `bb04a4f1ea` is clean, `check_conventions --base upstream/main` passes, and CI shows 5 pass and 5 skipped. **Mutation testing:** 85 single-line mutants. These cover all 18 comparison operators (each operator swapped, compared as 32-bit, compared as signed), both clock getters, all three timeout forms (negative timeout, `now < since`, boundary, 32-bit elapsed, whole seconds), the `AddDays`/`AddHours` narrowing, the `FormatRFC3339` size forwarding, `operator+`, and `Set`/`GetDateTime`. **76 are killed**, including all 34 survivors from my first review. The 9 survivors: - 6 are equivalent: `eq`/`ne` compared as signed. - 1 is equivalent: in the unsigned form, `elapsed >= timeout` gives the same remaining time (0) at the boundary. - 2 narrow `AddDays`/`AddHours` to 16 bits. `0x100000001` has the same low 16 bits as 1, so the test can't tell them apart. This is optional: a `0x10001` row would catch them. I'm not asking for it, since the 32-bit narrowing is what the module does and the test already pins it. <details><summary>Optional rows (pass on this head, kill both 16-bit mutants)</summary> ```cpp time = epoch; CHECK(_ZN3sce2np4Time7AddDaysEl(&time, 0x10001) == &time && time.tick == unixEpochTick + 0x10001ull * 86400000000ull); time = epoch; CHECK(_ZN3sce2np4Time8AddHoursEl(&time, 0x10001) == &time && time.tick == unixEpochTick + 0x10001ull * 3600000000ull); ``` </details> LGTM. AI-assisted: yes (review, harness and mutation run).
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!12859
No description provided.