mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-26 20:53:11 +00:00
feat(example): add pytest for ble example config test
This commit is contained in:
@@ -5,10 +5,12 @@ from typing import Tuple
|
||||
|
||||
import pexpect
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
from pytest_embedded_idf.dut import IdfDut
|
||||
|
||||
|
||||
# Case 1: gatt client and gatt server test
|
||||
# EXAMPLE_CI_ID=3
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32c6
|
||||
@@ -18,10 +20,10 @@ from pytest_embedded_idf.dut import IdfDut
|
||||
@pytest.mark.esp32c61
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.parametrize(
|
||||
'count, app_path, config, erase_all', [
|
||||
'count, app_path, config', [
|
||||
(2,
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_server")}|{os.path.join(os.path.dirname(__file__), "gatt_client")}',
|
||||
'name', 'y'),
|
||||
'name'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -53,14 +55,15 @@ def test_gatt_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> None:
|
||||
|
||||
|
||||
# Case 2: gatt client and gatt server test for ESP32C2 26mhz xtal
|
||||
# EXAMPLE_CI_ID=3
|
||||
@pytest.mark.esp32c2
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'count, target, baud, app_path, config, erase_all', [
|
||||
'count, target, baud, app_path, config', [
|
||||
(2, 'esp32c2|esp32c2', '74880',
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_server")}|{os.path.join(os.path.dirname(__file__), "gatt_client")}',
|
||||
'esp32c2_xtal26m', 'y'),
|
||||
'esp32c2_xtal26m'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -92,6 +95,7 @@ def test_c2_26mhz_xtal_gatt_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> N
|
||||
|
||||
|
||||
# Case 3: gatt security server and gatt security client test
|
||||
# EXAMPLE_CI_ID=5
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32c6
|
||||
@@ -101,10 +105,10 @@ def test_c2_26mhz_xtal_gatt_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> N
|
||||
@pytest.mark.esp32c61
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.parametrize(
|
||||
'count, app_path, config, erase_all', [
|
||||
'count, app_path, config', [
|
||||
(2,
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_security_server")}|{os.path.join(os.path.dirname(__file__), "gatt_security_client")}',
|
||||
'name', 'y'),
|
||||
'name'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -150,17 +154,20 @@ def test_gatt_security_func(app_path: str, dut: Tuple[IdfDut, IdfDut], target: T
|
||||
assert 'rst:' not in str(gatt_security_server_output) and 'boot:' not in str(gatt_security_server_output)
|
||||
assert 'Disconnected' not in str(gatt_security_client_output)
|
||||
assert 'Disconnected' not in str(gatt_security_server_output)
|
||||
gatt_security_client.serial.erase_flash()
|
||||
gatt_security_server.serial.erase_flash()
|
||||
|
||||
|
||||
# Case 4: gatt security server and gatt security client test for ESP32C2 26mhz xtal
|
||||
# EXAMPLE_CI_ID=5
|
||||
@pytest.mark.esp32c2
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'count, target, baud, app_path, config, erase_all', [
|
||||
'count, target, baud, app_path, config', [
|
||||
(2, 'esp32c2|esp32c2', '74880',
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_security_server")}|{os.path.join(os.path.dirname(__file__), "gatt_security_client")}',
|
||||
'esp32c2_xtal26m', 'y'),
|
||||
'esp32c2_xtal26m'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -200,6 +207,8 @@ def test_c2_26mhz_xtal_gatt_security_func(app_path: str, dut: Tuple[IdfDut, IdfD
|
||||
assert 'rst:' not in str(gatt_security_server_output) and 'boot:' not in str(gatt_security_server_output)
|
||||
assert 'Disconnected' not in str(gatt_security_client_output)
|
||||
assert 'Disconnected' not in str(gatt_security_server_output)
|
||||
gatt_security_client.serial.erase_flash()
|
||||
gatt_security_server.serial.erase_flash()
|
||||
|
||||
|
||||
# Case 5: ble ibeacon test
|
||||
@@ -212,10 +221,10 @@ def test_c2_26mhz_xtal_gatt_security_func(app_path: str, dut: Tuple[IdfDut, IdfD
|
||||
@pytest.mark.esp32c61
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.parametrize(
|
||||
'count, app_path, config, erase_all', [
|
||||
'count, app_path, config', [
|
||||
(2,
|
||||
f'{os.path.join(os.path.dirname(__file__), "ble_ibeacon")}|{os.path.join(os.path.dirname(__file__), "ble_ibeacon")}',
|
||||
'sender|receiver', 'y'),
|
||||
'sender|receiver'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -241,10 +250,10 @@ def test_ble_ibeacon_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> None:
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'count, target, baud, app_path, config, erase_all', [
|
||||
'count, target, baud, app_path, config', [
|
||||
(2, 'esp32c2|esp32c2', '74880',
|
||||
f'{os.path.join(os.path.dirname(__file__), "ble_ibeacon")}|{os.path.join(os.path.dirname(__file__), "ble_ibeacon")}',
|
||||
'esp32c2_xtal26m_sender|esp32c2_xtal26m_receiver', 'y'),
|
||||
'esp32c2_xtal26m_sender|esp32c2_xtal26m_receiver'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@@ -263,3 +272,131 @@ def test_c2_26mhz_ble_ibeacon_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) ->
|
||||
ibeacon_receiver.expect_exact('Minor: 0xf206 (61958)', timeout=30)
|
||||
ibeacon_receiver.expect_exact('Measured power (RSSI at a 1m distance):', timeout=30)
|
||||
ibeacon_receiver.expect_exact('RSSI of packet: ', timeout=30)
|
||||
|
||||
|
||||
# Case 6: gatt client and gatt server config test
|
||||
# EXAMPLE_CI_ID=4
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32c6
|
||||
@pytest.mark.esp32c5
|
||||
@pytest.mark.esp32h2
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.esp32c61
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.parametrize(
|
||||
'count, app_path, config', [
|
||||
(2,
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_server")}|{os.path.join(os.path.dirname(__file__), "gatt_client")}',
|
||||
'cfg_test'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_gatt_config_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> None:
|
||||
gatt_client = dut[1]
|
||||
gatt_server = dut[0]
|
||||
gatt_client_addr = gatt_client.expect(r'Bluetooth MAC: (([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})', timeout=30).group(1).decode('utf8')
|
||||
gatt_server_addr = gatt_server.expect(r'Bluetooth MAC: (([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})', timeout=30).group(1).decode('utf8')
|
||||
gatt_client.expect_exact('GATT client register, status 0', timeout=30)
|
||||
gatt_server.expect_exact('GATT server register, status 0', timeout=30)
|
||||
gatt_server.expect_exact('Advertising start successfully', timeout=30)
|
||||
gatt_client.expect_exact('Scanning start successfully', timeout=30)
|
||||
gatt_client.expect_exact(f'Connected, conn_id 0, remote {gatt_server_addr}', timeout=30)
|
||||
gatt_server.expect_exact(f'Connected, conn_id 0, remote {gatt_client_addr}', timeout=30)
|
||||
gatt_client.expect_exact('Connection params update, status 0', timeout=30)
|
||||
gatt_server.expect_exact('Connection params update, status 0', timeout=30)
|
||||
gatt_client.expect_exact('Service discover complete', timeout=30)
|
||||
gatt_client.expect_exact('Service search complete', timeout=30)
|
||||
gatt_client.expect_exact('MTU exchange, status 0, MTU 500', timeout=30)
|
||||
gatt_server.expect_exact('MTU exchange, MTU 500', timeout=30)
|
||||
gatt_server.expect_exact('Notification enable', timeout=30)
|
||||
gatt_client.expect_exact('Notification received', timeout=30)
|
||||
gatt_client_output = gatt_client.expect(pexpect.TIMEOUT, timeout=10)
|
||||
gatt_server_output = gatt_server.expect(pexpect.TIMEOUT, timeout=10)
|
||||
assert 'rst:' not in str(gatt_client_output) and 'boot:' not in str(gatt_client_output)
|
||||
assert 'rst:' not in str(gatt_server_output) and 'boot:' not in str(gatt_server_output)
|
||||
assert 'Disconnected' not in str(gatt_client_output)
|
||||
assert 'Disconnected' not in str(gatt_server_output)
|
||||
|
||||
|
||||
# Case 7: gatt client and gatt server config test for ESP32C2 26mhz xtal
|
||||
# EXAMPLE_CI_ID=3
|
||||
@pytest.mark.esp32c2
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'count, target, baud, app_path, config', [
|
||||
(2, 'esp32c2|esp32c2', '74880',
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_server")}|{os.path.join(os.path.dirname(__file__), "gatt_client")}',
|
||||
'esp32c2_cfg_test'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_c2_26mhz_xtal_gatt_config_func(app_path: str, dut: Tuple[IdfDut, IdfDut]) -> None:
|
||||
gatt_client = dut[1]
|
||||
gatt_server = dut[0]
|
||||
gatt_client_addr = gatt_client.expect(r'Bluetooth MAC: (([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})').group(1).decode('utf8')
|
||||
gatt_server_addr = gatt_server.expect(r'Bluetooth MAC: (([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})').group(1).decode('utf8')
|
||||
gatt_client.expect_exact('GATT client register, status 0', timeout=30)
|
||||
gatt_server.expect_exact('GATT server register, status 0', timeout=30)
|
||||
gatt_server.expect_exact('Advertising start successfully', timeout=30)
|
||||
gatt_client.expect_exact('Scanning start success', timeout=30)
|
||||
gatt_client.expect_exact(f'Connected, conn_id 0, remote {gatt_server_addr}', timeout=30)
|
||||
gatt_server.expect_exact(f'Connected, conn_id 0, remote {gatt_client_addr}', timeout=30)
|
||||
gatt_client.expect_exact('Connection params update, status 0', timeout=30)
|
||||
gatt_server.expect_exact('Connection params update, status 0', timeout=30)
|
||||
gatt_client.expect_exact('Service discover complete', timeout=30)
|
||||
gatt_client.expect_exact('Service search complete', timeout=30)
|
||||
gatt_client.expect_exact('MTU exchange, status 0, MTU 500', timeout=30)
|
||||
gatt_server.expect_exact('MTU exchange, MTU 500', timeout=30)
|
||||
gatt_server.expect_exact('Notification enable', timeout=30)
|
||||
gatt_client.expect_exact('Notification received', timeout=30)
|
||||
gatt_client_output = gatt_client.expect(pexpect.TIMEOUT, timeout=10)
|
||||
gatt_server_output = gatt_server.expect(pexpect.TIMEOUT, timeout=10)
|
||||
assert 'rst:' not in str(gatt_client_output) and 'boot:' not in str(gatt_client_output)
|
||||
assert 'rst:' not in str(gatt_server_output) and 'boot:' not in str(gatt_server_output)
|
||||
assert 'Disconnected' not in str(gatt_client_output)
|
||||
assert 'Disconnected' not in str(gatt_server_output)
|
||||
|
||||
|
||||
# Case 8: BLE init deinit loop test
|
||||
@pytest.mark.esp32c6
|
||||
@pytest.mark.esp32h2
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.esp32c5
|
||||
@pytest.mark.esp32c61
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize('config, app_path', [('init_deinit',
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_client")}')], indirect=True)
|
||||
def test_bluedroid_host_init_deinit(dut: Dut) -> None:
|
||||
all_hp = []
|
||||
dut.expect_exact('Bluetooth MAC:')
|
||||
for _ in range(20):
|
||||
all_hp.append(int(dut.expect(r'Free memory: (\d+) bytes').group(1).decode('utf8')))
|
||||
|
||||
# the heapsize after host deinit is same
|
||||
assert len(list(set(all_hp))) == 1
|
||||
|
||||
|
||||
# # Case 9: BLE init deinit loop test for ESP32C2 26mhz xtal
|
||||
@pytest.mark.esp32c2
|
||||
@pytest.mark.wifi_two_dut
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'baud, app_path, config', [
|
||||
('74880',
|
||||
f'{os.path.join(os.path.dirname(__file__), "gatt_client")}',
|
||||
'esp32c2_init_deinit'),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_c2_26mhz_bluedroid_host_init_deinit(dut: Dut) -> None:
|
||||
all_hp = []
|
||||
dut.expect_exact('Bluetooth MAC:')
|
||||
for _ in range(20):
|
||||
all_hp.append(int(dut.expect(r'Free memory: (\d+) bytes').group(1).decode('utf8')))
|
||||
|
||||
# the heapsize after host deinit is same
|
||||
assert len(list(set(all_hp))) == 1
|
||||
|
||||
Reference in New Issue
Block a user