From 758b33d977e5ccd3074f8e55a9da878d804122e9 Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Mon, 9 Dec 2024 16:59:23 +0800 Subject: [PATCH] feat(repo): update conf file --- CHANGELOG.md | 6 + Kconfig | 55 +++--- README.md | 38 ++-- esp_utils_conf.h | 54 +++--- idf_component.yml | 2 +- library.properties | 2 +- src/check/esp_utils_check.h | 306 +++++++++++++++++++-------------- src/esp_utils_conf_kconfig.h | 50 ++---- src/esp_utils_types.h | 9 + src/esp_utils_versions.h | 6 +- src/log/esp_utils_log.c | 4 +- src/log/esp_utils_log.h | 18 +- src/memory/esp_utils_mem.h | 6 +- test_apps/main/test_on_c.c | 16 +- test_apps/main/test_on_cpp.cpp | 16 +- 15 files changed, 294 insertions(+), 294 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 328aa2f..9f7fd3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.1.1 + +### Enhancements: + +* feat(repo): update config header and Kconfig file s + ## v0.1.0 ### Enhancements: diff --git a/Kconfig b/Kconfig index df18c96..5b91d3f 100644 --- a/Kconfig +++ b/Kconfig @@ -5,43 +5,32 @@ menu "ESP Library Utils Configurations" menu "Check functions" depends on ESP_UTILS_CONF_FILE_SKIP - config ESP_UTILS_CONF_ENABLE_CHECK - bool "Enable check functions" - default y - help - If enabled, the driver will check the function parameters, return value, etc. Disable them will reduce the code size. + choice ESP_UTILS_CONF_CHECK_HANDLE_METHOD + prompt "Select handle method when check failed" + default ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG - config ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG - bool "Print log messages on error" - default y - depends on ESP_UTILS_CONF_ENABLE_CHECK - help - If enabled, the driver will print error message when check failed. + config ESP_UTILS_CHECK_HANDLE_WITH_NONE + bool "Do nothing" - config ESP_UTILS_CONF_CHECK_WITH_ASSERT - bool "Assert on error" - default n - depends on ESP_UTILS_CONF_ENABLE_CHECK - help - If enabled, the driver will assert when check failed. + config ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG + bool "Print error message" + + config ESP_UTILS_CHECK_HANDLE_WITH_ASSERT + bool "Assert" + endchoice + + config ESP_UTILS_CONF_CHECK_HANDLE_METHOD + int + default 0 if ESP_UTILS_CHECK_HANDLE_WITH_NONE + default 1 if ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG + default 2 if ESP_UTILS_CHECK_HANDLE_WITH_ASSERT endmenu menu "Log functions" depends on ESP_UTILS_CONF_FILE_SKIP - config ESP_UTILS_CONF_ENABLE_LOG - bool "Enable log functions" - default y - help - If enabled, the driver will output log for debugging. - - config ESP_UTILS_CONF_LOG_BUFFER_SIZE - int "Buffer size for formatting messages" - depends on ESP_UTILS_CONF_ENABLE_LOG - default 256 choice ESP_UTILS_CONF_LOG_LEVEL prompt "Select global log level" - depends on ESP_UTILS_CONF_ENABLE_LOG default ESP_UTILS_CONF_LOG_LEVEL_INFO config ESP_UTILS_CONF_LOG_LEVEL_DEBUG @@ -63,6 +52,11 @@ menu "ESP Library Utils Configurations" bool "Error" help Critical errors, software module cannot recover on its own + + config ESP_UTILS_CONF_LOG_LEVEL_NONE + bool "None" + help + No log output endchoice config ESP_UTILS_CONF_LOG_LEVEL @@ -71,6 +65,7 @@ menu "ESP Library Utils Configurations" default 1 if ESP_UTILS_CONF_LOG_LEVEL_INFO default 2 if ESP_UTILS_CONF_LOG_LEVEL_WARNING default 3 if ESP_UTILS_CONF_LOG_LEVEL_ERROR + default 4 if ESP_UTILS_CONF_LOG_LEVEL_NONE config ESP_UTILS_CONF_ENABLE_LOG_TRACE bool "Enable trace function" @@ -78,6 +73,10 @@ menu "ESP Library Utils Configurations" default n help If enabled, the driver will print trace log messages when enter/exit functions, useful for debugging + + config ESP_UTILS_CONF_LOG_BUFFER_SIZE + int "Buffer size for formatting messages" + default 256 endmenu menu "Memory functions" diff --git a/README.md b/README.md index 1436d18..7257c7a 100644 --- a/README.md +++ b/README.md @@ -104,21 +104,17 @@ Since `esp-lib-utils` configures its functionality through the *esp_utils_conf.h ```c ... -/* Set to 1 if use `ESP_UTILS_LOG*()` macros */ -#define ESP_UTILS_CONF_ENABLE_LOG (1) // 0/1 -#if ESP_UTILS_CONF_ENABLE_LOG - /** - * Global log level, logs with a level lower than this will not be compiled. Choose one of the following: - * - ESP_UTILS_LOG_LEVEL_DEBUG: Extra information which is not necessary for normal use (values, pointers, sizes, etc) - * (lowest level) - * - ESP_UTILS_LOG_LEVEL_INFO: Information messages which describe the normal flow of events - * - ESP_UTILS_LOG_LEVEL_WARNING: Error conditions from which recovery measures have been taken - * - ESP_UTILS_LOG_LEVEL_ERROR: Critical errors, software module cannot recover on its own (highest level) - * - */ - #define ESP_UTILS_CONF_LOG_LEVEL (ESP_UTILS_LOG_LEVEL_DEBUG) - ... -#endif // ESP_UTILS_CONF_ENABLE_LOG +/** + * Global log level, logs with a level lower than this will not be compiled. Choose one of the following: + * - ESP_UTILS_LOG_LEVEL_DEBUG: Extra information which is not necessary for normal use (values, pointers, sizes, etc) + * (lowest level) + * - ESP_UTILS_LOG_LEVEL_INFO: Information messages which describe the normal flow of events + * - ESP_UTILS_LOG_LEVEL_WARNING: Error conditions from which recovery measures have been taken + * - ESP_UTILS_LOG_LEVEL_ERROR: Critical errors, software module cannot recover on its own + * - ESP_UTILS_LOG_LEVEL_NONE: No log output (highest level) (Minimum code size) + * + */ +#define ESP_UTILS_CONF_LOG_LEVEL (ESP_UTILS_LOG_LEVEL_DEBUG) ... ``` @@ -166,10 +162,10 @@ bool test_check_false_goto(void) ESP_UTILS_CHECK_FALSE_GOTO(true, err, "Check false goto failed"); ESP_UTILS_CHECK_FALSE_GOTO(false, end, "Check false goto success"); - ESP_UTILS_CHECK_TAG(err) +err: return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -191,10 +187,10 @@ bool test_check_error_goto(void) ESP_UTILS_CHECK_ERROR_GOTO(ESP_OK, err, "Check error goto failed"); ESP_UTILS_CHECK_ERROR_GOTO(ESP_FAIL, end, "Check error goto success"); - ESP_UTILS_CHECK_TAG(err) +err: return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -216,10 +212,10 @@ static bool test_check_null_goto(void) ESP_UTILS_CHECK_NULL_GOTO((void *)1, err, "Check null goto failed"); ESP_UTILS_CHECK_NULL_GOTO(NULL, end, "Check null goto success"); - ESP_UTILS_CHECK_TAG(err) +err: return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } diff --git a/esp_utils_conf.h b/esp_utils_conf.h index 4804dc8..750551a 100644 --- a/esp_utils_conf.h +++ b/esp_utils_conf.h @@ -12,49 +12,37 @@ ///////////////////////////////////////////////// Check Configurations ///////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** - * These functions are used to check the function parameters, return value, etc. Disable them will reduce the code size. + * Check handle method, choose one of the following: + * - ESP_UTILS_CHECK_HANDLE_WITH_NONE: Do nothing when check failed (Minimum code size) + * - ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG: Print error message when check failed (Recommended) + * - ESP_UTILS_CHECK_HANDLE_WITH_ASSERT: Assert when check failed * */ -/* Set to 1 if use `ESP_UTILS_CHECK_*()` macros */ -#define ESP_UTILS_CONF_ENABLE_CHECK (1) // 0/1 -#if ESP_UTILS_CONF_ENABLE_CHECK - /* Set to 1 if print message when check failed */ - #define ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG (1) // 0/1 - - /* Set to 1 if assert when check failed */ - #define ESP_UTILS_CONF_CHECK_WITH_ASSERT (0) // 0/1 -#endif // ESP_UTILS_CONF_ENABLE_CHECK +#define ESP_UTILS_CONF_CHECK_HANDLE_METHOD (ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////// Log Configurations ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** - * These functions are used to print log messages. Disable them will reduce the code size. + * Global log level, logs with a level lower than this will not be compiled. Choose one of the following: + * - ESP_UTILS_LOG_LEVEL_DEBUG: Extra information which is not necessary for normal use (values, pointers, sizes, etc) + * (lowest level) + * - ESP_UTILS_LOG_LEVEL_INFO: Information messages which describe the normal flow of events + * - ESP_UTILS_LOG_LEVEL_WARNING: Error conditions from which recovery measures have been taken + * - ESP_UTILS_LOG_LEVEL_ERROR: Critical errors, software module cannot recover on its own + * - ESP_UTILS_LOG_LEVEL_NONE: No log output (highest level) (Minimum code size) * */ -/* Set to 1 if use `ESP_UTILS_LOG*()` macros */ -#define ESP_UTILS_CONF_ENABLE_LOG (1) // 0/1 -#if ESP_UTILS_CONF_ENABLE_LOG - /** - * Global log level, logs with a level lower than this will not be compiled. Choose one of the following: - * - ESP_UTILS_LOG_LEVEL_DEBUG: Extra information which is not necessary for normal use (values, pointers, sizes, etc) - * (lowest level) - * - ESP_UTILS_LOG_LEVEL_INFO: Information messages which describe the normal flow of events - * - ESP_UTILS_LOG_LEVEL_WARNING: Error conditions from which recovery measures have been taken - * - ESP_UTILS_LOG_LEVEL_ERROR: Critical errors, software module cannot recover on its own (highest level) - * - */ - #define ESP_UTILS_CONF_LOG_LEVEL (ESP_UTILS_LOG_LEVEL_INFO) - #if ESP_UTILS_CONF_LOG_LEVEL == ESP_UTILS_LOG_LEVEL_DEBUG +#define ESP_UTILS_CONF_LOG_LEVEL (ESP_UTILS_LOG_LEVEL_INFO) +#if ESP_UTILS_CONF_LOG_LEVEL == ESP_UTILS_LOG_LEVEL_DEBUG - /* Set to 1 if print trace log messages when enter/exit functions, useful for debugging */ - #define ESP_UTILS_CONF_ENABLE_LOG_TRACE (0) + /* Set to 1 if print trace log messages when enter/exit functions, useful for debugging */ + #define ESP_UTILS_CONF_ENABLE_LOG_TRACE (0) - #endif // ESP_UTILS_CONF_LOG_LEVEL +#endif // ESP_UTILS_CONF_LOG_LEVEL - /* Log format buffer size */ - #define ESP_UTILS_CONF_LOG_BUFFER_SIZE (256) -#endif // ESP_UTILS_CONF_ENABLE_LOG +/* Log format buffer size */ +#define ESP_UTILS_CONF_LOG_BUFFER_SIZE (256) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// Memory Configurations ///////////////////////////////////////////////// @@ -96,8 +84,8 @@ * 3. Even if the patch version is not consistent, it will not affect normal functionality. * */ -#define ESP_UTILS_CONF_FILE_VERSION_MAJOR 0 -#define ESP_UTILS_CONF_FILE_VERSION_MINOR 1 +#define ESP_UTILS_CONF_FILE_VERSION_MAJOR 1 +#define ESP_UTILS_CONF_FILE_VERSION_MINOR 0 #define ESP_UTILS_CONF_FILE_VERSION_PATCH 0 // *INDENT-OFF* diff --git a/idf_component.yml b/idf_component.yml index 964f92e..e489f8a 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "0.1.0" +version: "0.1.1" description: esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory. url: https://github.com/esp-arduino-libs/esp-lib-utils repository: https://github.com/esp-arduino-libs/esp-lib-utils.git diff --git a/library.properties b/library.properties index cd7e435..a7569ee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=esp-lib-utils -version=0.1.0 +version=0.1.1 author=espressif maintainer=espressif sentence=esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory. diff --git a/src/check/esp_utils_check.h b/src/check/esp_utils_check.h index 38adce6..75485cd 100644 --- a/src/check/esp_utils_check.h +++ b/src/check/esp_utils_check.h @@ -7,90 +7,10 @@ #include "esp_utils_conf_internal.h" #include "log/esp_utils_log.h" -#if !ESP_UTILS_CONF_ENABLE_CHECK - -#ifndef ESP_UTILS_CHECK_TAG -#define ESP_UTILS_CHECK_TAG(goto_tag) -#endif - -#define ESP_UTILS_CHECK_NULL_RETURN(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_NULL_GOTO(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_NULL_EXIT(x, ...) ((void)(x)) - -#define ESP_UTILS_CHECK_FALSE_RETURN(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_FALSE_GOTO(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) ((void)(x)) - -#define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_ERROR_GOTO(x, ...) ((void)(x)) -#define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) ((void)(x)) - -#ifdef __cplusplus -#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) ((void)(x)) -#define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, fmt, ...) ((void)(x)) -#define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, fmt, ...) ((void)(x)) -#endif // __cplusplus - -#else - -#if ESP_UTILS_CONF_CHECK_WITH_ASSERT - -#ifndef ESP_UTILS_CHECK_TAG -#define ESP_UTILS_CHECK_TAG(goto_tag) -#endif - -#define ESP_UTILS_CHECK_NULL_RETURN(x, ...) assert((x) != NULL) -#define ESP_UTILS_CHECK_NULL_GOTO(x, ...) assert((x) != NULL) -#define ESP_UTILS_CHECK_NULL_EXIT(x, ...) assert((x) != NULL) - -#define ESP_UTILS_CHECK_FALSE_RETURN(x, ...) assert(x) -#define ESP_UTILS_CHECK_FALSE_GOTO(x, ...) assert(x) -#define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) assert(x) - -#define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) assert((x) != ESP_OK) -#define ESP_UTILS_CHECK_ERROR_GOTO(x, ...) assert((x) != ESP_OK) -#define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) assert((x) != ESP_OK) - -#ifdef __cplusplus -#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ...) do {\ - try { \ - x; \ - } catch (const std::exception &e) { \ - assert(false); \ - } \ - } while (0) - -#define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, ...) do {\ - try { \ - x; \ - } catch (const std::exception &e) { \ - assert(false); \ - } \ - } while (0) - -#define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, ...) do {\ - try { \ - x; \ - } catch (const std::exception &e) { \ - assert(false); \ - } \ - } while (0) -#endif // __cplusplus - -#else - -#ifndef unlikely -#define unlikely(x) (x) -#endif - -#ifndef ESP_UTILS_CHECK_TAG -#define ESP_UTILS_CHECK_TAG(goto_tag) goto_tag: -#endif - -#if ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG +#if ESP_UTILS_CONF_CHECK_HANDLE_METHOD == ESP_UTILS_CHECK_HANDLE_WITH_NONE /** - * @brief Check if the pointer is NULL; if NULL, log an error and return the specified value. + * @brief Check if the pointer is NULL; if NULL, return the specified value. * * @param x Pointer to check * @param ret Value to return if the pointer is NULL @@ -99,13 +19,12 @@ */ #define ESP_UTILS_CHECK_NULL_RETURN(x, ret, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while(0) /** - * @brief Check if the pointer is NULL; if NULL, log an error and goto the specified label. + * @brief Check if the pointer is NULL; if NULL, goto the specified label. * * @param x Pointer to check * @param goto_tag Label to jump to if the pointer is NULL @@ -114,13 +33,12 @@ */ #define ESP_UTILS_CHECK_NULL_GOTO(x, goto_tag, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while(0) /** - * @brief Check if the pointer is NULL; if NULL, log an error and return without a value. + * @brief Check if the pointer is NULL; if NULL, return without a value. * * @param x Pointer to check * @param fmt Format string for the error message @@ -128,13 +46,12 @@ */ #define ESP_UTILS_CHECK_NULL_EXIT(x, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while(0) /** - * @brief Check if the value is false; if false, log an error and return the specified value. + * @brief Check if the value is false; if false, return the specified value. * * @param x Value to check * @param ret Value to return if the value is false @@ -143,13 +60,12 @@ */ #define ESP_UTILS_CHECK_FALSE_RETURN(x, ret, fmt, ...) do { \ if (unlikely((x) == false)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while(0) /** - * @brief Check if the value is false; if false, log an error and goto the specified label. + * @brief Check if the value is false; if false, goto the specified label. * * @param x Value to check * @param goto_tag Label to jump to if the value is false @@ -158,13 +74,12 @@ */ #define ESP_UTILS_CHECK_FALSE_GOTO(x, goto_tag, fmt, ...) do { \ if (unlikely((x) == false)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while(0) /** - * @brief Check if the value is false; if false, log an error and return without a value. + * @brief Check if the value is false; if false, return without a value. * * @param x Value to check * @param fmt Format string for the error message @@ -172,13 +87,12 @@ */ #define ESP_UTILS_CHECK_FALSE_EXIT(x, fmt, ...) do { \ if (unlikely((x) == false)) { \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while(0) /** - * @brief Check if the value is not `ESP_OK`; if not, log an error and return the specified value. + * @brief Check if the value is not `ESP_OK`; if not, return the specified value. * * @param x Value to check * @param ret Value to return if the value is false @@ -188,13 +102,12 @@ #define ESP_UTILS_CHECK_ERROR_RETURN(x, ret, fmt, ...) do { \ esp_err_t err = (x); \ if (unlikely(err != ESP_OK)) { \ - ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ return ret; \ } \ } while(0) /** - * @brief Check if the value is not `ESP_OK`; if not, log an error and goto the specified label. + * @brief Check if the value is not `ESP_OK`; if not, goto the specified label. * * @param x Value to check * @param goto_tag Label to jump to if the value is false @@ -202,81 +115,84 @@ * @param ... Additional arguments for the format string */ #define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, fmt, ...) do { \ - esp_err_t err = (x); \ - if (unlikely((err) != ESP_OK)) { \ - ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ + if (unlikely((x) != ESP_OK)) { \ goto goto_tag; \ } \ } while(0) /** - * @brief Check if the value is not `ESP_OK`; if not, log an error and return without a value. + * @brief Check if the value is not `ESP_OK`; if not, return without a value. * * @param x Value to check * @param fmt Format string for the error message * @param ... Additional arguments for the format string */ #define ESP_UTILS_CHECK_ERROR_EXIT(x, fmt, ...) do { \ - esp_err_t err = (x); \ - if (unlikely((err) != ESP_OK)) { \ - ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ + if (unlikely((x) != ESP_OK)) { \ return; \ } \ } while(0) -#ifdef __cplusplus /** * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` * */ -#if CONFIG_COMPILER_CXX_EXCEPTIONS - +#if defined(__cplusplus) && defined(CONFIG_COMPILER_CXX_EXCEPTIONS) +/** + * @brief Check if the expression throws an exception; if it does, return the specified value. + * + * @param x Value to check + * @param ret Value to return if the value is false + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ - ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while (0) +/** + * @brief Check if the expression throws an exception; if it does, goto the specified label. + * + * @param x Value to check + * @param goto_tag Label to jump to if the value is false + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ - ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while (0) +/** + * @brief Check if the expression throws an exception; if it does, return without a value. + * + * @param x Value to check + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ - ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ - ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while (0) +#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS #else -#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) (x) -#define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, fmt, ...) do {\ - x; \ - /* Aoivd unused tag warning */ \ - if (0) { \ - goto goto_tag; \ - } \ - } while (0) -#define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, fmt, ...) (x) - -#endif // CONFIG_COMPILER_CXX_EXCEPTIONS -#endif // __cplusplus +#ifndef unlikely +#define unlikely(x) (x) +#endif -#else +#if ESP_UTILS_CONF_CHECK_HANDLE_METHOD == ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG /** * @brief Check if the pointer is NULL; if NULL, log an error and return the specified value. @@ -288,6 +204,7 @@ */ #define ESP_UTILS_CHECK_NULL_RETURN(x, ret, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while(0) @@ -302,6 +219,7 @@ */ #define ESP_UTILS_CHECK_NULL_GOTO(x, goto_tag, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while(0) @@ -315,6 +233,7 @@ */ #define ESP_UTILS_CHECK_NULL_EXIT(x, fmt, ...) do { \ if (unlikely((x) == NULL)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while(0) @@ -329,6 +248,7 @@ */ #define ESP_UTILS_CHECK_FALSE_RETURN(x, ret, fmt, ...) do { \ if (unlikely((x) == false)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while(0) @@ -343,6 +263,7 @@ */ #define ESP_UTILS_CHECK_FALSE_GOTO(x, goto_tag, fmt, ...) do { \ if (unlikely((x) == false)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while(0) @@ -356,6 +277,7 @@ */ #define ESP_UTILS_CHECK_FALSE_EXIT(x, fmt, ...) do { \ if (unlikely((x) == false)) { \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while(0) @@ -371,6 +293,7 @@ #define ESP_UTILS_CHECK_ERROR_RETURN(x, ret, fmt, ...) do { \ esp_err_t err = (x); \ if (unlikely(err != ESP_OK)) { \ + ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ return ret; \ } \ } while(0) @@ -384,7 +307,9 @@ * @param ... Additional arguments for the format string */ #define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, fmt, ...) do { \ - if (unlikely((x) != ESP_OK)) { \ + esp_err_t err = (x); \ + if (unlikely((err) != ESP_OK)) { \ + ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ goto goto_tag; \ } \ } while(0) @@ -397,37 +322,154 @@ * @param ... Additional arguments for the format string */ #define ESP_UTILS_CHECK_ERROR_EXIT(x, fmt, ...) do { \ - if (unlikely((x) != ESP_OK)) { \ + esp_err_t err = (x); \ + if (unlikely((err) != ESP_OK)) { \ + ESP_UTILS_LOGE(fmt " [%s]", ##__VA_ARGS__, esp_err_to_name(err)); \ return; \ } \ } while(0) -#ifdef __cplusplus +/** + * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` + * + */ +#if defined(__cplusplus) && defined(CONFIG_COMPILER_CXX_EXCEPTIONS) +/** + * @brief Check if the expression throws an exception; if it does, log an error and return the specified value. + * + * @param x Value to check + * @param ret Value to return if the value is false + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ + ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return ret; \ } \ } while (0) +/** + * @brief Check if the expression throws an exception; if it does, log an error and goto the specified label. + * + * @param x Value to check + * @param goto_tag Label to jump to if the value is false + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ + ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ goto goto_tag; \ } \ } while (0) +/** + * @brief Check if the expression throws an exception; if it does, log an error and return without a value. + * + * @param x Value to check + * @param fmt Format string for the error message + * @param ... Additional arguments for the format string + */ #define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, fmt, ...) do {\ try { \ x; \ } catch (const std::exception &e) { \ + ESP_UTILS_LOGE("Exception caught: %s", e.what()); \ + ESP_UTILS_LOGE(fmt, ##__VA_ARGS__); \ return; \ } \ } while (0) -#endif // __cplusplus +#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS + +#elif ESP_UTILS_CONF_CHECK_HANDLE_METHOD == ESP_UTILS_CHECK_HANDLE_WITH_ASSERT -#endif // ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG -#endif // ESP_UTILS_CONF_CHECK_WITH_ASSERT -#endif // ESP_UTILS_CONF_ENABLE_CHECK +#define ESP_UTILS_CHECK_NULL_RETURN(x, ...) assert((x) != NULL) +#define ESP_UTILS_CHECK_NULL_GOTO(x, goto_tag, ...) do { \ + assert((x) != NULL); \ + /* Aoivd unused tag warning */ \ + if (0) { \ + goto goto_tag; \ + } \ + } while (0) +#define ESP_UTILS_CHECK_NULL_EXIT(x, ...) assert((x) != NULL) + +#define ESP_UTILS_CHECK_FALSE_RETURN(x, ...) assert(x) +#define ESP_UTILS_CHECK_FALSE_GOTO(x, goto_tag, ...) do { \ + assert(x); \ + /* Aoivd unused tag warning */ \ + if (0) { \ + goto goto_tag; \ + } \ + } while (0) +#define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) assert(x) + +#define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) assert((x) == ESP_OK) +#define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, ...) do { \ + assert((x) == ESP_OK); \ + /* Aoivd unused tag warning */ \ + if (0) { \ + goto goto_tag; \ + } \ + } while (0) +#define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) assert((x) == ESP_OK) + +/** + * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` + * + */ +#if defined(__cplusplus) && defined(CONFIG_COMPILER_CXX_EXCEPTIONS) +#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ...) do {\ + try { \ + x; \ + } catch (const std::exception &e) { \ + assert(false); \ + } \ + } while (0) + +#define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, ...) do {\ + try { \ + x; \ + } catch (const std::exception &e) { \ + assert(false); \ + goto goto_tag; \ + } \ + } while (0) + +#define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, ...) do {\ + try { \ + x; \ + } catch (const std::exception &e) { \ + assert(false); \ + } \ + } while (0) +#endif // __cplusplus && CONFIG_COMPILER_CXX_EXCEPTIONS + +#endif // ESP_UTILS_CONF_CHECK_HANDLE_METHOD +#endif // ESP_UTILS_CONF_CHECK_HANDLE_METHOD + +#ifdef __cplusplus +#ifndef ESP_UTILS_CHECK_EXCEPTION_RETURN +#define ESP_UTILS_CHECK_EXCEPTION_RETURN(x, ret, fmt, ...) ((void)(x)) +#endif // ESP_UTILS_CHECK_EXCEPTION_RETURN + +#ifndef ESP_UTILS_CHECK_EXCEPTION_GOTO +#define ESP_UTILS_CHECK_EXCEPTION_GOTO(x, goto_tag, fmt, ...) do { \ + (void)x; \ + /* Aoivd unused tag warning */ \ + if (0) { \ + goto goto_tag; \ + } \ + } while (0) +#endif // ESP_UTILS_CHECK_EXCEPTION_GOTO + +#ifndef ESP_UTILS_CHECK_EXCEPTION_EXIT +#define ESP_UTILS_CHECK_EXCEPTION_EXIT(x, fmt, ...) ((void)(x)) +#endif // ESP_UTILS_CHECK_EXCEPTION_EXIT +#endif // __cplusplus diff --git a/src/esp_utils_conf_kconfig.h b/src/esp_utils_conf_kconfig.h index cdba301..081dd93 100644 --- a/src/esp_utils_conf_kconfig.h +++ b/src/esp_utils_conf_kconfig.h @@ -11,51 +11,17 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////// Check Configurations ///////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/** - * Check functions related. - * - */ -#ifndef ESP_UTILS_CONF_ENABLE_CHECK - #ifdef CONFIG_ESP_UTILS_CONF_ENABLE_CHECK - #define ESP_UTILS_CONF_ENABLE_CHECK CONFIG_ESP_UTILS_CONF_ENABLE_CHECK - #else - #define ESP_UTILS_CONF_ENABLE_CHECK (0) - #endif -#endif -#ifndef ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG - #ifdef CONFIG_ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG - #define ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG CONFIG_ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG - #else - #define ESP_UTILS_CONF_CHECK_WITH_ERROR_LOG (0) - #endif -#endif -#ifndef ESP_UTILS_CONF_CHECK_WITH_ASSERT - #ifdef CONFIG_ESP_UTILS_CONF_CHECK_WITH_ASSERT - #define ESP_UTILS_CONF_CHECK_WITH_ASSERT CONFIG_ESP_UTILS_CONF_CHECK_WITH_ASSERT +#ifndef ESP_UTILS_CONF_CHECK_HANDLE_METHOD + #ifdef CONFIG_ESP_UTILS_CONF_CHECK_HANDLE_METHOD + #define ESP_UTILS_CONF_CHECK_HANDLE_METHOD CONFIG_ESP_UTILS_CONF_CHECK_HANDLE_METHOD #else - #define ESP_UTILS_CONF_CHECK_WITH_ASSERT (0) + #define ESP_UTILS_CONF_CHECK_HANDLE_METHOD (ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG) #endif #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////// LOG Configurations ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#ifndef ESP_UTILS_CONF_ENABLE_LOG - #ifdef CONFIG_ESP_UTILS_CONF_ENABLE_LOG - #define ESP_UTILS_CONF_ENABLE_LOG CONFIG_ESP_UTILS_CONF_ENABLE_LOG - #else - #define ESP_UTILS_CONF_ENABLE_LOG (0) - #endif -#endif - -#ifndef ESP_UTILS_CONF_LOG_BUFFER_SIZE - #ifdef CONFIG_ESP_UTILS_CONF_LOG_BUFFER_SIZE - #define ESP_UTILS_CONF_LOG_BUFFER_SIZE CONFIG_ESP_UTILS_CONF_LOG_BUFFER_SIZE - #else - #define ESP_UTILS_CONF_LOG_BUFFER_SIZE (256) - #endif -#endif - #ifndef ESP_UTILS_CONF_LOG_LEVEL #ifdef CONFIG_ESP_UTILS_CONF_LOG_LEVEL #define ESP_UTILS_CONF_LOG_LEVEL CONFIG_ESP_UTILS_CONF_LOG_LEVEL @@ -72,6 +38,14 @@ #endif #endif +#ifndef ESP_UTILS_CONF_LOG_BUFFER_SIZE + #ifdef CONFIG_ESP_UTILS_CONF_LOG_BUFFER_SIZE + #define ESP_UTILS_CONF_LOG_BUFFER_SIZE CONFIG_ESP_UTILS_CONF_LOG_BUFFER_SIZE + #else + #define ESP_UTILS_CONF_LOG_BUFFER_SIZE (256) + #endif +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////// Memory Configurations ///////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/esp_utils_types.h b/src/esp_utils_types.h index 3cbb70c..94768bd 100644 --- a/src/esp_utils_types.h +++ b/src/esp_utils_types.h @@ -8,6 +8,14 @@ #include "sdkconfig.h" +/** + * @brief Macros for check handle method + * + */ +#define ESP_UTILS_CHECK_HANDLE_WITH_NONE (0) /*!< Do nothing when check failed */ +#define ESP_UTILS_CHECK_HANDLE_WITH_ERROR_LOG (1) /*!< Print error message when check failed */ +#define ESP_UTILS_CHECK_HANDLE_WITH_ASSERT (2) /*!< Assert when check failed */ + /** * @brief Macros for log level * @@ -17,6 +25,7 @@ #define ESP_UTILS_LOG_LEVEL_INFO (1) /*!< Information messages which describe the normal flow of events */ #define ESP_UTILS_LOG_LEVEL_WARNING (2) /*!< Error conditions from which recovery measures have been taken */ #define ESP_UTILS_LOG_LEVEL_ERROR (3) /*!< Critical errors, software module cannot recover on its own */ +#define ESP_UTILS_LOG_LEVEL_NONE (4) /*!< No log output */ /** * @brief Macros for memory type diff --git a/src/esp_utils_versions.h b/src/esp_utils_versions.h index 7cdd8a8..60020c4 100644 --- a/src/esp_utils_versions.h +++ b/src/esp_utils_versions.h @@ -10,11 +10,11 @@ /* Library Version */ #define ESP_UTILS_VERSION_MAJOR 0 #define ESP_UTILS_VERSION_MINOR 1 -#define ESP_UTILS_VERSION_PATCH 0 +#define ESP_UTILS_VERSION_PATCH 1 /* File `esp_utils_conf.h` */ -#define ESP_UTILS_CONF_VERSION_MAJOR 0 -#define ESP_UTILS_CONF_VERSION_MINOR 1 +#define ESP_UTILS_CONF_VERSION_MAJOR 1 +#define ESP_UTILS_CONF_VERSION_MINOR 0 #define ESP_UTILS_CONF_VERSION_PATCH 0 // *INDENT-OFF* diff --git a/src/log/esp_utils_log.c b/src/log/esp_utils_log.c index 7573367..2b82b50 100644 --- a/src/log/esp_utils_log.c +++ b/src/log/esp_utils_log.c @@ -6,12 +6,13 @@ #include #include "esp_utils_conf_internal.h" -#if ESP_UTILS_CONF_ENABLE_LOG /** * @brief Extract filename from file path * * @param file_path File path + * * @return File name + * */ const char *esp_utils_log_extract_file_name(const char *file_path) { @@ -22,4 +23,3 @@ const char *esp_utils_log_extract_file_name(const char *file_path) return filename ? filename + 1 : file_path; } -#endif // ESP_UTILS_CONF_ENABLE_LOG diff --git a/src/log/esp_utils_log.h b/src/log/esp_utils_log.h index 2d36f6c..8e358f6 100644 --- a/src/log/esp_utils_log.h +++ b/src/log/esp_utils_log.h @@ -36,7 +36,6 @@ class Log { return instance; } -#if ESP_UTILS_CONF_ENABLE_LOG // Templates and conditional compilation: Filter logs by different levels template void print(const char *file, int line, const char *func, const char *format, ...) @@ -44,7 +43,7 @@ class Log { // Logs below the global level will not be compiled if constexpr (level >= ESP_UTILS_CONF_LOG_LEVEL) { // Mutex to avoid interleaved log messages - _mutex.lock(); + std::lock_guard lock(_mutex); // Use variadic arguments for formatted output va_list args; va_start(args, format); @@ -55,19 +54,12 @@ class Log { "[%c][%s][%s:%04d](%s): %s\n", logLevelToChar(level), ESP_UTILS_LOG_TAG, esp_utils_log_extract_file_name(file), line, func, _buffer ); - _mutex.unlock(); } } -#else - // When logging is disabled, the `print` function has an empty implementation - template - void print(const char *, int, const char *, const char *, ...) const {} -#endif /* ESP_UTILS_CONF_ENABLE_LOG */ private: Log() = default; -#if ESP_UTILS_CONF_ENABLE_LOG // Convert log level to string static constexpr char logLevelToChar(int level) { @@ -83,7 +75,6 @@ class Log { char _buffer[ESP_UTILS_CONF_LOG_BUFFER_SIZE]; std::mutex _mutex; -#endif }; } // namespace esp_utils @@ -145,17 +136,10 @@ const char *esp_utils_log_extract_file_name(const char *file_path); * Macros to simplify logging calls * */ -#if ESP_UTILS_CONF_ENABLE_LOG #define ESP_UTILS_LOGD(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) #define ESP_UTILS_LOGI(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_INFO, format, ##__VA_ARGS__) #define ESP_UTILS_LOGW(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) #define ESP_UTILS_LOGE(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) -#else -#define ESP_UTILS_LOGD(...) -#define ESP_UTILS_LOGI(...) -#define ESP_UTILS_LOGW(...) -#define ESP_UTILS_LOGE(...) -#endif // ESP_UTILS_CONF_ENABLE_LOG #endif // __cplusplus diff --git a/src/memory/esp_utils_mem.h b/src/memory/esp_utils_mem.h index bad5905..4bbaa15 100644 --- a/src/memory/esp_utils_mem.h +++ b/src/memory/esp_utils_mem.h @@ -33,11 +33,13 @@ struct GeneralMemoryAllocator { return nullptr; } void *ptr = esp_utils_mem_gen_malloc(n * sizeof(T)); -#if CONFIG_COMPILER_CXX_EXCEPTIONS if (ptr == nullptr) { +#if CONFIG_COMPILER_CXX_EXCEPTIONS throw std::bad_alloc(); - } +#else + abort(); #endif // CONFIG_COMPILER_CXX_EXCEPTIONS + } return static_cast(ptr); } diff --git a/test_apps/main/test_on_c.c b/test_apps/main/test_on_c.c index d07fae0..ace00c5 100644 --- a/test_apps/main/test_on_c.c +++ b/test_apps/main/test_on_c.c @@ -32,10 +32,10 @@ TEST_CASE("Test memory functions on C", "[utils][memory][C]") ESP_UTILS_CHECK_NULL_GOTO(bad_ptr, end, "Failed to allocate memory size: %d", MALLOC_BAD_SIZE); ESP_UTILS_LOGI("Malloced value: %d", bad_ptr[0]); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Memory allocation failed"); - ESP_UTILS_CHECK_TAG(end) +end: free(good_ptr); return; @@ -56,12 +56,12 @@ static bool test_check_false_goto(void) ESP_UTILS_CHECK_FALSE_GOTO(true, err, "Check false goto failed"); ESP_UTILS_CHECK_FALSE_GOTO(false, end, "Check false goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check false goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -90,12 +90,12 @@ static bool test_check_error_goto(void) ESP_UTILS_CHECK_ERROR_GOTO(ESP_OK, err, "Check error goto failed"); ESP_UTILS_CHECK_ERROR_GOTO(ESP_FAIL, end, "Check error goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check error goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -124,12 +124,12 @@ static bool test_check_null_goto(void) ESP_UTILS_CHECK_NULL_GOTO((void *)1, err, "Check null goto failed"); ESP_UTILS_CHECK_NULL_GOTO(NULL, end, "Check null goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check null goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } diff --git a/test_apps/main/test_on_cpp.cpp b/test_apps/main/test_on_cpp.cpp index e8e0851..6fa8de9 100644 --- a/test_apps/main/test_on_cpp.cpp +++ b/test_apps/main/test_on_cpp.cpp @@ -49,10 +49,10 @@ TEST_CASE("Test memory functions on cpp", "[utils][memory][CPP]") ESP_UTILS_LOGI("Malloced value: %d", bad_ptr->buffer[0]); } - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Memory allocation failed"); - ESP_UTILS_CHECK_TAG(end) +end: return; } @@ -71,12 +71,12 @@ static bool test_check_false_goto(void) ESP_UTILS_CHECK_FALSE_GOTO(true, err, "Check false goto failed"); ESP_UTILS_CHECK_FALSE_GOTO(false, end, "Check false goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check false goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -105,12 +105,12 @@ static bool test_check_error_goto(void) ESP_UTILS_CHECK_ERROR_GOTO(ESP_OK, err, "Check error goto failed"); ESP_UTILS_CHECK_ERROR_GOTO(ESP_FAIL, end, "Check error goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check error goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; } @@ -139,12 +139,12 @@ static bool test_check_null_goto(void) ESP_UTILS_CHECK_NULL_GOTO((void *)1, err, "Check null goto failed"); ESP_UTILS_CHECK_NULL_GOTO(NULL, end, "Check null goto success"); - ESP_UTILS_CHECK_TAG(err) +err: TEST_ASSERT(false && "Check null goto failed"); return false; - ESP_UTILS_CHECK_TAG(end) +end: return true; }