-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Describe the bug
While creating some additional utilities for dealing with time structures, and using the unit_testing
board (since that is the least expensive of all of our test platforms), I was triggering an unexpected assertion.
Namely:
BUILD_ASSERT(sizeof(((struct timespec *)0)->tv_sec) == sizeof(int64_t), "tv_sec must be 64-bit");
Just to be sure that this was out of the ordinary, I created a testsuite to check that time_t
was 64-bit on all other platforms (see 'Additional Context'), and sure enough, every other architecture that is supported by Zephyr supports a 64-bit time_t
,
except for unit_testing
and native_sim/native
(the 32-bit variant of native_sim/native/64
).
I realize it's a bit tricky due to the current -m32
CFLAG, and what that might imply for the host platform in terms of other standard C types if we were to move to -m64
instead.
However, we typically do want to test both 64-bit and 32-bit platforms with our unit_testing
platform, and for the most part, standard C types should be compatible between our unit_testing
platform and all other Zephyr platforms.
Please also mention any information which could help others to understand
the problem you're facing:
- What target platform are you using?
unit_testing
,native_sim/native
(and all other architectures) - What have you tried to diagnose or workaround this issue? Compared with every other architecture supported by Zephyr
- Is this a regression? Unsure
To Reproduce
- create basic testsuites with the added items below
twister -i -p unit_testing -T tests/unit/timeutil
- See error
- run contrived non-unit-testing testsuite below
- See success (inconsistence)
Expected behavior
That standard C types should be consistent between the unit_testing
platform and all other platforms in Zephyr.
Impact
The impact to the utilities and testsuite that I'm working on is pretty big, since it should cover most possible values within the [INT64_MIN, INT64_MAX]
range, but without the support of the unit_testing
platform itself,
Logs and console output
west build -p auto -b unit_testing -t run tests/unit/timeutil/
...
In file included from /home/cfriedt/zephyrproject/zephyr/include/zephyr/toolchain.h:52,
from /home/cfriedt/zephyrproject/zephyr/include/zephyr/sys/printk.h:11,
from /home/cfriedt/zephyrproject/zephyr/subsys/testsuite/ztest/include/zephyr/ztest.h:37,
from /home/cfriedt/zephyrproject/zephyr/tests/unit/timeutil/test_timespec.c:12:
/home/cfriedt/zephyrproject/zephyr/include/zephyr/toolchain/gcc.h:87:36: error: static assertion failed: "tv_sec must be 64-bit"
87 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
| ^~~~~~~~~~~~~~
/home/cfriedt/zephyrproject/zephyr/include/zephyr/sys/timespec_util.h:23:1: note: in expansion of macro ‘BUILD_ASSERT’
23 | BUILD_ASSERT(sizeof(((struct timespec *)0)->tv_sec) == sizeof(int64_t), "tv_sec must be 64-bit");
twister -i -T tests/lib/time_t/
...
ERROR - native_sim/native tests/lib/time_t/libraries.time_t.size ERROR: Build failure
...
ccache /usr/lib/ccache/gcc -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DTC_RUNID=071b3a4d2ea8804c8fa5ef11ea55afa5 -D__ZEPHYR__=1 -I/home/cfriedt/zephyrproject/zephyr/twister-out/native_sim_native/host/tests/lib/time_t/libraries.time_t.size/zephyr/include/generated/zephyr -I/home/cfriedt/zephyrproject/zephyr/include -I/home/cfriedt/zephyrproject/zephyr/twister-out/native_sim_native/host/tests/lib/time_t/libraries.time_t.size/zephyr/include/generated -I/home/cfriedt/zephyrproject/zephyr/soc/native/inf_clock -I/home/cfriedt/zephyrproject/zephyr/boards/native/native_sim -I/home/cfriedt/zephyrproject/zephyr/scripts/native_simulator/common/src/include -I/home/cfriedt/zephyrproject/zephyr/scripts/native_simulator/native/src/include -I/home/cfriedt/zephyrproject/zephyr/subsys/testsuite/include -I/home/cfriedt/zephyrproject/zephyr/subsys/testsuite/coverage -I/home/cfriedt/zephyrproject/zephyr/subsys/testsuite/ztest/include -fno-strict-aliasing -Werror -Os -imacros /home/cfriedt/zephyrproject/zephyr/twister-out/native_sim_native/host/tests/lib/time_t/libraries.time_t.size/zephyr/include/generated/zephyr/autoconf.h -fno-common -g -gdwarf-4 -fdiagnostics-color=always -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/cfriedt/zephyrproject/zephyr/tests/lib/time_t=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/cfriedt/zephyrproject/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/cfriedt/zephyrproject=WEST_TOPDIR -ffunction-sections -fdata-sections -m32 -msse2 -mfpmath=sse -fvisibility=hidden -fno-freestanding -std=c11 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c /home/cfriedt/zephyrproject/zephyr/tests/lib/time_t/src/main.c
In file included from /home/cfriedt/zephyrproject/zephyr/include/zephyr/toolchain.h:52,
from /home/cfriedt/zephyrproject/zephyr/include/zephyr/sys/util.h:18,
from /home/cfriedt/zephyrproject/zephyr/include/zephyr/sys_clock.h:19,
from /home/cfriedt/zephyrproject/zephyr/include/zephyr/sys/timespec_util.h:15,
from /home/cfriedt/zephyrproject/zephyr/tests/lib/time_t/src/main.c:4:
/home/cfriedt/zephyrproject/zephyr/include/zephyr/toolchain/gcc.h:87:36: error: static assertion failed: "tv_sec must be 64-bit"
87 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
| ^~~~~~~~~~~~~~
/home/cfriedt/zephyrproject/zephyr/include/zephyr/sys/timespec_util.h:23:1: note: in expansion of macro ‘BUILD_ASSERT’
23 | BUILD_ASSERT(sizeof(((struct timespec *)0)->tv_sec) == sizeof(int64_t), "tv_sec must be 64-bit");
| ^~~~~~~~~~~~
/home/cfriedt/zephyrproject/zephyr/include/zephyr/toolchain/gcc.h:87:36: error: static assertion failed: "tv_sec must be 64-bit"
87 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
| ^~~~~~~~~~~~~~
/home/cfriedt/zephyrproject/zephyr/tests/lib/time_t/src/main.c:7:1: note: in expansion of macro ‘BUILD_ASSERT’
7 | BUILD_ASSERT(sizeof(((struct timespec *)0)->tv_sec) == sizeof(int64_t), "tv_sec must be 64-bit");
| ^~~~~~~~~~~~
Environment (please complete the following information):
- OS: Linux
- Toolchain: Zephyr SDK v0.17.0
- Commit SHA: 4512cbf
Additional context
basic testcase.yml
for the unit_testing
platform and the test_timeutil.c
below (and added to tests/unit/timeutil/CMakeLists.txt
).
tests/unit/timeutil/test_timeutil.c
:
BUILD_ASSERT(sizeof(((struct timespec *)0)->tv_sec) == sizeof(int64_t), "tv_sec must be 64-bit");
When the same .c
file is run through a non-unit_testing
testsuite (tests/lib/time_t/
) with the testcase.yml
file below, all other platforms pass except for unit_testing
and native_sim/native
, even in contrast to other 32-bit platforms.
testcase.yaml
common:
tags:
- libc
# 1 tier0 platform per supported architecture
platform_key:
- arch
- simulation
tests:
libraries.time_t.size: {}
libraries.time_t.size.armclang_std_libc:
toolchain_allow: armclang
extra_configs:
- CONFIG_ARMCLANG_STD_LIBC=y
libraries.time_t.size.arcmwdtlib:
toolchain_allow: arcmwdt
extra_configs:
- CONFIG_ARCMWDT_LIBC=y
libraries.time_t.size.minimal:
extra_configs:
- CONFIG_MINIMAL_LIBC=y
libraries.time_t.size.newlib:
filter: TOOLCHAIN_HAS_NEWLIB == 1
extra_configs:
- CONFIG_NEWLIB_LIBC=y
libraries.time_t.size.picolibc:
tags: picolibc
filter: CONFIG_PICOLIBC_SUPPORTED
extra_configs:
- CONFIG_PICOLIBC=y