chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:04:25 +08:00
commit 548b49ebc0
20937 changed files with 5455372 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include_next <setjmp.h>
#include "esp_debug_helpers.h"
/*
* This is the middle layer of setjmp to be used with the unity.
*/
/** Insert backtrace before longjmp (TEST_ABORT).
*
* Currently we only do long jump before test is ignored or failed.
* If this is also called when test pass, we may need to add some check before
* backtrace is called.
*/
#define longjmp(buf, val) do {esp_backtrace_print(100); longjmp(buf, val);} while(0)
+84
View File
@@ -0,0 +1,84 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef UNITY_CONFIG_H
#define UNITY_CONFIG_H
// This file gets included from unity.h via unity_internals.h
// It is inside #ifdef __cplusplus / extern "C" block, so we can
// only use C features here
#include <esp_err.h>
#include <stddef.h>
#include <math.h>
#include "sdkconfig.h"
#ifdef CONFIG_UNITY_ENABLE_FLOAT
#define UNITY_INCLUDE_FLOAT
#else
#define UNITY_EXCLUDE_FLOAT
#endif //CONFIG_UNITY_ENABLE_FLOAT
#ifdef CONFIG_UNITY_ENABLE_DOUBLE
#define UNITY_INCLUDE_DOUBLE
#else
#define UNITY_EXCLUDE_DOUBLE
#endif //CONFIG_UNITY_ENABLE_DOUBLE
#ifdef CONFIG_UNITY_ENABLE_64BIT
#define UNITY_SUPPORT_64
#endif
#ifdef CONFIG_UNITY_ENABLE_COLOR
#define UNITY_OUTPUT_COLOR
#endif
#ifndef __cplusplus
#define UNITY_IS_NAN isnan
#define UNITY_IS_INF isinf
#else
#define UNITY_IS_NAN std::isnan
#define UNITY_IS_INF std::isinf
#endif
// Note, using __noreturn__ rather than noreturn
// https://github.com/espressif/esp-idf/issues/11339
#define UNITY_NORETURN __attribute__((__noreturn__))
#define UNITY_EXCLUDE_TIME_H
void unity_flush(void);
void unity_putc(int c);
void unity_gets(char* dst, size_t len);
void unity_exec_time_start(void);
void unity_exec_time_stop(void);
uint32_t unity_exec_time_get_ms(void);
#define UNITY_OUTPUT_CHAR(a) unity_putc(a)
#define UNITY_OUTPUT_FLUSH() unity_flush()
#define UNITY_EXEC_TIME_START() unity_exec_time_start()
#define UNITY_EXEC_TIME_STOP() unity_exec_time_stop()
#define UNITY_EXEC_TIME_MS() unity_exec_time_get_ms()
#ifdef CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER
#include "unity_test_runner.h"
#endif //CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER
#ifdef CONFIG_UNITY_ENABLE_FIXTURE
// Two separate "extras" options here:
// 1. Disable memory allocation wrappers in Unity Fixture
#define UNITY_FIXTURE_NO_EXTRAS
// 2. Add IDF-specific additions to Unity Fixture
#include "unity_fixture_extras.h"
#endif // CONFIG_UNITY_ENABLE_FIXTURE
// shorthand to check esp_err_t return code
#define TEST_ESP_OK(rc) TEST_ASSERT_EQUAL_HEX32(ESP_OK, rc)
#define TEST_ESP_ERR(err, rc) TEST_ASSERT_EQUAL_HEX32(err, rc)
#endif //UNITY_CONFIG_H
@@ -0,0 +1,70 @@
/*
* SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* IDF-specific additions to "Unity Fixture".
* This file doesn't need to be included directly, it gets included into unity.h
* through unity_config.h.
*/
#pragma once
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(CONFIG_IDF_TARGET) || defined(CONFIG_IDF_TARGET_LINUX)
#define UNITY_MAYBE_EXIT(rc) do { exit(rc); } while(0)
#else
#define UNITY_MAYBE_EXIT(rc) do { (void) rc; } while(0)
#endif
/* A shorthand for running all tests called from one function "func_", from the app_main function.
* Use this when there is more than one test group.
*
* Example:
*
* #include "unity.h"
* #include "unity_fixture.h"
*
* static_void run_all_tests(void) {
* RUN_TEST_GROUP(group1); // test group defined in another file, e.g. test_group1.c
* RUN_TEST_GROUP(group2); // test group defined in another file, e.g. test_group2.c
* }
*
* void app_main(void) {
* UNITY_MAIN_FUNC(run_all_tests);
* }
*/
#define UNITY_MAIN_FUNC(func_) do { \
const char* argv[] = { "test", "-v" }; \
const int argc = sizeof(argv)/sizeof(argv[0]); \
int rc = UnityMain(argc, argv, func_); \
printf("\nTests finished, rc=%d\n", rc); \
UNITY_MAYBE_EXIT(rc); \
} while(0)
/* A shorthand for running one test group from the app_main function, when there is only
* one test group and it is defined in the same file.
*
* Example:
*
* #include "unity.h"
* #include "unity_fixture.h"
*
* TEST_GROUP(my_feature);
* // also define TEST_SETUP, TEST_TEARDOWN, TESTs, TEST_GROUP_RUNNER
*
* void app_main(void) {
* UNITY_MAIN(my_feature);
* }
*/
#define UNITY_MAIN(group_) UNITY_MAIN_FUNC(TEST_ ## group_ ## _GROUP_RUNNER)
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,209 @@
/*
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
// This file gets included from unity.h via unity_internals.h via unity_config.h
// It is inside #ifdef __cplusplus / extern "C" block, so we can
// only use C features here
// Define helpers to register test cases from multiple files
#define UNITY_EXPAND2(a, b) a ## b
#define UNITY_EXPAND(a, b) UNITY_EXPAND2(a, b)
#define UNITY_TEST_UID(what) UNITY_EXPAND(what, __LINE__)
#define UNITY_TEST_REG_HELPER reg_helper ## UNITY_TEST_UID
#define UNITY_TEST_DESC_UID desc ## UNITY_TEST_UID
// get count of __VA_ARGS__
#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)
#define PP_ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_RSEQ_N() 9,8,7,6,5,4,3,2,1,0
// support max 5 test func now
#define FN_NAME_SET_1(a) {#a}
#define FN_NAME_SET_2(a, b) {#a, #b}
#define FN_NAME_SET_3(a, b, c) {#a, #b, #c}
#define FN_NAME_SET_4(a, b, c, d) {#a, #b, #c, #d}
#define FN_NAME_SET_5(a, b, c, d, e) {#a, #b, #c, #d, #e}
#define FN_NAME_SET2(n) FN_NAME_SET_##n
#define FN_NAME_SET(n, ...) FN_NAME_SET2(n)(__VA_ARGS__)
#define UNITY_TEST_FN_SET(...) \
static test_func UNITY_TEST_UID(test_functions)[] = {__VA_ARGS__}; \
static const char* UNITY_TEST_UID(test_fn_name)[] = FN_NAME_SET(PP_NARG(__VA_ARGS__), __VA_ARGS__)
typedef void (* test_func)(void);
typedef struct test_desc_t
{
const char* name;
const char* desc;
test_func* fn;
const char* file;
int line;
uint8_t test_fn_count;
const char ** test_fn_name;
struct test_desc_t* next;
} test_desc_t;
void unity_testcase_register(test_desc_t* desc);
/* Test case macro, a-la CATCH framework.
First argument is a free-form description,
second argument is (by convention) a list of identifiers, each one in square brackets.
Identifiers are used to group related tests, or tests with specific properties.
Use like:
TEST_CASE("Frobnicator forbnicates", "[frobnicator][rom]")
{
// test goes here
}
*/
#define TEST_CASE(name_, desc_) \
static void UNITY_TEST_UID(test_func_) (void); \
static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \
{ \
static test_func test_fn_[] = {&UNITY_TEST_UID(test_func_)}; \
static test_desc_t UNITY_TEST_UID(test_desc_) = { \
.name = name_, \
.desc = desc_, \
.fn = test_fn_, \
.file = __FILE__, \
.line = __LINE__, \
.test_fn_count = 1, \
.test_fn_name = NULL, \
.next = NULL \
}; \
unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \
}\
static void UNITY_TEST_UID(test_func_) (void)
/*
* Multiple stages test cases will handle the case that test steps are separated by DUT reset.
* e.g: we want to verify some function after SW reset, WDT reset or deep sleep reset.
*
* First argument is a free-form description,
* second argument is (by convention) a list of identifiers, each one in square brackets.
* subsequent arguments are names test functions separated by reset.
* e.g:
* TEST_CASE_MULTIPLE_STAGES("run light sleep after deep sleep","[sleep]", goto_deepsleep, light_sleep_after_deep_sleep_wakeup);
* */
#define TEST_CASE_MULTIPLE_STAGES(name_, desc_, ...) \
UNITY_TEST_FN_SET(__VA_ARGS__); \
static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \
{ \
static test_desc_t UNITY_TEST_UID(test_desc_) = { \
.name = name_, \
.desc = desc_"[multi_stage]", \
.fn = UNITY_TEST_UID(test_functions), \
.file = __FILE__, \
.line = __LINE__, \
.test_fn_count = PP_NARG(__VA_ARGS__), \
.test_fn_name = UNITY_TEST_UID(test_fn_name), \
.next = NULL \
}; \
unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \
}
/*
* First argument is a free-form description,
* second argument is (by convention) a list of identifiers, each one in square brackets.
* subsequent arguments are names of test functions for different DUTs
* e.g:
* TEST_CASE_MULTIPLE_DEVICES("master and slave spi","[spi][test_env=UT_T2_1]", master_test, slave_test);
* */
#define TEST_CASE_MULTIPLE_DEVICES(name_, desc_, ...) \
UNITY_TEST_FN_SET(__VA_ARGS__); \
static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \
{ \
static test_desc_t UNITY_TEST_UID(test_desc_) = { \
.name = name_, \
.desc = desc_"[multi_device]", \
.fn = UNITY_TEST_UID(test_functions), \
.file = __FILE__, \
.line = __LINE__, \
.test_fn_count = PP_NARG(__VA_ARGS__), \
.test_fn_name = UNITY_TEST_UID(test_fn_name), \
.next = NULL \
}; \
unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \
}
/**
* Note: initialization of test_desc_t fields above has to be done exactly
* in the same order as the fields are declared in the structure.
* Otherwise the initializer will not be valid in C++ (which doesn't
* support designated initializers). G++ can parse the syntax, but
* field names are treated as annotations and don't affect initialization
* order. Also make sure all the fields are initialized.
*/
void unity_run_test_by_name(const char *name);
void unity_run_test_by_index(int test_index);
void unity_run_tests_by_tag(const char *tag, bool invert);
void unity_run_all_tests(void);
void unity_run_menu(void);
int unity_get_test_count(void);
bool unity_get_test_info(int test_index, test_desc_t* out_info);
#include "sdkconfig.h" //to get IDF_TARGET_xxx
#define CONFIG_IDF_TARGET_NA 0
/*
* This macro is to disable those tests and their callees that cannot be built or run temporarily
* (needs update or runners).
*
* Usage:
* ```
* #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S2)
* TEST_CASE("only for esp32", "")
* {
* }
* #endif
* ```
*/
#define TEMPORARY_DISABLED_FOR_TARGETS(...) (_UNITY_DFT_10(__VA_ARGS__, NA, NA, NA, NA, NA, NA, NA, NA, NA))
/*
* This macro is to disable those tests and their callees that is totally impossible to run on the
* specific targets. Usage same as TEMPORARY_DISABLED_FOR_TARGETS.
*/
#define DISABLED_FOR_TARGETS(...) TEMPORARY_DISABLED_FOR_TARGETS(__VA_ARGS__)
#define _UNITY_DFT_10(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_9(__VA_ARGS__))
#define _UNITY_DFT_9(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_8(__VA_ARGS__))
#define _UNITY_DFT_8(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_7(__VA_ARGS__))
#define _UNITY_DFT_7(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_6(__VA_ARGS__))
#define _UNITY_DFT_6(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_5(__VA_ARGS__))
#define _UNITY_DFT_5(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_4(__VA_ARGS__))
#define _UNITY_DFT_4(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_3(__VA_ARGS__))
#define _UNITY_DFT_3(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_2(__VA_ARGS__))
#define _UNITY_DFT_2(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET || _UNITY_DFT_1(__VA_ARGS__))
#define _UNITY_DFT_1(TARGET, ...) (CONFIG_IDF_TARGET_##TARGET)
@@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity_test_utils_memory.h"
#include "unity_test_utils_cache.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Delete task ensuring dynamic memory (for stack, tcb etc.) gets freed up immediately
*
* @param[in] thandle Handle of task to be deleted (should not be NULL or self handle)
*/
void unity_utils_task_delete(TaskHandle_t thandle);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Disable flash cache and run user stub function and then enable flash cache again
*
* @note You should make sure the passed-in function is in internal RAM.
*
* @param post_cache_disable User function to be invoked after cache is disabled.
* @param user_ctx User context to be passed to user function.
*/
void unity_utils_run_cache_disable_stub(void (*post_cache_disable)(void *), void *user_ctx);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,80 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Adjust the allowed memory leak thresholds for unit tests.
*
* Usually, unit tests will check if memory is leaked. Some functionality used by unit tests may unavoidably
* leak memory. This function allows to adjust that memory leak threshold.
*
* @param leak_level Maximum allowed memory leak which will not trigger a unit test failure.
*/
void unity_utils_set_leak_level(size_t leak_level);
/**
* @brief Start/Restart memory leak checking.
*
* Records the current free memory values at time of calling. After the test case, it may be checked with
* \c unity_utils_finish_and_evaluate_leaks.
*
* If this function is called repeatedly, only the free memory values at the last time of calling will prevail
* as reference.
*/
void unity_utils_record_free_mem(void);
/**
* @brief Calculate leaks and check they are below against a threshold
*
* This function is for internal use, users shouldn't have a reason to call this.
*
* Calculates the leak from \c before_free and \c after_free and checks that the difference does not exceed
* \c threshold. It uses a unity assert to to the check and report in case of failure.
* A summary of the leaked data will be printed in all cases.
*/
void unity_utils_check_leak(unsigned int before_free,
unsigned int after_free,
const char *type,
unsigned int threshold);
/**
* @brief Evaluate memory leak checking according to the provided thresholds.
*
* If the current memory leak level (counted from the last time calling \c unity_utils_record_free_mem() ) exceeds
* \c threshold, a unit test failure will be triggered.
*/
void unity_utils_evaluate_leaks_direct(size_t threshold);
/**
* @brief Evaluate memory leaks.
*
* If the current memory leak level (counted from the last time calling \c unity_utils_record_free_mem() ) exceeds
* the threshold set before via \c unity_utils_set_leak_level(), a unit test failure will be triggered.
*
* @note The user MUST set the allowed leak threshold before via \c unity_utils_set_leak_level(), otherwise the
* allowed leak threshold is undefined.
*/
void unity_utils_evaluate_leaks(void);
/**
* @brief Helper function to setup and initialize heap tracing.
*
* @param num_heap_records the size of the heap record buffer,
* counted in number of heap record elements (heap_trace_record_t).
* Use a default value of 80 if no special requirements need to be met.
*/
void unity_utils_setup_heap_record(size_t num_heap_records);
#ifdef __cplusplus
}
#endif