Skip to content

Commit 68399eb

Browse files
loop233laride
authored andcommitted
feat: add bthome test_apps
1 parent 1500989 commit 68399eb

File tree

10 files changed

+607
-0
lines changed

10 files changed

+607
-0
lines changed

.gitlab/ci/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,18 @@ build_components_bluetooth_ble_hci_test_apps:
10731073
variables:
10741074
EXAMPLE_DIR: components/bluetooth/ble_hci/test_apps
10751075

1076+
build_components_bluetooth_ble_adv_bthome_test_apps:
1077+
extends:
1078+
- .build_examples_template
1079+
- .rules:build:components_bluetooth_ble_adv_bthome_test_apps
1080+
parallel:
1081+
matrix:
1082+
- IMAGE: espressif/idf:release-v5.0
1083+
- IMAGE: espressif/idf:release-v5.1
1084+
- IMAGE: espressif/idf:release-v5.2
1085+
variables:
1086+
EXAMPLE_DIR: components/bluetooth/ble_adv/bthome/test_apps
1087+
10761088
build_components_button_test_apps:
10771089
extends:
10781090
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
- "components/bluetooth/ble_hci/**/*"
5353
- "tools/cmake_utilities/package_manager.cmake"
5454

55+
.patterns-components_bluetooth_ble_adv_bthome: &patterns-components_bluetooth_ble_adv_bthome
56+
- "components/bluetooth/ble_adv/bthome/**/*"
57+
- "tools/cmake_utilities/package_manager.cmake"
58+
5559
.patterns-components_bootloader_support_plus: &patterns-components_bootloader_support_plus
5660
- "components/bootloader_support_plus/**/*"
5761
- "components/utilities/xz/**/*"
@@ -1867,6 +1871,17 @@
18671871
- <<: *if-dev-push
18681872
changes: *patterns-components_bluetooth_ble_hci
18691873

1874+
.rules:build:components_bluetooth_ble_adv_bthome_test_apps:
1875+
rules:
1876+
- <<: *if-protected
1877+
- <<: *if-label-build
1878+
- <<: *if-label-target_test
1879+
- <<: *if-trigger-job
1880+
- <<: *if-dev-push
1881+
changes: *patterns-build_system
1882+
- <<: *if-dev-push
1883+
changes: *patterns-components_bluetooth_ble_adv_bthome
1884+
18701885
.rules:build:component_bus_test:
18711886
rules:
18721887
- <<: *if-protected

.gitlab/ci/target_test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,3 +940,37 @@ tools_test_cmake_utilities:
940940
TEST_TARGET: ${IDF_TARGET}
941941
TEST_FOLDER: tools/cmake_utilities
942942
TEST_ENV: ${ENV_TAG}
943+
944+
components_test_bluetooth_ble_adv_bthome:
945+
extends:
946+
- .pytest_template
947+
- .rules:build:components_bluetooth_ble_adv_bthome_test_apps
948+
needs:
949+
- job: "build_components_bluetooth_ble_adv_bthome_test_apps"
950+
artifacts: true
951+
optional: false
952+
parallel:
953+
matrix:
954+
- IDF_TARGET: esp32
955+
IDF_VERSION: "5.0"
956+
ENV_TAG: "generic"
957+
- IDF_TARGET: esp32s3
958+
IDF_VERSION: "5.0"
959+
ENV_TAG: "generic"
960+
- IDF_TARGET: esp32c3
961+
IDF_VERSION: "5.0"
962+
ENV_TAG: "generic"
963+
- IDF_TARGET: esp32h2
964+
IDF_VERSION: "5.0"
965+
ENV_TAG: "generic"
966+
- IDF_TARGET: esp32c6
967+
IDF_VERSION: "5.0"
968+
ENV_TAG: "generic"
969+
tags:
970+
- ${IDF_TARGET}
971+
- ${ENV_TAG}
972+
image: $DOCKER_TARGET_TEST_v5_1_ENV_IMAGE
973+
variables:
974+
TEST_TARGET: ${IDF_TARGET}
975+
TEST_FOLDER: components/bluetooth/ble_adv/bthome
976+
TEST_ENV: ${ENV_TAG}

components/bluetooth/ble_adv/bthome/bthome_v2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ esp_err_t bthome_register_callbacks(bthome_handle_t handle, bthome_callbacks_t *
457457

458458
esp_err_t bthome_load_params(bthome_handle_t handle)
459459
{
460+
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "handle is null");
460461
bthome_t *bthome = (bthome_t *)handle;
461462
uint8_t counter[4];
462463
bthome->callbacks.load(handle, BTHOME_COUNTER_KEY, counter, sizeof(counter));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
6+
"../../")
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(bthome_test)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# BTHome Component Test Application
2+
3+
This directory contains test applications for the BTHome component.
4+
5+
## Test Structure
6+
7+
- `main/bthome_test.c` - Main test file containing unit tests for BTHome functionality
8+
- `pytest_bthome.py` - Pytest configuration for automated testing
9+
- `sdkconfig.defaults` - Default configuration for the test application
10+
11+
## Test Cases
12+
13+
The test application includes the following test cases:
14+
15+
1. **bthome_create_delete** - Tests basic object creation and deletion
16+
2. **bthome_encryption_config** - Tests encryption key and MAC address configuration
17+
3. **bthome_payload_creation** - Tests sensor data payload creation
18+
4. **bthome_binary_sensor_data** - Tests binary sensor data handling
19+
5. **bthome_event_data** - Tests event data handling
20+
6. **bthome_adv_data_creation** - Tests advertisement data creation
21+
7. **bthome_adv_data_parsing** - Tests advertisement data parsing
22+
8. **bthome_memory_management** - Tests memory management and leak detection
23+
9. **bthome_error_handling** - Tests error handling and edge cases
24+
25+
## Building and Running
26+
27+
To build the test application:
28+
29+
```bash
30+
cd components/bluetooth/ble_adv/bthome/test_apps
31+
idf.py build
32+
```
33+
34+
To run the tests:
35+
36+
```bash
37+
idf.py monitor
38+
```
39+
40+
## CI Integration
41+
42+
The test application is integrated into the CI pipeline and will run automatically when:
43+
- BTHome component code is modified
44+
- The test application itself is modified
45+
- Manual CI trigger
46+
47+
The tests run on multiple ESP32 variants (ESP32, ESP32-S3, ESP32-C3) and IDF versions (4.4, 5.0, 5.1, 5.2).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "bthome_test.c"
2+
INCLUDE_DIRS "."
3+
REQUIRES bthome unity)

0 commit comments

Comments
 (0)