From 3602d332c4f8f462b5517c75dd65625ee89c1587 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 10 Apr 2022 19:52:06 +0200 Subject: [PATCH 1/2] log: support ESP_LOG_BUFFER* functions for Linux target --- components/log/CMakeLists.txt | 5 +---- components/log/host_test/log_test/main/log_test.cpp | 12 ++++++++++++ components/log/log_buffers.c | 10 +++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/log/CMakeLists.txt b/components/log/CMakeLists.txt index 6deb0b5428..bd841ede36 100644 --- a/components/log/CMakeLists.txt +++ b/components/log/CMakeLists.txt @@ -1,12 +1,9 @@ idf_build_get_property(target IDF_TARGET) -set(srcs "log.c") +set(srcs "log.c" "log_buffers.c") set(priv_requires "") if(${target} STREQUAL "linux") - # We leave log buffers out for now on Linux since it's rarely used. Explicitely add esp_rom to Linux target - # since we don't have the common components there yet. list(APPEND srcs "log_linux.c") else() - list(APPEND srcs "log_buffers.c") list(APPEND priv_requires soc hal esp_hw_support) endif() diff --git a/components/log/host_test/log_test/main/log_test.cpp b/components/log/host_test/log_test/main/log_test.cpp index 76c4dfc5a7..a4befc9a24 100644 --- a/components/log/host_test/log_test/main/log_test.cpp +++ b/components/log/host_test/log_test/main/log_test.cpp @@ -193,6 +193,18 @@ TEST_CASE("changing log level") CHECK(regex_search(fix.get_print_buffer_string(), test_print) == true); } +TEST_CASE("log buffer") +{ + PrintFixture fix(ESP_LOG_INFO); + const uint8_t buffer[] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + }; + ESP_LOG_BUFFER_HEX(TEST_TAG, buffer, sizeof(buffer)); + const std::regex buffer_regex("I \\([0-9]*\\) test: 01 02 03 04 05 06 07 08 11 12 13 14 15 16 17 18", std::regex::ECMAScript); + CHECK(regex_search(fix.get_print_buffer_string(), buffer_regex)); +} + TEST_CASE("rom printf") { PutcFixture fix; diff --git a/components/log/log_buffers.c b/components/log/log_buffers.c index 03935c9217..2fcef1b2b6 100644 --- a/components/log/log_buffers.c +++ b/components/log/log_buffers.c @@ -7,9 +7,17 @@ #include #include #include +#include #include "esp_log.h" -#include "esp_memory_utils.h" // for esp_ptr_byte_accessible +#ifndef CONFIG_IDF_TARGET_LINUX +#include "esp_memory_utils.h" // for esp_ptr_byte_accessible +#else +static inline bool esp_ptr_byte_accessible(const void* ptr) { + (void) ptr; + return true; +} +#endif // CONFIG_IDF_TARGET_LINUX //print number of bytes per line for esp_log_buffer_char and esp_log_buffer_hex #define BYTES_PER_LINE 16 From 34aa82a11af95b3ca79b07c29d636719b0b3d162 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 10 Apr 2022 19:54:56 +0200 Subject: [PATCH 2/2] cmake: use -warn_commons instead of --warn-common on macOS --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 569f1a329e..56fa70e4b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,12 +198,13 @@ if(CONFIG_ESP_SYSTEM_USE_EH_FRAME) endif() list(APPEND link_options "-fno-lto") -list(APPEND link_options "-Wl,--warn-common") if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") list(APPEND link_options "-Wl,-dead_strip") + list(APPEND link_options "-Wl,-warn_commons") else() list(APPEND link_options "-Wl,--gc-sections") + list(APPEND link_options "-Wl,--warn-common") endif() # SMP FreeRTOS user provided minimal idle hook. This allows the user to provide