2021-11-18 01:27:30 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2017-01-04 23:51:02 -05:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-20 21:40:42 -05:00
|
|
|
// Utilities for esp-idf unit tests
|
|
|
|
|
2017-08-21 10:33:03 -04:00
|
|
|
#include <stdint.h>
|
2017-02-20 21:40:42 -05:00
|
|
|
#include <esp_partition.h>
|
2018-10-25 00:52:32 -04:00
|
|
|
#include "sdkconfig.h"
|
2020-02-29 04:32:53 -05:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
2020-08-12 23:56:52 -04:00
|
|
|
#include "unity.h"
|
2020-12-03 22:35:21 -05:00
|
|
|
#include "soc/soc_caps.h"
|
2018-10-25 00:52:32 -04:00
|
|
|
/* include performance pass standards header file */
|
|
|
|
#include "idf_performance.h"
|
2020-08-12 23:56:52 -04:00
|
|
|
#include "idf_performance_target.h"
|
2018-10-25 00:52:32 -04:00
|
|
|
|
2020-02-04 13:08:41 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-10-25 00:52:32 -04:00
|
|
|
/* For performance check with unity test on IDF */
|
|
|
|
/* These macros should only be used with ESP-IDF.
|
|
|
|
* To use performance check, we need to first define pass standard in idf_performance.h.
|
|
|
|
*/
|
2019-10-20 01:21:23 -04:00
|
|
|
|
|
|
|
//macros call this to expand an argument instead of directly converting into str
|
|
|
|
#define PERFORMANCE_STR(s) #s
|
|
|
|
//macros call this to contact strings after expanding them
|
|
|
|
#define PERFORMANCE_CON(a, b) _PERFORMANCE_CON(a, b)
|
|
|
|
#define _PERFORMANCE_CON(a, b) a##b
|
|
|
|
|
2020-11-30 18:23:32 -05:00
|
|
|
#if !CONFIG_UNITY_IGNORE_PERFORMANCE_TESTS
|
|
|
|
#define _TEST_PERFORMANCE_ASSERT TEST_ASSERT
|
|
|
|
#else
|
|
|
|
#define _TEST_PERFORMANCE_ASSERT(ARG) printf("Ignoring performance test [%s]\n", PERFORMANCE_STR(ARG))
|
|
|
|
#endif
|
|
|
|
|
2021-05-28 08:08:51 -04:00
|
|
|
#define TEST_PERFORMANCE_LESS_THAN(name, value_fmt, value, ...) do { \
|
|
|
|
IDF_LOG_PERFORMANCE(#name, value_fmt, value, ##__VA_ARGS__); \
|
2020-11-30 18:23:32 -05:00
|
|
|
_TEST_PERFORMANCE_ASSERT(value < PERFORMANCE_CON(IDF_PERFORMANCE_MAX_, name)); \
|
2018-10-25 00:52:32 -04:00
|
|
|
} while(0)
|
|
|
|
|
2021-05-28 08:08:51 -04:00
|
|
|
#define TEST_PERFORMANCE_GREATER_THAN(name, value_fmt, value, ...) do { \
|
|
|
|
IDF_LOG_PERFORMANCE(#name, value_fmt, value, ##__VA_ARGS__); \
|
2020-11-30 18:23:32 -05:00
|
|
|
_TEST_PERFORMANCE_ASSERT(value > PERFORMANCE_CON(IDF_PERFORMANCE_MIN_, name)); \
|
2018-10-25 00:52:32 -04:00
|
|
|
} while(0)
|
|
|
|
|
2020-12-03 22:35:21 -05:00
|
|
|
/* Macros to be used when performance is calculated using the cache compensated timer
|
|
|
|
will not assert if ccomp not supported */
|
|
|
|
#if SOC_CCOMP_TIMER_SUPPORTED
|
2021-05-28 08:08:51 -04:00
|
|
|
#define TEST_PERFORMANCE_CCOMP_GREATER_THAN(name, value_fmt, value, ...) \
|
|
|
|
TEST_PERFORMANCE_GREATER_THAN(name, value_fmt, value, ##__VA_ARGS__)
|
|
|
|
#define TEST_PERFORMANCE_CCOMP_LESS_THAN(name, value_fmt, value, ...) \
|
|
|
|
TEST_PERFORMANCE_LESS_THAN(name, value_fmt, value, ##__VA_ARGS__)
|
2020-12-03 22:35:21 -05:00
|
|
|
#else
|
2021-05-28 08:08:51 -04:00
|
|
|
#define TEST_PERFORMANCE_CCOMP_GREATER_THAN(name, value_fmt, value, ...) \
|
|
|
|
IDF_LOG_PERFORMANCE(#name, value_fmt, value, ##__VA_ARGS__)
|
|
|
|
#define TEST_PERFORMANCE_CCOMP_LESS_THAN(name, value_fmt, value, ...) \
|
|
|
|
IDF_LOG_PERFORMANCE(#name, value_fmt, value, ##__VA_ARGS__)
|
2020-12-03 22:35:21 -05:00
|
|
|
#endif //SOC_CCOMP_TIMER_SUPPORTED
|
|
|
|
|
|
|
|
|
2018-10-25 00:52:32 -04:00
|
|
|
/* @brief macro to print IDF performance
|
2021-06-23 02:10:07 -04:00
|
|
|
* @param item : performance item name. a string pointer.
|
2018-10-25 00:52:32 -04:00
|
|
|
* @param value_fmt: print format and unit of the value, for example: "%02fms", "%dKB"
|
|
|
|
* @param value : the performance value.
|
|
|
|
*/
|
2021-05-28 08:08:51 -04:00
|
|
|
#define IDF_LOG_PERFORMANCE(item, value_fmt, value, ...) \
|
2021-09-01 20:45:19 -04:00
|
|
|
printf("[Performance][%s]: " value_fmt "\n", item, value, ##__VA_ARGS__)
|
2018-10-25 00:52:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Some definitions applicable to Unity running in FreeRTOS */
|
|
|
|
#define UNITY_FREERTOS_PRIORITY CONFIG_UNITY_FREERTOS_PRIORITY
|
|
|
|
#define UNITY_FREERTOS_CPU CONFIG_UNITY_FREERTOS_CPU
|
|
|
|
#define UNITY_FREERTOS_STACK_SIZE CONFIG_UNITY_FREERTOS_STACK_SIZE
|
2017-02-20 21:40:42 -05:00
|
|
|
|
|
|
|
/* Return the 'flash_test' custom data partition (type 0x55)
|
|
|
|
defined in the custom partition table.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
const esp_partition_t *get_test_data_partition(void);
|
2017-01-04 23:51:02 -05:00
|
|
|
|
2017-08-21 10:33:03 -04:00
|
|
|
/**
|
|
|
|
* @brief Initialize reference clock
|
|
|
|
*
|
|
|
|
* Reference clock provides timestamps at constant 1 MHz frequency, even when
|
|
|
|
* the APB frequency is changing.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void ref_clock_init(void);
|
2017-08-21 10:33:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deinitialize reference clock
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void ref_clock_deinit(void);
|
2017-08-21 10:33:03 -04:00
|
|
|
|
2017-11-30 06:31:51 -05:00
|
|
|
|
2017-08-21 10:33:03 -04:00
|
|
|
/**
|
|
|
|
* @brief Get reference clock timestamp
|
|
|
|
* @return number of microseconds since the reference clock was initialized
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
uint64_t ref_clock_get(void);
|
2017-11-30 06:31:51 -05:00
|
|
|
|
2018-10-25 00:52:32 -04:00
|
|
|
/**
|
|
|
|
* @brief Entry point of the test application
|
|
|
|
*
|
|
|
|
* Starts Unity test runner in a separate task and returns.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void test_main(void);
|
2018-09-25 20:17:46 -04:00
|
|
|
|
|
|
|
void unity_reset_leak_checks(void);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call this function from a test case which requires TCP/IP or
|
|
|
|
* LWIP functionality.
|
|
|
|
*
|
|
|
|
* @note This should be the first function the test case calls, as it will
|
|
|
|
* allocate memory on first use (and also reset the test case leak checker).
|
|
|
|
*/
|
|
|
|
void test_case_uses_tcpip(void);
|
|
|
|
|
2017-11-30 06:31:51 -05:00
|
|
|
/**
|
2018-12-13 03:58:34 -05:00
|
|
|
* @brief wait for signals with parameters.
|
2017-11-30 06:31:51 -05:00
|
|
|
*
|
|
|
|
* for multiple devices test cases, DUT might need to wait for other DUTs before continue testing.
|
|
|
|
* As all DUTs are independent, need user (or test script) interaction to make test synchronized.
|
|
|
|
*
|
|
|
|
* Here we provide signal functions for this.
|
|
|
|
* For example, we're testing GPIO, DUT1 has one pin connect to with DUT2.
|
|
|
|
* DUT2 will output high level and then DUT1 will read input.
|
|
|
|
* DUT1 should call `unity_wait_for_signal("output high level");` before it reads input.
|
|
|
|
* DUT2 should call `unity_send_signal("output high level");` after it finished setting output high level.
|
|
|
|
* According to the console logs:
|
|
|
|
*
|
|
|
|
* DUT1 console:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Waiting for signal: [output high level]!
|
|
|
|
* Please press "Enter" key to once any board send this signal.
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* DUT2 console:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Send signal: [output high level]!
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Then we press Enter key on DUT1's console, DUT1 starts to read input and then test success.
|
|
|
|
*
|
2018-12-13 03:58:34 -05:00
|
|
|
* Another example, we have 2 DUTs in multiple devices test, and DUT1 need to get DUT2's mac address to perform BT connection.
|
|
|
|
* DUT1 should call `unity_wait_for_signal_param("dut2 mac address", mac, 19);` to wait for DUT2's mac address.
|
|
|
|
* DUT2 should call `unity_send_signal_param("dut2 mac address", "10:20:30:40:50:60");` to send to DUT1 its mac address.
|
|
|
|
* According to the console logs:
|
|
|
|
*
|
|
|
|
* DUT1 console:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Waiting for signal: [dut2 mac address]!
|
|
|
|
* Please input parameter value from any board send this signal and press "Enter" key.
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* DUT2 console:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* Send signal: [dut2 mac address][10:20:30:40:50:60]!
|
|
|
|
* ```
|
|
|
|
*
|
2017-11-30 06:31:51 -05:00
|
|
|
* @param signal_name signal name which DUT expected to wait before proceed testing
|
2018-12-13 03:58:34 -05:00
|
|
|
* @param parameter_buf buffer to receive parameter
|
|
|
|
* @param buf_len length of parameter_buf.
|
|
|
|
* Currently we have a limitation that it will write 1 extra byte at the end of string.
|
|
|
|
* We need to use a buffer with 2 bytes longer than actual string length.
|
2017-11-30 06:31:51 -05:00
|
|
|
*/
|
2018-12-13 03:58:34 -05:00
|
|
|
void unity_wait_for_signal_param(const char* signal_name, char *parameter_buf, uint8_t buf_len);
|
2017-11-30 06:31:51 -05:00
|
|
|
|
|
|
|
/**
|
2018-12-13 03:58:34 -05:00
|
|
|
* @brief wait for signals.
|
|
|
|
*
|
|
|
|
* @param signal_name signal name which DUT expected to wait before proceed testing
|
|
|
|
*/
|
|
|
|
static inline void unity_wait_for_signal(const char* signal_name)
|
|
|
|
{
|
|
|
|
unity_wait_for_signal_param(signal_name, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief DUT send signal and pass parameter to other devices.
|
|
|
|
*
|
|
|
|
* @param signal_name signal name which DUT send once it finished preparing.
|
|
|
|
* @param parameter a string to let remote device to receive.
|
|
|
|
*/
|
|
|
|
void unity_send_signal_param(const char* signal_name, const char *parameter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief DUT send signal with parameter.
|
2017-11-30 06:31:51 -05:00
|
|
|
*
|
|
|
|
* @param signal_name signal name which DUT send once it finished preparing.
|
|
|
|
*/
|
2018-12-13 03:58:34 -05:00
|
|
|
static inline void unity_send_signal(const char* signal_name)
|
|
|
|
{
|
|
|
|
unity_send_signal_param(signal_name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief convert mac string to mac address
|
|
|
|
*
|
|
|
|
* @param mac_str MAC address string with format "xx:xx:xx:xx:xx:xx"
|
|
|
|
* @param[out] mac_addr store converted MAC address
|
|
|
|
*/
|
|
|
|
bool unity_util_convert_mac_from_string(const char* mac_str, uint8_t *mac_addr);
|
2019-04-11 21:31:23 -04:00
|
|
|
|
2020-02-26 19:57:00 -05:00
|
|
|
typedef struct test_utils_exhaust_memory_record_s *test_utils_exhaust_memory_rec;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit the largest free block of memory with a particular capability set to
|
|
|
|
* 'limit' bytes (meaning an allocation of 'limit' should succeed at least once,
|
|
|
|
* but any allocation of more bytes will fail.)
|
|
|
|
*
|
|
|
|
* Returns a record pointer which needs to be passed back in to test_utils_free_exhausted_memory
|
|
|
|
* before the test completes, to avoid a major memory leak.
|
|
|
|
*
|
|
|
|
* @param caps Capabilities of memory to exhause
|
|
|
|
* @param limit The size to limit largest free block to
|
|
|
|
* @return Record pointer to pass to test_utils_free_exhausted_memory() once done
|
|
|
|
*/
|
|
|
|
test_utils_exhaust_memory_rec test_utils_exhaust_memory(uint32_t caps, size_t limit);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to free memory which was taken up by test_utils_exhaust_memory() call
|
|
|
|
*
|
|
|
|
* @param rec Result previously returned from test_utils_exhaust_memory()
|
|
|
|
*/
|
|
|
|
void test_utils_free_exhausted_memory(test_utils_exhaust_memory_rec rec);
|
|
|
|
|
|
|
|
|
2020-02-29 04:32:53 -05:00
|
|
|
/**
|
|
|
|
* @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 test_utils_task_delete(TaskHandle_t thandle);
|
2020-02-04 13:08:41 -05:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|