From eeb8e7f0a427420d0910168a7f5b13786f26f7d0 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Jun 2025 20:48:56 -0400 Subject: [PATCH 1/4] tests: lib: timespec_util: display CONFIG_64BIT Display whether the architecture's native word size is 64-bit or not. Signed-off-by: Chris Friedt --- tests/lib/timespec_util/src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/timespec_util/src/main.c b/tests/lib/timespec_util/src/main.c index f538a41e7256..b4f286eaef4e 100644 --- a/tests/lib/timespec_util/src/main.c +++ b/tests/lib/timespec_util/src/main.c @@ -367,6 +367,7 @@ ZTEST(timeutil_api, test_timespec_to_timeout) static void *setup(void) { + printk("CONFIG_64BIT=%c\n", IS_ENABLED(CONFIG_64BIT) ? 'y' : 'n'); printk("CONFIG_TIMEOUT_64BIT=%c\n", CONFIG_TIMEOUT_64BIT ? 'y' : 'n'); printk("K_TICK_MAX: %lld\n", (long long)K_TICK_MAX); printk("minimum timeout: {%lld, %lld}\n", (long long)k_timeout_limits[0].tv_sec, From 8d2a4be795d14c8fa904ebeea7f3691296be705d Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Jun 2025 20:50:12 -0400 Subject: [PATCH 2/4] arch: posix: instruct native_sim to use 64-bit time_t 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 --- arch/posix/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index 21b6bf7f197d..3a84892bf78f 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -54,6 +54,8 @@ else() # Linux.x86_64 zephyr_compile_options(-m32) zephyr_link_libraries(-m32) + zephyr_compile_options(-D__USE_TIME_BITS64=1) + target_link_options(native_simulator INTERFACE "-m32") target_compile_options(native_simulator INTERFACE "-m32") From 95807ab9d8f6c08f9281754c3455fe6babfe2a12 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Jun 2025 21:10:44 -0400 Subject: [PATCH 3/4] cmake: unittest: ensure unit_testing platform uses 64-bit time_t Use a 64-bit time_t on the unit_testing platform. Signed-off-by: Chris Friedt --- cmake/modules/unittest.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/modules/unittest.cmake b/cmake/modules/unittest.cmake index 97b0d099f6e5..c496a2c153f8 100644 --- a/cmake/modules/unittest.cmake +++ b/cmake/modules/unittest.cmake @@ -96,8 +96,8 @@ if(M64_MODE) set (CMAKE_C_FLAGS "-m64") set (CMAKE_CXX_FLAGS "-m64") else() -set (CMAKE_C_FLAGS "-m32") #deprecated on macOS -set (CMAKE_CXX_FLAGS "-m32") #deprecated on macOS +set (CMAKE_C_FLAGS "-m32 -D__USE_TIME_BITS64=1") #deprecated on macOS +set (CMAKE_CXX_FLAGS "-m32 -D__USE_TIME_BITS64=1") #deprecated on macOS endif(M64_MODE) endif() From 947ea75b97642095b90c7086673014f103fc7f87 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Jun 2025 21:08:15 -0400 Subject: [PATCH 4/4] tests: move lib/timespec_util to unit/timeutil 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 --- tests/lib/timespec_util/CMakeLists.txt | 8 ----- tests/lib/timespec_util/prj.conf | 1 - tests/lib/timespec_util/testcase.yaml | 36 ------------------- tests/unit/timeutil/CMakeLists.txt | 1 + tests/unit/timeutil/main.c | 4 ++- tests/unit/timeutil/testcase.yaml | 8 +++++ .../src/main.c => unit/timeutil/timespec.c} | 8 ++--- 7 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 tests/lib/timespec_util/CMakeLists.txt delete mode 100644 tests/lib/timespec_util/prj.conf delete mode 100644 tests/lib/timespec_util/testcase.yaml rename tests/{lib/timespec_util/src/main.c => unit/timeutil/timespec.c} (98%) diff --git a/tests/lib/timespec_util/CMakeLists.txt b/tests/lib/timespec_util/CMakeLists.txt deleted file mode 100644 index e436a632ba04..000000000000 --- a/tests/lib/timespec_util/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(timespec_util) - -FILE(GLOB app_sources src/main.c) -target_sources(app PRIVATE ${app_sources}) diff --git a/tests/lib/timespec_util/prj.conf b/tests/lib/timespec_util/prj.conf deleted file mode 100644 index 9467c2926896..000000000000 --- a/tests/lib/timespec_util/prj.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZTEST=y diff --git a/tests/lib/timespec_util/testcase.yaml b/tests/lib/timespec_util/testcase.yaml deleted file mode 100644 index d69c5bb755fb..000000000000 --- a/tests/lib/timespec_util/testcase.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# FIXME: this should be under tests/unit/timeutil but will not work due to #90029 -common: - filter: not CONFIG_NATIVE_LIBC - tags: - - timeutils - # 1 tier0 platform per supported architecture - platform_key: - - arch - - simulation - integration_platforms: - - native_sim/native/64 -tests: - libraries.timespec_utils: {} - libraries.timespec_utils.speed: - extra_configs: - - CONFIG_SPEED_OPTIMIZATIONS=y - libraries.timespec_utils.armclang_std_libc: - toolchain_allow: armclang - extra_configs: - - CONFIG_ARMCLANG_STD_LIBC=y - libraries.timespec_utils.arcmwdtlib: - toolchain_allow: arcmwdt - extra_configs: - - CONFIG_ARCMWDT_LIBC=y - libraries.timespec_utils.minimal: - extra_configs: - - CONFIG_MINIMAL_LIBC=y - libraries.timespec_utils.newlib: - filter: TOOLCHAIN_HAS_NEWLIB == 1 - extra_configs: - - CONFIG_NEWLIB_LIBC=y - libraries.timespec_utils.picolibc: - tags: picolibc - filter: CONFIG_PICOLIBC_SUPPORTED - extra_configs: - - CONFIG_PICOLIBC=y diff --git a/tests/unit/timeutil/CMakeLists.txt b/tests/unit/timeutil/CMakeLists.txt index 0981463e8798..217cf0fdca89 100644 --- a/tests/unit/timeutil/CMakeLists.txt +++ b/tests/unit/timeutil/CMakeLists.txt @@ -14,4 +14,5 @@ target_sources(testbinary test_s32.c test_s64.c test_sync.c + timespec.c ) diff --git a/tests/unit/timeutil/main.c b/tests/unit/timeutil/main.c index 6937d8fe81e8..860a6a9ee2ce 100644 --- a/tests/unit/timeutil/main.c +++ b/tests/unit/timeutil/main.c @@ -8,6 +8,8 @@ #include "timeutil_test.h" #include "../../../lib/utils/timeutil.c" +extern void *setup(void); + void timeutil_check(const struct timeutil_test_data *tp, size_t count) { @@ -52,4 +54,4 @@ void timeutil_check(const struct timeutil_test_data *tp, } } -ZTEST_SUITE(timeutil_api, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(timeutil_api, NULL, setup, NULL, NULL, NULL); diff --git a/tests/unit/timeutil/testcase.yaml b/tests/unit/timeutil/testcase.yaml index eac190d82adf..b645e625a24f 100644 --- a/tests/unit/timeutil/testcase.yaml +++ b/tests/unit/timeutil/testcase.yaml @@ -8,3 +8,11 @@ tests: utilities.time.64bit: extra_args: M64_MODE=1 + + utilities.time.timeout32: + extra_configs: + - CONFIG_TIMEOUT_64BIT=n + + utilities.time.timeout64: + extra_configs: + - CONFIG_TIMEOUT_64BIT=y diff --git a/tests/lib/timespec_util/src/main.c b/tests/unit/timeutil/timespec.c similarity index 98% rename from tests/lib/timespec_util/src/main.c rename to tests/unit/timeutil/timespec.c index b4f286eaef4e..63b27d5cc5eb 100644 --- a/tests/lib/timespec_util/src/main.c +++ b/tests/unit/timeutil/timespec.c @@ -268,7 +268,7 @@ ZTEST(timeutil_api, test_timespec_equal) zexpect_false(timespec_equal(&a, &b)); } -#define K_TICK_MAX ((uint64_t)(CONFIG_TIMEOUT_64BIT ? (INT64_MAX) : (UINT32_MAX))) +#define K_TICK_MAX ((uint64_t)(IS_ENABLED(CONFIG_TIMEOUT_64BIT) ? (INT64_MAX) : (UINT32_MAX))) #define NS_PER_TICK (NSEC_PER_SEC / CONFIG_SYS_CLOCK_TICKS_PER_SEC) /* 0 := lower limit, 2 := upper limit */ @@ -365,10 +365,10 @@ ZTEST(timeutil_api, test_timespec_to_timeout) } } -static void *setup(void) +void *setup(void) { printk("CONFIG_64BIT=%c\n", IS_ENABLED(CONFIG_64BIT) ? 'y' : 'n'); - printk("CONFIG_TIMEOUT_64BIT=%c\n", CONFIG_TIMEOUT_64BIT ? 'y' : 'n'); + printk("CONFIG_TIMEOUT_64BIT=%c\n", IS_ENABLED(CONFIG_TIMEOUT_64BIT) ? 'y' : 'n'); printk("K_TICK_MAX: %lld\n", (long long)K_TICK_MAX); printk("minimum timeout: {%lld, %lld}\n", (long long)k_timeout_limits[0].tv_sec, (long long)k_timeout_limits[0].tv_nsec); @@ -377,5 +377,3 @@ static void *setup(void) return NULL; } - -ZTEST_SUITE(timeutil_api, NULL, setup, NULL, NULL, NULL);