From df9fdae4c4f29a3cd94a3a10ab405c575b21199b Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 17 Feb 2026 17:55:30 +0100 Subject: [PATCH] Add smoke test for availability of some Unix functions The goal isn't to do any functional testing, but to have a simple diagnostic if some Unix platform function isn't available, and to have a record of success in the outcome file. Signed-off-by: Gilles Peskine --- tests/suites/test_suite_platform_unix.data | 12 +++++ .../suites/test_suite_platform_unix.function | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/suites/test_suite_platform_unix.data create mode 100644 tests/suites/test_suite_platform_unix.function diff --git a/tests/suites/test_suite_platform_unix.data b/tests/suites/test_suite_platform_unix.data new file mode 100644 index 0000000000..7135bf77b3 --- /dev/null +++ b/tests/suites/test_suite_platform_unix.data @@ -0,0 +1,12 @@ + smoke test +unistd_available: + +# At the time of writing, we don't actually use CLOCK_REALTIME. +# But it's the only clock that's guaranteed by POSIX. +clock_gettime(CLOCK_REALTIME) smoke test +clock_gettime_available:CLOCK_REALTIME + +# Used for mbedtls_ms_time() on platforms where we don't think +# CLOCK_BOOTTIME is available. +clock_gettime(CLOCK_MONOTONIC) smoke test +clock_gettime_available:CLOCK_MONOTONIC diff --git a/tests/suites/test_suite_platform_unix.function b/tests/suites/test_suite_platform_unix.function new file mode 100644 index 0000000000..14f3099a4e --- /dev/null +++ b/tests/suites/test_suite_platform_unix.function @@ -0,0 +1,45 @@ +/* BEGIN_HEADER */ +/* Test access to the Unix primitives used in platform_util.c and elsewhere. + * We aren't testing that they work, just getting an easy-to-understand + * diagnostic if they aren't available. + * (There is a separate test suite for the platform_util.h interfacces.) + */ + +#include +#include +#include "common.h" + +#if defined(MBEDTLS_PLATFORM_IS_UNIXLIKE) + +#include +#include + +#endif /* defined(MBEDTLS_PLATFORM_IS_UNIXLIKE) */ + +/* END_HEADER */ + +/* Note: we can't make the whole test suite depend on + * MBEDTLS_PLATFORM_IS_UNIXLIKE, because file-level dependencies can only + * come from build_info.h, platform.h or some test helper headers, not + * from internal macros. */ +/* BEGIN_DEPENDENCIES + * END_DEPENDENCIES */ + +/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */ +void unistd_available() +{ + pid_t pid = getpid(); + TEST_LE_S(1, pid); +} +/* END_CASE */ + +/* BEGIN_CASE depends_on:MBEDTLS_PLATFORM_IS_UNIXLIKE */ +void clock_gettime_available(int clockid) +{ + struct timespec ts = { 0, 0 }; + memset(&ts, 0, sizeof(ts)); + int ret = clock_gettime(clockid, &ts); + TEST_ASSERT_ERRNO(ret == 0); + TEST_LE_S(1, ts.tv_sec); +} +/* END_CASE */