feat(log): Added PRIuSIZE printf formatter macro

pull/13473/head
Jakob Hasse 2024-03-19 14:53:57 +08:00
rodzic 53e3833f44
commit e4aa326c3a
6 zmienionych plików z 56 dodań i 0 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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"

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.

Wyświetl plik

@ -0,0 +1,2 @@
idf_component_register(SRCS "generic_build_test.c"
INCLUDE_DIRS ".")

Wyświetl plik

@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <stddef.h>
#include "inttypes_ext.h"
void app_main(void)
{
size_t size = 47;
printf("size is: %" PRIuSIZE "\n", size); // test IDF's PRIuSIZE
}