Sfoglia il codice sorgente

Merge branch 'bugfix/linux_target_log_macos' into 'master'

linux target: add ESP_LOG_BUFFERS support, fix build on macOS

See merge request espressif/esp-idf!17726
Ivan Grokhotkov 3 anni fa
parent
commit
a4e8a623b3

+ 2 - 1
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

+ 1 - 4
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()
 

+ 12 - 0
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;

+ 9 - 1
components/log/log_buffers.c

@@ -7,9 +7,17 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include <stdbool.h>
 #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