From cb5c414fe875815a3f766f7276e77af7240dcccd Mon Sep 17 00:00:00 2001 From: idy Date: Sun, 26 Jul 2026 07:54:29 +0800 Subject: [PATCH 1/2] fix(esp_libc): provide picolibc timespec_get The Picolibc headers in the ESP-IDF v6.0 toolchain declare the C11 timespec_get API, but the corresponding archives do not define it. Provide the missing compatibility implementation through esp_libc and cover valid and invalid time bases. --- components/esp_libc/CMakeLists.txt | 1 + components/esp_libc/src/picolibc/timespec_get.c | 15 +++++++++++++++ .../esp_libc/test_apps/newlib/main/test_time.c | 11 +++++++++++ 3 files changed, 27 insertions(+) create mode 100644 components/esp_libc/src/picolibc/timespec_get.c diff --git a/components/esp_libc/CMakeLists.txt b/components/esp_libc/CMakeLists.txt index 5f3beec8a04..ce2529d143c 100644 --- a/components/esp_libc/CMakeLists.txt +++ b/components/esp_libc/CMakeLists.txt @@ -77,6 +77,7 @@ else() list(APPEND srcs "src/picolibc/picolibc_init.c" "src/picolibc/rand.c" + "src/picolibc/timespec_get.c" "src/picolibc/open_memstream.c" "src/picolibc/errno.c" "src/picolibc/bufio_setvbuf.c") # TODO IDF-15494: remove this and the following lines diff --git a/components/esp_libc/src/picolibc/timespec_get.c b/components/esp_libc/src/picolibc/timespec_get.c new file mode 100644 index 00000000000..81d3d5c5abc --- /dev/null +++ b/components/esp_libc/src/picolibc/timespec_get.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +int timespec_get(struct timespec *ts, int base) +{ + if (base != TIME_UTC || clock_gettime(CLOCK_REALTIME, ts) < 0) { + return 0; + } + return base; +} diff --git a/components/esp_libc/test_apps/newlib/main/test_time.c b/components/esp_libc/test_apps/newlib/main/test_time.c index 5b885dffb77..ffded3907ff 100644 --- a/components/esp_libc/test_apps/newlib/main/test_time.c +++ b/components/esp_libc/test_apps/newlib/main/test_time.c @@ -548,6 +548,17 @@ TEST_CASE("test posix_timers clock_... functions", "[newlib]") test_posix_timers_clock(); } +TEST_CASE("timespec_get returns UTC time", "[newlib]") +{ + struct timespec ts = {0}; + + TEST_ASSERT_EQUAL_INT(TIME_UTC, timespec_get(&ts, TIME_UTC)); + TEST_ASSERT_GREATER_OR_EQUAL_INT64(0, ts.tv_sec); + TEST_ASSERT_GREATER_OR_EQUAL_INT32(0, ts.tv_nsec); + TEST_ASSERT_LESS_THAN_INT32(1000000000L, ts.tv_nsec); + TEST_ASSERT_EQUAL_INT(0, timespec_get(&ts, -1)); +} + #define TEST_USE_CPU_CYCLES 1 #if TEST_USE_CPU_CYCLES && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE #include "esp_cpu.h" From ed92ba1e24c909446e693b42192e4716ae664176 Mon Sep 17 00:00:00 2001 From: idy Date: Sun, 26 Jul 2026 10:31:44 +0800 Subject: [PATCH 2/2] fix(esp_libc): limit timespec_get test to picolibc The regression test was compiled by Newlib configurations even though that libc does not expose TIME_UTC or timespec_get in the selected toolchain. - Guard the test with CONFIG_LIBC_PICOLIBC - Label the case as a Picolibc-specific regression Generated with [Codex](https://github.com/openai) --- components/esp_libc/test_apps/newlib/main/test_time.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/esp_libc/test_apps/newlib/main/test_time.c b/components/esp_libc/test_apps/newlib/main/test_time.c index ffded3907ff..3c748a2cdac 100644 --- a/components/esp_libc/test_apps/newlib/main/test_time.c +++ b/components/esp_libc/test_apps/newlib/main/test_time.c @@ -548,7 +548,8 @@ TEST_CASE("test posix_timers clock_... functions", "[newlib]") test_posix_timers_clock(); } -TEST_CASE("timespec_get returns UTC time", "[newlib]") +#if CONFIG_LIBC_PICOLIBC +TEST_CASE("timespec_get returns UTC time", "[picolibc]") { struct timespec ts = {0}; @@ -558,6 +559,7 @@ TEST_CASE("timespec_get returns UTC time", "[newlib]") TEST_ASSERT_LESS_THAN_INT32(1000000000L, ts.tv_nsec); TEST_ASSERT_EQUAL_INT(0, timespec_get(&ts, -1)); } +#endif #define TEST_USE_CPU_CYCLES 1 #if TEST_USE_CPU_CYCLES && CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE