Skip to content

build: ensure time_t is consistent across all supported platforms #92274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Jun 27, 2025

Previously, the unit_testing and native_sim platforms would use a 32-bit time_t due to the -m32 cflag.

However, on glibc-based systems (at least), this can be controlled via -D__USE_TIME_BITS64=1.

Using a 64-bit time_t is important for historical reasons, to be robust for the future, and also just for compatibility with all other platforms supported by Zephyr, as well as the greater Internet-of-Things at large.

With that, we can move tests/lib/timespec_util to tests/unit/timeutil, since those tests are now platform-independent.

Fixes #90029

Should probably be merged after #92255.

Testing Done (after native_sim fix, for bisectability):

$ west build -p auto -b native_sim -t run tests/lib/timespec_util/
*** Booting Zephyr OS build v4.1.0-6994-g8d2a4be795d1 ***
Running TESTSUITE timeutil_api
===================================================================
CONFIG_64BIT=n
CONFIG_TIMEOUT_64BIT=y
K_TICK_MAX: 9223372036854775807
minimum timeout: {0, 10000000}
maximum timeout: {18446744073, 699551616}
START - test_timespec_add
 PASS - test_timespec_add in 0.000 seconds
===================================================================
START - test_timespec_compare
 PASS - test_timespec_compare in 0.000 seconds
===================================================================
START - test_timespec_equal
 PASS - test_timespec_equal in 0.000 seconds
===================================================================
START - test_timespec_from_timeout
 PASS - test_timespec_from_timeout in 0.000 seconds
===================================================================
START - test_timespec_is_valid
 PASS - test_timespec_is_valid in 0.000 seconds
===================================================================
START - test_timespec_negate
 PASS - test_timespec_negate in 0.000 seconds
===================================================================
START - test_timespec_normalize
 PASS - test_timespec_normalize in 0.000 seconds
===================================================================
START - test_timespec_sub
 PASS - test_timespec_sub in 0.000 seconds
===================================================================
START - test_timespec_to_timeout
 PASS - test_timespec_to_timeout in 0.000 seconds
===================================================================
TESTSUITE timeutil_api succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [timeutil_api]: pass = 9, fail = 0, skip = 0, total = 9 duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_add] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_compare] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_equal] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_from_timeout] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_is_valid] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_negate] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_normalize] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_sub] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_to_timeout] duration = 0.000 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Testing Done (after unit_testing fix, for bisectability):

$ west build -p auto -b unit_testing -t run tests/unit/timeutil/
-- west build: running target run
[1/1] cd /home/cfriedt/zephyrproject/zephyr/build && /home/cfriedt/zephyrproject/zephyr/build/testbinary
Running TESTSUITE timeutil_api
===================================================================
CONFIG_64BIT=n
CONFIG_TIMEOUT_64BIT=y
K_TICK_MAX: 9223372036854775807
minimum timeout: {0, 100000}
maximum timeout: {18446744073, 709451616}
START - test_gmtime
 PASS - test_gmtime in 0.000 seconds
===================================================================
START - test_s32
 PASS - test_s32 in 0.000 seconds
===================================================================
START - test_s64
 PASS - test_s64 in 0.000 seconds
===================================================================
START - test_sync
 PASS - test_sync in 0.000 seconds
===================================================================
START - test_timespec_add
 PASS - test_timespec_add in 0.000 seconds
===================================================================
START - test_timespec_compare
 PASS - test_timespec_compare in 0.000 seconds
===================================================================
START - test_timespec_equal
 PASS - test_timespec_equal in 0.000 seconds
===================================================================
START - test_timespec_from_timeout
 PASS - test_timespec_from_timeout in 0.000 seconds
===================================================================
START - test_timespec_is_valid
 PASS - test_timespec_is_valid in 0.000 seconds
===================================================================
START - test_timespec_negate
 PASS - test_timespec_negate in 0.000 seconds
===================================================================
START - test_timespec_normalize
 PASS - test_timespec_normalize in 0.000 seconds
===================================================================
START - test_timespec_sub
 PASS - test_timespec_sub in 0.000 seconds
===================================================================
START - test_timespec_to_timeout
 PASS - test_timespec_to_timeout in 0.000 seconds
===================================================================
TESTSUITE timeutil_api succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [timeutil_api]: pass = 13, fail = 0, skip = 0, total = 13 duration = 0.000 seconds
 - PASS - [timeutil_api.test_gmtime] duration = 0.000 seconds
 - PASS - [timeutil_api.test_s32] duration = 0.000 seconds
 - PASS - [timeutil_api.test_s64] duration = 0.000 seconds
 - PASS - [timeutil_api.test_sync] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_add] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_compare] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_equal] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_from_timeout] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_is_valid] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_negate] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_normalize] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_sub] duration = 0.000 seconds
 - PASS - [timeutil_api.test_timespec_to_timeout] duration = 0.000 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Testing Done (via twister):

$ twister -p unit_testing -T tests/unit/timeutil
Renaming output directory to /home/cfriedt/zephyrproject/zephyr/twister-out.4
INFO    - Using Ninja..
INFO    - Zephyr version: v4.1.0-6996-g947ea75b9764
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/cfriedt/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 32
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:    4/   4  100%  built (not run):    0, filtered:    0, failed:    0, error:    0
INFO    - 4 test scenarios (4 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 4 of 4 executed test configurations passed (100.00%), 0 built (not run), 0 failed, 0 errored, with no warnings in 4.13 seconds.
INFO    - 52 of 52 executed test cases passed (100.00%) on 1 out of total 1106 platforms (0.09%).
INFO    - 4 test configurations executed on platforms, 0 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/cfriedt/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/cfriedt/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/cfriedt/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - Run completed

cfriedt added 4 commits June 26, 2025 20:48
Display whether the architecture's native word size is 64-bit or not.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Use a 64-bit time_t on native_sim. This ensures that native_sim (and
hopefully also platforms based on it?) uses a 64-bit time_t type in
the native C library.

This is important to ensure that e.g. the Y2K bug isn't an issue,
among other things.

With that, the size of time_t in Zephyr is uniform across all
supported architectures and platforms.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Use a 64-bit time_t on the unit_testing platform.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Since native_sim and unit_testing platforms can now be compiled with
time_t as 64-bits, that means that all platforms in Zephyr are
consistent.

Move the (now platform-independent) lib/timespec_util tests to
unit/timeutil.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
@cfriedt cfriedt force-pushed the native-sim-64-bit-time-t branch from 17097f1 to 947ea75 Compare June 27, 2025 01:25
Copy link

Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on. Let's first discuss in the bug about the bug being a bug, and about the way forward.
In any case, to the best of my understanding __USE_TIME_BITS64 is an internal glibc macro which the user is not meant to set. See:
https://sourceware.org/glibc/wiki/Y2038ProofnessDesign
See also #75567 about a possible way forward.

@nashif nashif assigned aescolar and unassigned nashif and andyross Jun 27, 2025
@cfriedt
Copy link
Member Author

cfriedt commented Jul 6, 2025

I'd like to close this in favour of #75567 with my main ask being that we move to 64-bit time_t and 64-bit off_t by default.

@cfriedt cfriedt closed this Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

boards: unit_testing + native_sim/native: time_t incompatible with all other platforms
4 participants