Skip to content

Commit

Permalink
Enabled most unit tests for ESP32 (project-chip#36738)
Browse files Browse the repository at this point in the history
* Enabled most unit tests for ESP32

* Reformatting by Restyled
  • Loading branch information
feasel0 authored Dec 6, 2024
1 parent cbf92b7 commit 22d490a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 38 deletions.
4 changes: 4 additions & 0 deletions build/chip/chip_test_suite.gni
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ template("chip_test_suite") {
} else {
public_deps += [ "${chip_root}/src/platform/logging:default" ]
}

if (chip_device_platform == "esp32") {
complete_static_lib = true
}
}

# Build a source_set or a flashable executable for each individual unit test source, which also includes the common files.
Expand Down
3 changes: 2 additions & 1 deletion src/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ static_library("credentials") {
import("${chip_root}/build/chip/tests.gni")
if (!(chip_build_tests && (chip_device_platform == "mbed" ||
chip_device_platform == "openiotsdk" ||
chip_device_platform == "nrfconnect"))) {
chip_device_platform == "nrfconnect" ||
chip_device_platform == "esp32"))) {
sources += [
"tests/CHIPAttCert_test_vectors.cpp",
"tests/CHIPAttCert_test_vectors.h",
Expand Down
5 changes: 1 addition & 4 deletions src/lib/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ static_library("core") {
]
}

static_library("vectortlv") {
output_name = "libVectorTlv"
output_dir = "${root_out_dir}/lib"

source_set("vectortlv") {
sources = [
"TLVVectorWriter.cpp",
"TLVVectorWriter.h",
Expand Down
4 changes: 1 addition & 3 deletions src/lib/support/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ static_library("support") {
}
}

static_library("test_utils") {
output_name = "libTestUtils"
output_dir = "${root_out_dir}/lib"
source_set("test_utils") {
deps = [ "${chip_root}/src/platform" ]

sources = [
Expand Down
3 changes: 3 additions & 0 deletions src/test_driver/esp32/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build/
/sdkconfig
/sdkconfig.old
/dependencies.lock
/sdkconfig
/managed_components/
35 changes: 23 additions & 12 deletions src/test_driver/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,36 @@ project(test-driver)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DLWIP_IPV6_SCOPES=0;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os;-DLWIP_IPV6_SCOPES=0" APPEND)

# TODO: libAppTests depends on MessagingTestHelpers, which depends on
# NetworkTestHelpers. That sort of depends on InetTestHelpers or
# equivalent (to provide gSystemLayer, gInet, InitNetwork(),
# ShutdownNetwork()) but there's only a POSIX implementation of that
# last, which does not compile on ESP32. Need to figure out how to
# make that work. See comments below for the transport layer tests,
# which have the same issue.
#
# libAppTests.a -lMessagingTestHelpers -lNetworkTestHelpers
#
# TODO: ble tests do not compile using CMake (library is not auto-built)
# libBleLayerTests.a

esp32_unit_test(NAME testAccess LIBRARY accesstest)
esp32_unit_test(NAME testAddressResolve LIBRARY AddressResolveTests)
esp32_unit_test(NAME testAppClusterBuildingBlock LIBRARY AppClusterBuildingBlockTests)
esp32_unit_test(NAME testAppDataModel LIBRARY AppDataModelTests)
esp32_unit_test(NAME testASN1 LIBRARY ASN1Tests)
esp32_unit_test(NAME testBDX LIBRARY BDXTests)
esp32_unit_test(NAME testChipCrypto LIBRARY ChipCryptoTests EXTRA_LIBRARIES -lCertTestVectors)
esp32_unit_test(NAME testCodegenDataModelProvider LIBRARY CodegenDataModelProviderTests)
esp32_unit_test(NAME testCore LIBRARY CoreTests)
esp32_unit_test(NAME testFormat LIBRARY FormatTests)
esp32_unit_test(NAME testIMInterface LIBRARY IMInterfaceTests)
esp32_unit_test(NAME testInetLayer LIBRARY InetLayerTests)
esp32_unit_test(NAME testInteractionModel LIBRARY InteractionModelTests)
esp32_unit_test(NAME testMinimalMdnsCore LIBRARY MinimalMdnsCoreTests)
esp32_unit_test(NAME testMinimalMdnsRecords LIBRARY MinimalMdnsRecordsTests)
esp32_unit_test(NAME testMinimalMdnsResponders LIBRARY MinimalMdnsRespondersTests)
esp32_unit_test(NAME testMdns LIBRARY MdnsTests)
esp32_unit_test(NAME testRetransmit LIBRARY RetransmitTests)
esp32_unit_test(NAME testSetupPayload LIBRARY SetupPayloadTests)
esp32_unit_test(NAME testSystemLayer LIBRARY SystemLayerTests)
esp32_unit_test(NAME testUserDirectedCommissioning LIBRARY UserDirectedCommissioningTests)

# TODO: libAppTests depends on MessagingTestHelpers, which depends on
# NetworkTestHelpers. That sort of depends on InetTestHelpers or
# equivalent (to provide gSystemLayer, gInet, InitNetwork(),
# ShutdownNetwork()) but there's only a POSIX implementation of that
# last, which does not compile on ESP32.
# This affects AppTests, MessagingLayerTests, MinimalMdnstests, ControllerTests
# ControllerDataModelTests, ICDServerTests, SecureChannelTests.


# allow other tools to discover what images are available without grepping for '.img'
Expand Down
39 changes: 23 additions & 16 deletions src/test_driver/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ An application that runs Matter's unit tests on ESP32 device or QEMU.

- [Matter Tests on Device](#chip-tests-on-device)
- [Supported Devices](#supported-devices)
- [Building the Application](#building-the-application)
- [To build the application, follow these steps:](#to-build-the-application-follow-these-steps)
- [Using QEMU](#using-qemu)
- [Requirements](#requirements)
- [Building Unit Tests](#building-unit-tests)
- [Running Unit Tests](#running-unit-tests)

---

Expand All @@ -20,7 +20,7 @@ The Matter application is intended to work on
[M5Stack](http://m5stack.com). Support for the [M5Stack](http://m5stack.com) is
still a Work in Progress.

## Building the Application
## Requirements

Building the application requires the use of the Espressif ESP32 IoT Development
Framework and the xtensa-esp32-elf toolchain.
Expand Down Expand Up @@ -51,20 +51,27 @@ follow these steps:
$ make -j8
$ export QEMU_ESP32=${HOME}/tools/qemu_esp32/xtensa-softmmu/qemu-system-xtensa

### To build the application, follow these steps:
## Building Unit Tests

#### Using QEMU
To build all unit tests:

- Setup ESP32 QEMU. This will build QEMU and install necessary artifacts to
run unit tests.
$ source scripts/activate.sh
$ scripts/build/build_examples.py --target esp32-qemu-tests build

```
source idf.sh
./qemu_setup.sh
```
This generates a list of QEMU images in `out/esp32-qemu-tests/`

- Run specific unit tests
There is one image for each test directory (i.e. each chip_test_suite). So for
example `src/inet/tests` builds to `out/esp32-qemu-tests/testInetLayer.img`

```
idf make -C build/chip/src/crypto/tests check
```
The file `out/esp32-qemu-tests/test_images.txt` contains the names of all the
images that were built.

## Running Unit Tests

To run all unit test images using QEMU:

$ src/test_driver/esp32/run_qemu_image.py --verbose --file-image-list out/esp32-qemu-tests/test_images.txt

To run a single unit test image, such as `testInetLayer.img`:

$ src/test_driver/esp32/run_qemu_image.py --verbose --image out/esp32-qemu-tests/testInetLayer.img
2 changes: 0 additions & 2 deletions src/test_driver/esp32/cmake/esp32_unit_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ macro(esp32_unit_test)
idf::main
-Wl,--whole-archive ${UNIT_TEST_LIBRARY} -Wl,--no-whole-archive
${UNIT_TEST_EXTRA_LIBRARIES}
-lVectorTlv
-lTestUtils
nlfaultinjection
)

Expand Down

0 comments on commit 22d490a

Please sign in to comment.