Skip to content

Commit 4429a43

Browse files
committed
Disallow --endpoint with automatic endpoint selection
1 parent 3bd4b45 commit 4429a43

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/python_testing/matter_testing_support.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class MatterTestConfig:
504504
# List of explicit tests to run by name. If empty, all tests will run
505505
tests: List[str] = field(default_factory=list)
506506
timeout: typing.Union[int, None] = None
507-
endpoint: int = 0
507+
endpoint: typing.Union[int, None] = 0
508508
app_pid: int = 0
509509

510510
commissioning_method: Optional[str] = None
@@ -980,7 +980,7 @@ async def read_single_attribute_check_success(
980980
if node_id is None:
981981
node_id = self.dut_node_id
982982
if endpoint is None:
983-
endpoint = self.matter_test_config.endpoint
983+
endpoint = 0 if self.matter_test_config.endpoint is None else self.matter_test_config.endpoint
984984

985985
result = await dev_ctrl.ReadAttribute(node_id, [(endpoint, attribute)], fabricFiltered=fabric_filtered)
986986
attr_ret = result[endpoint][cluster][attribute]
@@ -1012,7 +1012,7 @@ async def read_single_attribute_expect_error(
10121012
if node_id is None:
10131013
node_id = self.dut_node_id
10141014
if endpoint is None:
1015-
endpoint = self.matter_test_config.endpoint
1015+
endpoint = 0 if self.matter_test_config.endpoint is None else self.matter_test_config.endpoint
10161016

10171017
result = await dev_ctrl.ReadAttribute(node_id, [(endpoint, attribute)], fabricFiltered=fabric_filtered)
10181018
attr_ret = result[endpoint][cluster][attribute]
@@ -1041,12 +1041,13 @@ async def write_single_attribute(self, attribute_value: object, endpoint_id: int
10411041
"""
10421042
dev_ctrl = self.default_controller
10431043
node_id = self.dut_node_id
1044-
endpoint = self.matter_test_config.endpoint if endpoint_id is None else endpoint_id
1044+
if endpoint_id is None:
1045+
endpoint_id = 0 if self.matter_test_config.endpoint is None else self.matter_test_config.endpoint
10451046

1046-
write_result = await dev_ctrl.WriteAttribute(node_id, [(endpoint, attribute_value)])
1047+
write_result = await dev_ctrl.WriteAttribute(node_id, [(endpoint_id, attribute_value)])
10471048
if expect_success:
10481049
asserts.assert_equal(write_result[0].Status, Status.Success,
1049-
f"Expected write success for write to attribute {attribute_value} on endpoint {endpoint}")
1050+
f"Expected write success for write to attribute {attribute_value} on endpoint {endpoint_id}")
10501051
return write_result[0].Status
10511052

10521053
async def send_single_cmd(
@@ -1059,7 +1060,7 @@ async def send_single_cmd(
10591060
if node_id is None:
10601061
node_id = self.dut_node_id
10611062
if endpoint is None:
1062-
endpoint = self.matter_test_config.endpoint
1063+
endpoint = 0 if self.matter_test_config.endpoint is None else self.matter_test_config.endpoint
10631064

10641065
result = await dev_ctrl.SendCommand(nodeid=node_id, endpoint=endpoint, payload=cmd, timedRequestTimeoutMs=timedRequestTimeoutMs,
10651066
payloadCapability=payloadCapability)
@@ -1584,7 +1585,7 @@ def convert_args_to_matter_config(args: argparse.Namespace) -> MatterTestConfig:
15841585
config.pics = {} if args.PICS is None else read_pics_from_file(args.PICS)
15851586
config.tests = [] if args.tests is None else args.tests
15861587
config.timeout = args.timeout # This can be none, we pull the default from the test if it's unspecified
1587-
config.endpoint = 0 if args.endpoint is None else args.endpoint
1588+
config.endpoint = args.endpoint
15881589
config.app_pid = 0 if args.app_pid is None else args.app_pid
15891590

15901591
config.controller_node_id = args.controller_node_id
@@ -1863,7 +1864,17 @@ async def get_accepted_endpoints_for_test(self: MatterBaseTest, accept_function:
18631864
18641865
Returns a list of endpoints on which the test should be run given the accept_function for the test.
18651866
"""
1866-
wildcard = await self.default_controller.Read(self.dut_node_id, [()])
1867+
1868+
if self.matter_test_config.endpoint is not None:
1869+
msg = """
1870+
The --endpoint flag is disallowed for tests that run on all matching endpoints.
1871+
To enable running against a single endpoint for development purposes, use
1872+
--int-arg force_endpoint:1 (where "1" can be replaced with the desired endpoint)
1873+
Note that using force_endpoint is disallowed at certification and should be used
1874+
ONLY FOR DEVELOPMENT.
1875+
"""
1876+
asserts.fail(msg)
1877+
18671878
matching = [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
18681879
forced_endpoint = self.user_params.get('force_endpoint', None)
18691880
if forced_endpoint is None:
@@ -1931,7 +1942,6 @@ def per_endpoint_runner(self: MatterBaseTest, *args, **kwargs):
19311942
# Ditto for teardown - we want to tear down after each iteration, and we want to notify the hook that
19321943
# the test iteration is stopped. test_stop is called by on_pass or on_fail during the last iteration or
19331944
# on failure.
1934-
original_ep = self.matter_test_config.endpoint
19351945
for e in endpoints:
19361946
logging.info(f'Running test on endpoint {e}')
19371947
if e != endpoints[0]:
@@ -1942,7 +1952,7 @@ def per_endpoint_runner(self: MatterBaseTest, *args, **kwargs):
19421952
self.teardown_test()
19431953
test_duration = (datetime.now(timezone.utc) - self.test_start_time) / timedelta(microseconds=1)
19441954
self.runner_hook.test_stop(exception=None, duration=test_duration)
1945-
self.matter_test_config.endpoint = original_ep
1955+
self.matter_test_config.endpoint = None
19461956
return per_endpoint_runner
19471957
return run_for_each_matching_endpoint_internal
19481958

src/python_testing/test_testing/TestDecorators.py

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class TestDecorators(MatterBaseTest):
108108
def teardown_test(self):
109109
if 'force_endpoint' in self.user_params.keys():
110110
del self.user_params['force_endpoint']
111+
self.matter_test_config.endpoint = None
111112

112113
def test_checkers(self):
113114
has_onoff = has_cluster(Clusters.OnOff)
@@ -182,6 +183,16 @@ async def test_force_endpoint_bad(self):
182183

183184
await get_accepted_endpoints_for_test(self, has_onoff)
184185

186+
@async_test_body
187+
async def test_endpoints_with_endpoint_flag_set_failure(self):
188+
''' This test should cause an assertion because --endpoint flag is set.'''
189+
has_onoff = has_cluster(Clusters.OnOff)
190+
all_endpoints = await self.default_controller.Read(self.dut_node_id, [()])
191+
all_endpoints = list(all_endpoints.attributes.keys())
192+
self.matter_test_config.endpoint = 0
193+
194+
await get_accepted_endpoints_for_test(self, has_onoff)
195+
185196
# This test should cause an assertion because it has pics_ method
186197

187198
@run_once_for_node
@@ -300,6 +311,12 @@ def main():
300311
if ok:
301312
failures.append("Test case failure: test_force_endpoint_bad")
302313

314+
test_runner.set_test('TestDecorators.py', 'TestDecorators', 'test_endpoints_with_endpoint_flag_set_failure')
315+
read_resp = get_clusters([0, 1])
316+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
317+
if ok:
318+
failures.append("Test case failure: test_endpoints_with_endpoint_flag_set_failure")
319+
303320
test_name = 'test_whole_node_with_pics'
304321
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
305322
ok = test_runner.run_test_with_mock_read(read_resp, hooks)

0 commit comments

Comments
 (0)