From a3f75325fde67381c8318df04fee82326b36b36b Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Mon, 10 Aug 2026 21:03:23 +0200 Subject: [PATCH] Support AIX in utest_ns() AIX matches none of the platforms utest_ns() knows, so it falls through to #error Unsupported platform! and nothing builds there. It cannot share the Linux/BSD branch: that one calls timespec_get() when __STDC_VERSION__ >= 201112L, and AIX 7.2 does not have it. From the system's own /usr/include/time.h: 231:#define CLOCK_REALTIME ((clockid_t) 9) 238:extern int clock_gettime(clockid_t, struct timespec *); clock_gettime is there, timespec_get and TIME_UTC are not, so any translation unit compiled as C11 would fail. AIX gets its own branch instead. Verified on AIX 7.2 TL04 (7200-04-02-2027) on POWER8 with GCC 13.3.0: with this applied and -maix64, the test suite of a project that vendors utest.h builds and passes 441 of 441. Building in GCC's default 32-bit mode on AIX needs two further fixes, sent separately. --- utest.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utest.h b/utest.h index c6d6773..a40a81d 100644 --- a/utest.h +++ b/utest.h @@ -198,6 +198,9 @@ UTEST_C_FUNC __declspec(dllimport) int __stdcall QueryPerformanceFrequency( #define UTEST_USE_CLOCKGETTIME #endif +#elif defined(_AIX) +#include + #elif defined(__APPLE__) #include #endif @@ -368,6 +371,10 @@ static UTEST_INLINE utest_int64_t utest_ns(void) { #endif #endif return UTEST_CAST(utest_int64_t, ts.tv_sec) * 1000 * 1000 * 1000 + ts.tv_nsec; +#elif defined(_AIX) + struct timespec ts = {0, 0}; + clock_gettime(CLOCK_REALTIME, &ts); + return UTEST_CAST(utest_int64_t, ts.tv_sec) * 1000 * 1000 * 1000 + ts.tv_nsec; #elif __EMSCRIPTEN__ return emscripten_performance_now() * 1000000.0; #else