Skip to content

Commit

Permalink
Merge branch 'feature/add_ci_gateway_case' into 'main'
Browse files Browse the repository at this point in the history
add gateway ci case

See merge request espressif/esp-zigbee-sdk!86
  • Loading branch information
chshu committed Dec 28, 2023
2 parents 926a2fa + 794ba6a commit dfb7bb4
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 41 deletions.
46 changes: 46 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ before_script:
- cd ${ESP_ZIGBEE_SDK_PATH}
- pip install -r tools/ci/requirements-build.txt

.build_rcp_gateway: &build_rcp_gateway
- mv $CI_PROJECT_DIR/examples/esp_zigbee_gateway/sdkconfig.defaults $CI_PROJECT_DIR/examples/esp_zigbee_gateway/sdkconfig.defaults.ori
- cp $CI_PROJECT_DIR/tools/ci/sdkconfig_for_gateway_ci.defaults $CI_PROJECT_DIR/examples/esp_zigbee_gateway/sdkconfig.defaults
- cd $CI_PROJECT_DIR/examples/esp_zigbee_rcp
- idf.py set-target esp32h2
- idf.py build
- cd $CI_PROJECT_DIR/examples/esp_zigbee_gateway
- idf.py set-target esp32s3
- idf.py build
- mv $CI_PROJECT_DIR/examples/esp_zigbee_gateway/sdkconfig.defaults.ori $CI_PROJECT_DIR/examples/esp_zigbee_gateway/sdkconfig.defaults
- cd ${ESP_ZIGBEE_SDK_PATH}

build_non_pytest_examples:
stage: build
image: ${CI_DOCKER_REGISTRY}/esp-env-v5.3:1
Expand Down Expand Up @@ -89,6 +101,30 @@ build_pytest_examples:
tags:
- build

build_pytest_gateway:
stage: build
image: ${CI_DOCKER_REGISTRY}/esp-env-v5.3:1
artifacts:
paths:
- "**/build*/size.json"
- "**/build*/build_log.txt"
- "**/build*/*.bin"
- "**/build*/*.map"
- "**/build*/*.elf"
- "**/build*/flasher_args.json"
- "**/build*/flash_project_args"
- "**/build*/config/sdkconfig.json"
- "**/build*/bootloader/*.bin"
- "**/build*/partition_table/*.bin"
when: always
expire_in: 4 days
script:
- *update_zigbee_lib_script
- python tools/ci/build_apps.py ./examples --rcp_gateway
- *build_rcp_gateway
tags:
- build

build_docs:
stage: build
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.3:1-1
Expand Down Expand Up @@ -124,6 +160,16 @@ pytest_esp32c6_i154_zigbee_multi_dut:
- find examples/ -name "pytest_*.py" | xargs pytest --target esp32c6 -m zigbee_multi_dut
tags: ["esp32c6", "zigbee_multi_dut"]

pytest_esp32s3_i154_zigbee_multi_dut:
stage: target_test
image: ${CI_DOCKER_REGISTRY}/target-test-env-v5.3:1
needs:
- build_pytest_gateway
script:
- pip install -r tools/ci/requirements-pytest.txt
- find examples/ -name "pytest_*.py" | xargs pytest --target esp32s3 -m zigbee_multi_dut
tags: ["esp32s3", "zigbee_multi_dut"]

.deploy_docs_template:
stage: docs
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.3:1-1
Expand Down
46 changes: 41 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
from _pytest.terminal import TerminalReporter
from pytest_embedded.plugin import multi_dut_argument, multi_dut_fixture
from pytest_embedded.utils import find_by_suffix

import time
import glob
import subprocess

DEFAULT_SDKCONFIG = 'default'

Expand Down Expand Up @@ -124,14 +126,48 @@ def build_dir(app_path: str, target: Optional[str], config: Optional[str]) -> st
@pytest.fixture(autouse=True)
@multi_dut_fixture
def junit_properties(
test_case_name: str, record_xml_attribute: Callable[[str, object], None]
test_case_name: str, record_xml_attribute: Callable[[str, object], None]
) -> None:
"""
This fixture is autoused and will modify the junit report test case name to <target>.<config>.<case_name>
"""
record_xml_attribute('name', test_case_name)


@pytest.fixture()
def teardown_fixture(serial_ports):
"""
A pytest fixture responsible for erasing the flash memory of a list of test devices post-testing.
Yields:
None: The fixture initially yields control back to the test function without any modification to 'dut'.
Returns:
None: No return value since the primary purpose is the teardown side effect.
"""
yield
# after test, do erase flash process
proc = None
for serial_port in serial_ports:
print(f'erase flash on serial_port: {serial_port}')
proc = subprocess.Popen(f'python -m esptool --port {serial_port} erase_flash', shell=True)
proc.wait()
if proc is not None:
proc.kill()
time.sleep(1)


@pytest.fixture()
def serial_ports(dut):
usb_ports = []
for device in dut:
serial_port = device.expect(r'Serial port (/dev/ttyUSB[0-9]+)')
serial_port = serial_port[1].decode() if serial_port else None
usb_ports.append(serial_port)
acm_ports = glob.glob('/dev/ttyACM*')
serial_port_list = usb_ports + acm_ports
print(f'serial_port_list:{serial_port_list}')
return serial_port_list


##################
# Hook functions #
##################
Expand Down Expand Up @@ -165,8 +201,8 @@ def pytest_unconfigure(config: Config) -> None:

class IdfPytestEmbedded:
def __init__(
self,
target: Optional[str] = None,
self,
target: Optional[str] = None,
):
# CLI options to filter the test cases
self.target = target
Expand Down Expand Up @@ -216,7 +252,7 @@ def _get_param_config(_item: Function) -> str:
]

def pytest_runtest_makereport(
self, item: Function, call: CallInfo[None]
self, item: Function, call: CallInfo[None]
) -> Optional[TestReport]:
report = TestReport.from_item_and_call(item, call)
if report.outcome == 'failed':
Expand Down
2 changes: 1 addition & 1 deletion examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
if (err_status == ESP_OK) {
esp_zb_ieee_addr_t ieee_address;
esp_zb_get_long_address(ieee_address);
ESP_LOGI(TAG, "Formed network successfully (ieee_address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)",
ESP_LOGI(TAG, "Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)",
ieee_address[7], ieee_address[6], ieee_address[5], ieee_address[4],
ieee_address[3], ieee_address[2], ieee_address[1], ieee_address[0],
esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address());
Expand Down
10 changes: 10 additions & 0 deletions examples/pytest_esp_zigbee_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def config_zigbee_network(cli: Dut, light: Dut) -> Tuple[bool, str]:
],
indirect=True,
)
@pytest.mark.usefixtures('teardown_fixture')
def test_zb_cli_zc_connection(dut: Tuple[Dut, Dut]) -> None:
light = dut[1]
cli = dut[0]
Expand All @@ -78,6 +79,7 @@ def test_zb_cli_zc_connection(dut: Tuple[Dut, Dut]) -> None:
],
indirect=True,
)
@pytest.mark.usefixtures('teardown_fixture')
def test_zb_cli_zc_finding_binding(dut: Tuple[Dut, Dut]) -> None:
light = dut[1]
cli = dut[0]
Expand Down Expand Up @@ -120,6 +122,7 @@ def test_zb_cli_zc_finding_binding(dut: Tuple[Dut, Dut]) -> None:
],
indirect=True,
)
@pytest.mark.usefixtures('teardown_fixture')
def test_zb_cli_zc_ZCL_command(dut: Tuple[Dut, Dut]) -> None:
light = dut[1]
cli = dut[0]
Expand All @@ -136,20 +139,24 @@ def test_zb_cli_zc_ZCL_command(dut: Tuple[Dut, Dut]) -> None:
# On command
cli.write('zcl -c ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 01')
cli.expect('Done', timeout=3)
time.sleep(2)
# read on_off attribute
cli.write('zcl -a read ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 0x0104 0')
assert str(bool(light_on)) == cli.expect(r'Value: (\w+)', timeout=3)[1].decode()
# Off command
time.sleep(2)
cli.write('zcl -c ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 00')
cli.expect('Done', timeout=3)
time.sleep(2)
# read on_off attribute
cli.write('zcl -a read ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 0x0104 0')
time.sleep(2)
assert str(bool(light_off)) == cli.expect(r'Value: (\w+)', timeout=3)[1].decode()
# toggle command
time.sleep(2)
cli.write('zcl -c ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 02')
cli.expect('Done', timeout=3)
time.sleep(2)
# read on_off attribute
cli.write('zcl -a read ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0006 0x0104 0')
assert str(bool(light_on)) == cli.expect(r'Value: (\w+)', timeout=3)[1].decode()
Expand All @@ -170,9 +177,11 @@ def test_zb_cli_zc_ZCL_command(dut: Tuple[Dut, Dut]) -> None:
# Move (with On/Off) command
time.sleep(2)
cli.write('zcl -c ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0008 05 profile 0x0104 payload 0105')
time.sleep(2)
cli.expect('Done', timeout=3)
# read level_control attribute
cli.write('zcl -a read ' + light_nwk_addr + ' ' + light_endpoint + ' 0x0008 0x0104 0')
time.sleep(2)
cli.expect('Done', timeout=3)
# Step (with On/Off) command
time.sleep(2)
Expand Down Expand Up @@ -249,6 +258,7 @@ def test_zb_cli_zc_ZCL_command(dut: Tuple[Dut, Dut]) -> None:
],
indirect=True,
)
@pytest.mark.usefixtures('teardown_fixture')
def test_zb_cli_zc_check_leaving(dut: Tuple[Dut, Dut]) -> None:
light = dut[1]
cli = dut[0]
Expand Down
Loading

0 comments on commit dfb7bb4

Please sign in to comment.