examples/unit_test_app: added an unit test app

This commit is contained in:
Shubham Patil
2025-11-27 16:23:00 +05:30
parent 08f53683ea
commit 4551507f63
7 changed files with 163 additions and 0 deletions
+7
View File
@@ -134,8 +134,15 @@ examples/bridge_apps/esp_rainmaker_bridge:
- if: IDF_TARGET in ["esp32s3"]
temporary: true
reason: the other targets are not tested yet
examples/camera:
enable:
- if: IDF_TARGET in [""]
temporary: true
reason: Another CI has been added
examples/unit_test_app:
enable:
- if: IDF_TARGET in ["esp32c3"]
temporary: true
reason: the other targets are not tested yet
+23
View File
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.5)
set(PROJECT_VER "1.0")
set(PROJECT_VER_NUMBER 1)
set(ESP_MATTER_PATH $ENV{ESP_MATTER_PATH})
set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip)
set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../components"
"${MATTER_SDK_PATH}/config/esp32/components")
# Set the components to include the tests for.
set(TEST_COMPONENTS "esp_matter" CACHE STRING "List of components to test")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(unit_test_app)
# TODO: Remove -Wno-error=unused-result once submodules are updated to not treat unused return values as errors.
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H;-Wno-overloaded-virtual;-Wno-error=unused-result" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND)
# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various
# flags that depend on -Wformat
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND)
+52
View File
@@ -0,0 +1,52 @@
# ESP Matter Unit Test App
This application runs unit tests for the ESP Matter component using the Unity test framework.
## Unity Test Framework
This test app uses the Unity Test Framework suggested by ESP-IDF.
Further reads:
- [Unit Testing with Unity](https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/unit-testing.html)
- [Unit Testing in ESP32](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/unit-tests.html)
## Running the Tests
1. Build the application:
```bash
cd examples/unit_test_app
idf.py build
```
2. Flash to device:
```bash
idf.py -p <PORT> flash monitor
```
3. Run tests:
Once flashed, the test menu will appear in the serial monitor. You can:
- Press `Enter` to see the list of available tests
- Enter a test number to run a specific test
- Enter `*` to run all tests
## Extending the Tests
### Adding tests to existing component
1. Create a new `.cpp` file in `components/<component_name>/test/`
2. Add the filename to the source list in `components/<component_name>/test/CMakeLists.txt`:
```cmake
list(APPEND srcs_list "your_new_test_file.cpp")
```
3. Write the test cases in the new test file.
### Adding new component tests
Please refer to components/esp_matter/test directory for comprehensive structure and example.
- After adding the new component tests, you need to add the component to the TEST_COMPONENTS list in CMakeLists.txt
- Append the component name to the TEST_COMPONENTS list. For example, if you add a new component called "new_component", you need to add it to the TEST_COMPONENTS list in CMakeLists.txt:
```cmake
set(TEST_COMPONENTS "esp_matter new_component" CACHE STRING "List of components to test")
```
@@ -0,0 +1,3 @@
idf_component_register(SRCS "app_main.c"
INCLUDE_DIRS "."
REQUIRES unity esp_matter)
+16
View File
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "unity.h"
#include "esp_log.h"
static const char *TAG = "UT";
void app_main(void)
{
ESP_LOGI(TAG, "esp-matter unit test app");
unity_run_menu();
}
+10
View File
@@ -0,0 +1,10 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table
esp_secure_cert, 0x3F, ,0xd000, 0x2000, encrypted
nvs, data, nvs, 0x10000, 0xC000,
nvs_keys, data, nvs_keys,, 0x1000, encrypted
otadata, data, ota, , 0x2000
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, 0x20000, 0x1E0000,
ota_1, app, ota_1, 0x200000, 0x1E0000,
fctry, data, nvs, 0x3E0000, 0x6000
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table
3 esp_secure_cert, 0x3F, ,0xd000, 0x2000, encrypted
4 nvs, data, nvs, 0x10000, 0xC000,
5 nvs_keys, data, nvs_keys,, 0x1000, encrypted
6 otadata, data, ota, , 0x2000
7 phy_init, data, phy, , 0x1000,
8 ota_0, app, ota_0, 0x20000, 0x1E0000,
9 ota_1, app, ota_1, 0x200000, 0x1E0000,
10 fctry, data, nvs, 0x3E0000, 0x6000
+52
View File
@@ -0,0 +1,52 @@
# Unity Framework Configuration
CONFIG_UNITY_ENABLE_FLOAT=y
CONFIG_UNITY_ENABLE_DOUBLE=y
CONFIG_UNITY_ENABLE_64BIT=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
#enable BT
CONFIG_BT_ENABLED=n
#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y
# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xC000
# Enable chip shell
CONFIG_ENABLE_CHIP_SHELL=y
# Disable WiFi AP
CONFIG_ENABLE_WIFI_AP=n
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
# This example only use 2 dynamic endpoints
CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=16
# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
# borrowed from unit-test-app
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
CONFIG_SPI_FLASH_ENABLE_COUNTERS=y
CONFIG_ESP_TASK_WDT_INIT=n
CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS=y
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
CONFIG_COMPILER_STACK_CHECK=y
CONFIG_ADC_DISABLE_DAC=n
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
CONFIG_SPI_MASTER_IN_IRAM=y
CONFIG_EFUSE_VIRTUAL=y
CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y