From e4aa326c3a577920945a2f440edf51a27d170df5 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 19 Mar 2024 14:53:57 +0800 Subject: [PATCH] feat(log): Added PRIuSIZE printf formatter macro --- components/log/include/inttypes_ext.h | 20 +++++++++++++++++++ tools/test_apps/.build-test-rules.yml | 6 ++++++ .../generic_build_test/CMakeLists.txt | 9 +++++++++ .../generic_build_test/README.md | 4 ++++ .../generic_build_test/main/CMakeLists.txt | 2 ++ .../main/generic_build_test.c | 15 ++++++++++++++ 6 files changed, 56 insertions(+) create mode 100644 components/log/include/inttypes_ext.h create mode 100644 tools/test_apps/linux_compatible/generic_build_test/CMakeLists.txt create mode 100644 tools/test_apps/linux_compatible/generic_build_test/README.md create mode 100644 tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt create mode 100644 tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c diff --git a/components/log/include/inttypes_ext.h b/components/log/include/inttypes_ext.h new file mode 100644 index 0000000000..72cc346992 --- /dev/null +++ b/components/log/include/inttypes_ext.h @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +/* + * This header provides PRIuSIZE, a printf formatter macro for size_t which is similar to the macros + * PRIuX defined in inttypes.h. It is necessary because size_t has different width on different + * platforms (e.g., Linux and ESP32). The alternative would be always casting parameters + * to a certain type in printf and logging functions. + */ + +#if __SIZE_WIDTH__ == 64 // __SIZE_WIDTH__ is defined by both GCC and Clang +#define PRIuSIZE "lu" +#else +#define PRIuSIZE "u" +#endif diff --git a/tools/test_apps/.build-test-rules.yml b/tools/test_apps/.build-test-rules.yml index 9e725eb748..70dfa01002 100644 --- a/tools/test_apps/.build-test-rules.yml +++ b/tools/test_apps/.build-test-rules.yml @@ -24,6 +24,12 @@ tools/test_apps/linux_compatible/driver_mock: enable: - if: IDF_TARGET == "linux" +tools/test_apps/linux_compatible/generic_build_test: + enable: + - if: IDF_TARGET in ["esp32", "esp32c3", "linux"] + depends_components: + - log + tools/test_apps/linux_compatible/linux_freertos: enable: - if: IDF_TARGET == "linux" diff --git a/tools/test_apps/linux_compatible/generic_build_test/CMakeLists.txt b/tools/test_apps/linux_compatible/generic_build_test/CMakeLists.txt new file mode 100644 index 0000000000..6f761e8850 --- /dev/null +++ b/tools/test_apps/linux_compatible/generic_build_test/CMakeLists.txt @@ -0,0 +1,9 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(COMPONENTS main) +project(generic_build_test) diff --git a/tools/test_apps/linux_compatible/generic_build_test/README.md b/tools/test_apps/linux_compatible/generic_build_test/README.md new file mode 100644 index 0000000000..d413dde03d --- /dev/null +++ b/tools/test_apps/linux_compatible/generic_build_test/README.md @@ -0,0 +1,4 @@ +| Supported Targets | ESP32 | ESP32-C3 | Linux | +| ----------------- | ----- | -------- | ----- | + +This application is a build test. It checks that certain features can be used on different targets. diff --git a/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt b/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt new file mode 100644 index 0000000000..c19f364742 --- /dev/null +++ b/tools/test_apps/linux_compatible/generic_build_test/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "generic_build_test.c" + INCLUDE_DIRS ".") diff --git a/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c b/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c new file mode 100644 index 0000000000..6177434f33 --- /dev/null +++ b/tools/test_apps/linux_compatible/generic_build_test/main/generic_build_test.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include +#include +#include "inttypes_ext.h" + +void app_main(void) +{ + size_t size = 47; + printf("size is: %" PRIuSIZE "\n", size); // test IDF's PRIuSIZE +}