EasyManuals Logo

Espressif ESP32-S2 User Manual

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #1514 background imageLoading...
Page #1514 background image
Chapter 4. API Guides
Target based tests using a central unit test application which runs on the esp32s2. These tests use the Unity
<https://www.throwtheswitch.org/unity> unit test framework. They can be integrated into an ESP-IDF com-
ponent by placing them in the components test subdirectory. For the most part, this document is about
target based tests.
Linux-host based unit tests in which all the hardware is abstracted via mocks. Linux-host based tests are still
under development and only a small fraction of IDF components support them, currently. They are covered
here: target based unit testing.
4.30.1 Normal Test Cases
Unit tests are located in the test subdirectory of a component. Tests are written in C, and a single C source file can
contain multiple test cases. Test files start with the word test.
Each test file should include the unity.h header and the header for the C module to be tested.
Tests are added in a function in the C file as follows:
TEST_CASE("test name", "[module name]"
{
// Add test here
}
The first argument is a descriptive name for the test.
The second argument is an identifier in square brackets. Identifiers are used to group related test, or tests with
specific properties.
Note: There is no need to add a main function with UNITY_BEGIN() and UNITY_END() in each test
case. unity_platform.c will run UNITY_BEGIN() autonomously, and run the test cases, then call
UNITY_END().
The test subdirectory should contain a component CMakeLists.txt, since they are themselves components (i.e., a test
component). ESP-IDF uses the Unity test framework located in the unity component. Thus, each test component
should specify the unity component as a component requirement using the REQUIRES argument. Normally,
components should list their sources manually; for component tests however, this requirement is relaxed and the use
of the SRC_DIRS argument in idf_component_register is advised.
Overall, the minimal test subdirectory CMakeLists.txt file should contain the following:
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity)
See http://www.throwtheswitch.org/unity for more information about writing tests in Unity.
4.30.2 Multi-device Test Cases
The normal test cases will be executed on one DUT (Device Under Test). However, components that require some
form of communication (e.g., GPIO, SPI) require another device to communicate with, thus cannot be tested normal
test cases. Multi-device test cases involve writing multiple test functions, and running them on multiple DUTs.
The following is an example of a multi-device test case:
void gpio_master_test()
{
gpio_config_t slave_config = {
.pin_bit_mask = 1 << MASTER_GPIO_PIN,
.mode = GPIO_MODE_INPUT,
};
(continues on next page)
Espressif Systems 1503
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP32-S2 and is the answer not in the manual?

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish