Skip to content

Commit 6f8bd38

Browse files
committed
fix: Improve stability of test_zb_sleep and test_zb_basic
1 parent 4e4ee77 commit 6f8bd38

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

examples/pytest_esp_zigbee_open_examples.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,30 @@ def test_zb_basic(dut, count, app_path, erase_all):
4646
server = ExampleDevice(dut[1])
4747

4848
Common.check_zigbee_network_status(client, server)
49-
status_value, address_value, endpoint_value = client.get_match_desc_response_values()
49+
logs = str(client.dut.expect(r"Received report information: attribute\(0x0\), type\(0x10\), value\(0\)", timeout=15, return_what_before_match=True))
50+
51+
status_value, address_value, endpoint_value = client.get_match_desc_response_values(logs=logs)
5052
assert status_value == address_value == '0'
5153
assert endpoint_value == '10'
5254

53-
status_value, endpoint_count_value = client.get_active_endpoint_response_values()
55+
status_value, endpoint_count_value = client.get_active_endpoint_response_values(logs=logs)
5456
assert status_value == '0'
5557
# release/v1.0.8 change endpoint_count to 2
5658
assert endpoint_count_value == '2'
5759

5860
status_value, device_id_value, app_version_value, profile_id_value, endpoint_id_value = \
59-
client.get_simple_desc_response_values()
61+
client.get_simple_desc_response_values(logs=logs)
6062

6163
assert status_value == app_version_value == '0'
6264
assert device_id_value == '256'
6365
assert profile_id_value == '104'
6466
assert endpoint_id_value == '10'
6567

66-
address_value, endpoint_value, status_value = client.get_bind_response_values()
68+
address_value, endpoint_value, status_value = client.get_bind_response_values(logs=logs)
6769
assert address_value == status_value == '0'
6870
assert endpoint_value == '1'
6971

70-
address, src_endpoint, dst_endpoint, cluster = client.get_received_report_values()
72+
address, src_endpoint, dst_endpoint, cluster = client.get_received_report_values(logs=logs)
7173
assert address == '0'
7274
assert src_endpoint == '10'
7375
assert dst_endpoint == '1'

examples/zigbee_common.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from functools import wraps
99
import logging
1010
from constants import MatchPattern
11+
import re
1112

1213
logging.basicConfig(level=logging.INFO)
1314

@@ -16,7 +17,11 @@ def expect_decorator(pattern):
1617
def decorator(func):
1718
@wraps(func)
1819
def wrapper(self, *args, **kwargs):
19-
match_result = self.dut.expect(pattern, timeout=5)
20+
logs = kwargs.pop("logs", None)
21+
if logs is not None:
22+
match_result = re.compile(pattern).search(logs)
23+
else:
24+
match_result = self.dut.expect(pattern, timeout=5)
2025
if not match_result:
2126
assert False, f"No match found for pattern: {pattern}"
2227
matched_groups = match_result.groups()
@@ -78,7 +83,7 @@ def get_ota_receives_data(self, matched_values):
7883
logging.info(f"progress: {progress}, total: {total}")
7984
return matched_values
8085

81-
@expect_decorator(r'status\((\d+)\) and endpoint count\((\d+)\)')
86+
@expect_decorator(r"status\((\d+)\) and endpoint count\((\d+)\)")
8287
def get_active_endpoint_response_values(self, matched_values):
8388
status_value, endpoint_count_value = matched_values
8489
logging.info(f"Status: {status_value}, Endpoint Count: {endpoint_count_value}")
@@ -204,7 +209,7 @@ def zcl_send_gen_and_check(self, cmd, source_ep, cluster, short_address='', dst_
204209
comm += f' -d {short_address}' if short_address else ''
205210
comm += f' --dst-ep {dst_ep}' if dst_ep else ''
206211
self.dut.write(comm)
207-
self.dut.expect(r'Receive Zigbee action\(0x[0-9A-Fa-f]+\) callback', timeout=1)
212+
self.dut.expect(r'Receive Zigbee action\(0x[0-9A-Fa-f]+\) callback', timeout=6)
208213

209214
def zcl_send_raw_and_check(self, source_ep, cluster, cmd, short_address='', dst_ep='', payload=''):
210215
comm = f'zcl send_raw -e {source_ep} -c {cluster} --cmd {cmd}'

0 commit comments

Comments
 (0)