Merge branch 'feature/bt_component_test_app' into 'master'

feat(bt): migrate the tests from unit-test-app

Closes IDF-5567

See merge request espressif/esp-idf!26134
This commit is contained in:
Ivan Grokhotkov 2023-10-02 23:31:03 +08:00
commit 5cd6284b6c
11 changed files with 115 additions and 28 deletions

View File

@ -35,7 +35,7 @@ typedef struct {
tBTM_EXT_ADV_RECORD adv_record[MAX_BLE_ADV_INSTANCE] = {0}; tBTM_EXT_ADV_RECORD adv_record[MAX_BLE_ADV_INSTANCE] = {0};
extern void btm_ble_inter_set(bool extble_inter); extern void btm_ble_inter_set(bool extble_inter);
static char *btm_ble_hci_status_to_str(tHCI_STATUS status) static const char *btm_ble_hci_status_to_str(tHCI_STATUS status)
{ {
switch(status) { switch(status) {
case HCI_SUCCESS: case HCI_SUCCESS:

View File

@ -1,6 +0,0 @@
if(CONFIG_BT_ENABLED OR CMAKE_BUILD_EARLY_EXPANSION)
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES cmock nvs_flash bt esp_ringbuf)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
endif()

View File

@ -0,0 +1,8 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/bt/test_apps:
disable:
- if: IDF_TARGET not in ["esp32", "esp32c3"]
reason: Sufficient to run the tests on one chip of each architecture
depends_components:
- bt

View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main)
list(PREPEND SDKCONFIG_DEFAULTS
"$ENV{IDF_PATH}/tools/test_apps/configs/sdkconfig.debug_helpers"
"sdkconfig.defaults")
project(bt_test)

View File

@ -0,0 +1,21 @@
| Supported Targets | ESP32 | ESP32-C3 |
| ----------------- | ----- | -------- |
# `bt` component unit tests
When adding new test cases, check if the `depends_components` list in `.build-test-rules.yml` needs to be updated to include additional components. The test app will only be built and tested when these components are modified.
To build and run this test app, using esp32c3 target for example:
```bash
idf.py set-target esp32c3
idf.py build flash monitor
```
To run tests using pytest:
```bash
idf.py set-target esp32c3
idf.py build
pytest --target=esp32c3
```

View File

@ -0,0 +1,6 @@
idf_component_register(SRCS "test_bt_main.c"
"test_bt_common.c"
"test_smp.c"
INCLUDE_DIRS "."
PRIV_REQUIRES unity bt
WHOLE_ARCHIVE)

View File

@ -11,10 +11,14 @@
#include <stdbool.h> #include <stdbool.h>
#include "unity.h" #include "unity.h"
#include "sdkconfig.h"
// btdm_controller_compile_version_check defined only for ESP32
#ifdef CONFIG_IDF_TARGET_ESP32
extern bool btdm_controller_compile_version_check(void); extern bool btdm_controller_compile_version_check(void);
TEST_CASE("bt_controller_git_commit_check", "[bt_common]") TEST_CASE("bt_controller_git_commit_check", "[bt_common]")
{ {
TEST_ASSERT(btdm_controller_compile_version_check() == true); TEST_ASSERT(btdm_controller_compile_version_check() == true);
} }
#endif

View File

@ -0,0 +1,48 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "unity.h"
#include "unity_test_runner.h"
#include "esp_heap_caps.h"
#define TEST_MEMORY_LEAK_THRESHOLD_DEFAULT 0
static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
void set_leak_threshold(int threshold)
{
leak_threshold = threshold;
}
static size_t before_free_8bit;
static size_t before_free_32bit;
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= leak_threshold, "memory leak");
}
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
}
void tearDown(void)
{
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
}
void app_main(void)
{
printf("Running bt component tests\n");
unity_run_menu();
}

View File

@ -1,46 +1,32 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
/* /*
Tests for the BLE SMP implementation * Tests for the BLE SMP implementation
*/ */
#include <esp_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/xtensa_api.h"
#include "unity.h" #include "unity.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "freertos/ringbuf.h"
#include "esp_random.h" #include "esp_random.h"
#include "nvs_flash.h"
#include "esp_bt.h" #include "esp_bt.h"
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "esp_bt_device.h" #include "esp_bt_device.h"
#include "esp_gap_ble_api.h" #include "esp_gap_ble_api.h"
#define TAG "ble_smp_test"
#define KEY_LENGTH_DWORDS_P256 8 #define KEY_LENGTH_DWORDS_P256 8
typedef unsigned long DWORD; typedef unsigned long DWORD;
typedef uint32_t UINT32; typedef uint32_t UINT32;
typedef struct { typedef struct {
DWORD x[KEY_LENGTH_DWORDS_P256]; DWORD x[KEY_LENGTH_DWORDS_P256];
DWORD y[KEY_LENGTH_DWORDS_P256]; DWORD y[KEY_LENGTH_DWORDS_P256];
DWORD z[KEY_LENGTH_DWORDS_P256]; DWORD z[KEY_LENGTH_DWORDS_P256];
} Point; } Point;
@ -79,7 +65,7 @@ static void bt_rand(void *buf, size_t len)
for (int i = 0; i < (int)(len / sizeof(uint32_t)); i++) { for (int i = 0; i < (int)(len / sizeof(uint32_t)); i++) {
uint32_t rand = esp_random(); uint32_t rand = esp_random();
memcpy(buf + i*sizeof(uint32_t), &rand, sizeof(uint32_t)); memcpy(buf + i * sizeof(uint32_t), &rand, sizeof(uint32_t));
} }
return; return;

View File

@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.esp32c3
def test_bt(dut: Dut) -> None:
dut.run_all_single_board_cases()

View File

@ -1,4 +1,3 @@
CONFIG_IDF_TARGET="esp32"
TEST_COMPONENTS=bt
CONFIG_BT_ENABLED=y CONFIG_BT_ENABLED=y
CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 CONFIG_UNITY_FREERTOS_STACK_SIZE=12288
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n