Skip to content

Commit 5335041

Browse files
andy31415pull[bot]
authored andcommitted
Less XML parsing, resulting in less errors (#24667)
1 parent 3fc56ea commit 5335041

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

scripts/py_matter_yamltests/matter_yamltests/definitions.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __enforce_casing(self, target_name: str, targets: list):
232232
f'Unknown target {target_name}. Did you mean {name} ?')
233233

234234

235-
def SpecDefinitionsFromPath(path: str):
235+
def SpecDefinitionsFromPaths(paths: str):
236236
def sort_with_global_attribute_first(a, b):
237237
if a.endswith('global-attributes.xml'):
238238
return -1
@@ -245,7 +245,13 @@ def sort_with_global_attribute_first(a, b):
245245
elif a < b:
246246
return -1
247247

248-
filenames = glob.glob(path, recursive=False)
248+
filenames = []
249+
for path in paths:
250+
if '*' in path or '?' in path:
251+
filenames.extend(glob.glob(path, recursive=False))
252+
else:
253+
filenames.append(path)
254+
249255
filenames.sort(key=functools.cmp_to_key(sort_with_global_attribute_first))
250256
sources = [ParseSource(source=name) for name in filenames]
251257
return SpecDefinitions(sources)

scripts/tests/chiptest/yamltest_with_chip_repl_tester.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import click
3232
from chip.ChipStack import *
3333
from chip.yaml.runner import ReplTestRunner
34-
from matter_yamltests.definitions import SpecDefinitionsFromPath
34+
from matter_yamltests.definitions import SpecDefinitionsFromPaths
3535
from matter_yamltests.parser import TestParser
3636

3737
_DEFAULT_CHIP_ROOT = os.path.abspath(
@@ -75,7 +75,8 @@ def main(setup_code, yaml_path, node_id, pics_file):
7575
ca = certificate_authority_manager.NewCertificateAuthority()
7676
ca.NewFabricAdmin(vendorId=0xFFF1, fabricId=1)
7777
elif len(certificate_authority_manager.activeCaList[0].adminList) == 0:
78-
certificate_authority_manager.activeCaList[0].NewFabricAdmin(vendorId=0xFFF1, fabricId=1)
78+
certificate_authority_manager.activeCaList[0].NewFabricAdmin(
79+
vendorId=0xFFF1, fabricId=1)
7980

8081
ca_list = certificate_authority_manager.activeCaList
8182

@@ -93,26 +94,33 @@ def _StackShutDown():
9394

9495
try:
9596
# Creating Cluster definition.
96-
clusters_definitions = SpecDefinitionsFromPath(
97-
_CLUSTER_XML_DIRECTORY_PATH + '/*/*.xml',
98-
)
97+
clusters_definitions = SpecDefinitionsFromPaths([
98+
_CLUSTER_XML_DIRECTORY_PATH + '/chip/*.xml',
99+
100+
# Some still-silabs clusters
101+
_CLUSTER_XML_DIRECTORY_PATH + '/silabs/ha.xml', # For fan control
102+
_CLUSTER_XML_DIRECTORY_PATH + '/silabs/general.xml', # For groups cluster
103+
])
99104

100105
# Parsing YAML test and setting up chip-repl yamltests runner.
101106
yaml = TestParser(yaml_path, pics_file, clusters_definitions)
102-
runner = ReplTestRunner(clusters_definitions, certificate_authority_manager, dev_ctrl)
107+
runner = ReplTestRunner(
108+
clusters_definitions, certificate_authority_manager, dev_ctrl)
103109

104110
# Executing and validating test
105111
for test_step in yaml.tests:
106112
test_action = runner.encode(test_step)
107113
# TODO if test_action is None we should see if it is a pseudo cluster.
108114
if test_action is None:
109-
raise Exception(f'Failed to encode test step {test_step.label}')
115+
raise Exception(
116+
f'Failed to encode test step {test_step.label}')
110117
if not test_action.pics_enabled:
111118
continue
112119

113120
response = runner.execute(test_action)
114121
decoded_response = runner.decode(response)
115-
post_processing_result = test_step.post_process_response(decoded_response)
122+
post_processing_result = test_step.post_process_response(
123+
decoded_response)
116124
if not post_processing_result.is_success():
117125
raise Exception(f'Test step failed {test_step.label}')
118126
except Exception:

src/controller/python/chip/yaml/runner.py

+3
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ def decode(self, result: _ActionResult):
629629
return decoded_response
630630

631631
cluster_name = self._test_spec_definition.get_cluster_name(response.cluster_id)
632+
if cluster_name is None:
633+
raise Exception("Cannot find cluster name for id 0x%0X / %d" % (response.cluster_id, response.cluster_id))
634+
632635
decoded_response['clusterId'] = cluster_name
633636

634637
if hasattr(response, 'command_id'):

0 commit comments

Comments
 (0)