feat(example): add pytest for nimble examples

This commit is contained in:
yuanhonghui
2026-08-12 15:46:14 +08:00
parent b418d72bb0
commit eebeb6b62c
125 changed files with 4249 additions and 162 deletions
@@ -77,4 +77,16 @@ menu "Example Configuration"
help
Use this option to advertise a random address instead of public address
config EXAMPLE_CI_ID
int "example id for CI test"
default 0
help
This config the example id for CI test. Only for internal used.
config EXAMPLE_CI_PIPELINE_ID
int "The pipeline id for CI test"
default 0
help
This config the pipeline id for CI test. Only for internal used.
endmenu
@@ -6,6 +6,7 @@
#include "esp_log.h"
#include "nvs_flash.h"
#include <string.h>
#include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h"
#include "host/ble_hs.h"
@@ -17,6 +18,7 @@
/* Global constants */
static const char *TAG = "CTE_ADV_EXAMPLE";
static char adv_device_name[32] = "CTE_Periodic_Adv";
static uint8_t s_periodic_adv_raw_data[] = {0x0D, BLE_HS_ADV_TYPE_COMP_NAME, 'C','T','E',' ','P','e','r','i','o','d','i','c'};
#if !(MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_PERIODIC_ADV) && MYNEWT_VAL(BLE_AOA_AOD))
@@ -38,8 +40,8 @@ static void start_periodic_adv_cte(uint8_t own_addr_type)
assert(rc == 0);
ESP_LOGI(TAG, "Device Address: ");
ESP_LOGI(TAG, "%02x:%02x:%02x:%02x:%02x:%02x",
addr.val[5], addr.val[4], addr.val[3], addr.val[2], addr.val[1], addr.val[0]);
ESP_LOGI(TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x",
addr.val[5], addr.val[4], addr.val[3], addr.val[2], addr.val[1], addr.val[0]);
/* Configure extended advertising parameters */
struct ble_gap_ext_adv_params ext_adv_params = {
@@ -54,9 +56,16 @@ static void start_periodic_adv_cte(uint8_t own_addr_type)
assert(rc == 0);
/* Configure advertising data */
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
strncpy(adv_device_name, esp_ble_cte_get_example_name(), sizeof(adv_device_name) - 1);
adv_device_name[sizeof(adv_device_name) - 1] = '\0';
ESP_LOGI(TAG, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
adv_device_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID, CONFIG_IDF_FIRMWARE_CHIP_ID);
#endif
struct ble_hs_adv_fields adv_fields = {0};
adv_fields.name = (const uint8_t *)"CTE_Periodic_Adv";
adv_fields.name_len = strlen("CTE_Periodic_Adv");
adv_fields.name = (const uint8_t *)adv_device_name;
adv_fields.name_len = strlen(adv_device_name);
struct os_mbuf *data = os_msys_get_pkthdr(BLE_HS_ADV_MAX_FIELD_SZ, 0);
assert(data);
@@ -0,0 +1,2 @@
CONFIG_EXAMPLE_CI_ID=25
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
@@ -67,4 +67,16 @@ menu "Example Configuration"
help
GPIO pin number for the most significant bit (MSB) of antenna encoding.
config EXAMPLE_CI_ID
int "example id for CI test"
default 0
help
This config the example id for CI test. Only for internal used.
config EXAMPLE_CI_PIPELINE_ID
int "The pipeline id for CI test"
default 0
help
This config the pipeline id for CI test. Only for internal used.
endmenu
@@ -7,6 +7,7 @@
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_check.h"
#include <string.h>
#include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h"
@@ -17,6 +18,7 @@
static const char *TAG = "CTE_SYNC_EXAMPLE";
static int is_synced = 0;
static char sync_target_name[32] = "CTE_Periodic_Adv";
static int periodic_sync_gap_event(struct ble_gap_event *event, void *arg);
@@ -173,7 +175,7 @@ static int periodic_sync_gap_event(struct ble_gap_event *event, void *arg)
memcpy(dev_name, &adv_data[index + 2], name_len);
dev_name[name_len] = '\0';
if (strcmp(dev_name, CONFIG_EXAMPLE_SYNC_TARGET_DEVNAME) == 0) {
if (strcmp(dev_name, sync_target_name) == 0) {
should_sync = true;
break;
}
@@ -255,10 +257,27 @@ static void periodic_sync_on_reset(int reason)
static void periodic_sync_on_sync(void)
{
int rc;
uint8_t own_addr_type;
ble_addr_t addr;
/* Make sure we have proper identity address set (public preferred) */
rc = ble_hs_util_ensure_addr(0);
assert(rc == 0);
rc = ble_hs_id_infer_auto(0, &own_addr_type);
assert(rc == 0);
rc = ble_hs_id_copy_addr(own_addr_type, addr.val, NULL);
assert(rc == 0);
ESP_LOGI(TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x",
addr.val[5], addr.val[4], addr.val[3], addr.val[2], addr.val[1], addr.val[0]);
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
ESP_LOGI(TAG, "DeviceName:%s, CIID:%02X, PipelineID:%05X, ChipID:%02X",
sync_target_name, CONFIG_EXAMPLE_CI_ID, CONFIG_EXAMPLE_CI_PIPELINE_ID, CONFIG_IDF_FIRMWARE_CHIP_ID);
#endif
/* Begin scanning for a periodic advertiser to sync with. */
periodic_sync_scan();
}
@@ -300,6 +319,14 @@ void app_main(void)
assert(rc == 0);
#endif
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
strncpy(sync_target_name, esp_ble_cte_get_example_name(), sizeof(sync_target_name) - 1);
sync_target_name[sizeof(sync_target_name) - 1] = '\0';
#elif CONFIG_EXAMPLE_SYNC_BY_NAME
strncpy(sync_target_name, CONFIG_EXAMPLE_SYNC_TARGET_DEVNAME, sizeof(sync_target_name) - 1);
sync_target_name[sizeof(sync_target_name) - 1] = '\0';
#endif
#if MYNEWT_VAL(BLE_AOA_AOD)
ESP_LOGI(TAG, "\n%s", direction_finding_logo);
@@ -0,0 +1,3 @@
CONFIG_EXAMPLE_CI_ID=25
CONFIG_EXAMPLE_CI_PIPELINE_ID=${CI_PIPELINE_ID}
CONFIG_EXAMPLE_SYNC_BY_NAME=y
@@ -1,10 +1,11 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "cte_config.h"
#include "esp_log.h"
@@ -78,6 +79,20 @@ uint8_t antenna_use_gpio[CONFIG_EXAMPLE_ANT_GPIO_BIT_COUNT] = {
uint8_t antenna_signal_index[4] = {CTE_ANT0_IDX, CTE_ANT1_IDX, CTE_ANT2_IDX, CTE_ANT3_IDX};
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
char *esp_ble_cte_get_example_name(void)
{
static char example_name[32];
memset(example_name, 0, sizeof(example_name));
snprintf(example_name, sizeof(example_name), "BE%02X_%05X_%02X",
CONFIG_EXAMPLE_CI_ID & 0xFF,
CONFIG_EXAMPLE_CI_PIPELINE_ID & 0xFFFFF,
CONFIG_IDF_FIRMWARE_CHIP_ID & 0xFF);
return example_name;
}
#endif
int ble_direction_finding_antenna_init(uint8_t* gpio_array,uint8_t gpio_array_len){
int rc;
// GPIO configuration
@@ -16,3 +16,7 @@ extern uint8_t antenna_use_gpio[];
extern const char direction_finding_logo[];
int ble_direction_finding_antenna_init(uint8_t* gpio_array,uint8_t gpio_array_len);
#if CONFIG_EXAMPLE_CI_ID && CONFIG_EXAMPLE_CI_PIPELINE_ID
char *esp_ble_cte_get_example_name(void);
#endif