Description
Describe the bug
When building with the ARC MWDT toolchain, some tests fail because of inconsistent clockid values between the toolchain headers and Zephyr’s internal definitions.
Specifically:
CLOCK_REALTIME and CLOCK_MONOTONIC come from the toolchain header:
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
Zephyr internally defines:
#define SYS_CLOCK_REALTIME 1
#define SYS_CLOCK_MONOTONIC 4
and tries to map them in include/zephyr/posix/time.h:
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
#endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC
#endif
Because the toolchain headers already define these macros, the #ifndef guards fail, so the fallback Zephyr definitions are never applied.
Tests and code end up mixing:
-
CLOCK_REALTIME=0 (from toolchain)
-
SYS_CLOCK_REALTIME=1 (used in Zephyr kernel)
-
CLOCK_MONOTONIC=1 (toolchain)
-
SYS_CLOCK_MONOTONIC=4 (Zephyr)
This mismatch causes functions like:
clock_gettime(CLOCK_REALTIME, &tp);
to pass wrong clockid into Zephyr, leading to errors like EINVAL (invalid clock ID).
Regression
- This is a regression.
Steps to reproduce
Use the ARC MWDT toolchain (or any toolchain that defines CLOCK_REALTIME and CLOCK_MONOTONIC with different values, e.g., 0 and 1 instead of Zephyr’s 1 and 4).
Build and run a test like tests/posix/semaphores or tests/lib/c_lib/thrd:
west twister -p <your_arc_board> -s portability.posix.semaphores
or
west twister -p <your_arc_board> -s libraries.libc.c11_threads.picolibc.notls
Relevant log output
Booting Zephyr OS build v4.2.0-rc3
Running TESTSUITE posix_semaphores
START - test_named_semaphore
Assertion failed at WEST_TOPDIR/zephyr/tests/posix/semaphores/src/main.c:58: semaphore_test: (clock_gettime(CLOCK_REALTIME, &abstime) not equal to 0)
clock_gettime failed
FAIL - test_named_semaphore in 0.702 seconds
START - test_semaphore
Assertion failed at WEST_TOPDIR/zephyr/tests/posix/semaphores/src/main.c:58: semaphore_test: (clock_gettime(CLOCK_REALTIME, &abstime) not equal to 0)
clock_gettime failed
FAIL - test_semaphore in 0.006 seconds
TESTSUITE posix_semaphores failed.
------ TESTSUITE SUMMARY START ------
SUITE FAIL - 0.00% [posix_semaphores]: pass = 0, fail = 2, skip = 0, total = 2 duration = 0.708 seconds
FAIL - [posix_semaphores.test_named_semaphore] duration = 0.702 seconds
FAIL - [posix_semaphores.test_semaphore] duration = 0.006 seconds
------ TESTSUITE SUMMARY END ------
Impact
Annoyance – Minor irritation; no significant impact on usability or functionality.
Environment
OS: Linux
Toolchain (e.g Zephyr SDK, ...): arcmwdt
Commit SHA or Version used: Main 322da1d
Additional Context
This issue was introduced by PR #90096