From e6cd90ea55465e9f6180edfb7a8795de34b6ee97 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sat, 7 Oct 2023 00:21:32 -0400 Subject: [PATCH] Allow groupId to be a variable in YAML tests. This allows targeting group messages at a group id that's a config define. Fixes https://github.com/project-chip/connectedhomeip/issues/29637 --- .../matter_yamltests/parser.py | 2 ++ .../matter_yamltests/yaml_loader.py | 2 +- .../py_matter_yamltests/test_yaml_loader.py | 18 +++++++++++++++++- src/app/tests/suites/TestGroupMessaging.yaml | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/parser.py b/scripts/py_matter_yamltests/matter_yamltests/parser.py index 18e643d97d5df5..ec4462b4359dd3 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/parser.py +++ b/scripts/py_matter_yamltests/matter_yamltests/parser.py @@ -593,6 +593,8 @@ def __init__(self, test: _TestStepWithPlaceholders, step_index: int, runtime_con self._test.event) self._test.endpoint = self._config_variable_substitution( self._test.endpoint) + self._test.group_id = self._config_variable_substitution( + self._test.group_id) test.update_arguments(self.arguments) test.update_responses(self.responses) diff --git a/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py b/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py index d798ef5f06d99c..aba73157e1aa9f 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py +++ b/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py @@ -91,7 +91,7 @@ def __check_test_step(self, config: dict, content): 'identity': str, 'nodeId': int, 'runIf': str, # Should be a variable. - 'groupId': int, + 'groupId': (int, str), # Can be a variable. 'endpoint': (int, str), # Can be a variable 'cluster': str, 'attribute': str, diff --git a/scripts/py_matter_yamltests/test_yaml_loader.py b/scripts/py_matter_yamltests/test_yaml_loader.py index d0078a8bea7b98..41929d95747306 100644 --- a/scripts/py_matter_yamltests/test_yaml_loader.py +++ b/scripts/py_matter_yamltests/test_yaml_loader.py @@ -247,7 +247,6 @@ def test_key_tests_step_int_keys(self): ' - {key}: {value}') keys = [ 'nodeId', - 'groupId', 'minInterval', 'maxInterval', 'timedInteractionTimeoutMs', @@ -324,6 +323,23 @@ def test_key_tests_step_endpoint_number_key(self): x = content.format(value=value) self.assertRaises(TestStepInvalidTypeError, load, x) + def test_key_tests_step_group_id_key(self): + load = YamlLoader().load + + content = ('tests:\n' + ' - groupId: {value}') + + _, _, _, _, tests = load(content.format(value=1)) + self.assertEqual(tests, [{'groupId': 1}]) + + _, _, _, _, tests = load(content.format(value='TestKey')) + self.assertEqual(tests, [{'groupId': 'TestKey'}]) + + wrong_values = self._get_wrong_values([str, int], spaces=6) + for value in wrong_values: + x = content.format(value=value) + self.assertRaises(TestStepInvalidTypeError, load, x) + def test_key_tests_step_event_number_key(self): load = YamlLoader().load diff --git a/src/app/tests/suites/TestGroupMessaging.yaml b/src/app/tests/suites/TestGroupMessaging.yaml index 74aeef605eef54..89935b650b7e2c 100644 --- a/src/app/tests/suites/TestGroupMessaging.yaml +++ b/src/app/tests/suites/TestGroupMessaging.yaml @@ -22,6 +22,10 @@ config: nodeId: 0x12344321 cluster: "Basic Information" endpoint: 0 + # Test that a group id can be a variable. + groupIdVariable: + type: int16u + defaultValue: 0x0101 nodeId2: type: node_id defaultValue: 0x43211234 @@ -215,7 +219,7 @@ tests: - label: "Turn On the light to see attribute change" cluster: "On/Off" command: "On" - groupId: 0x0101 + groupId: groupIdVariable # 0x0101 # Give the group invoke time to actually happen; unicast delivery can outrace # multicast if the unicast packet is sent immediately after the multicast one.