Skip to content

Commit 1284339

Browse files
andy31415pull[bot]
authored andcommitted
Ensure repl tests stack cleanup even on errors. (#24665)
* Make the zapxml handlers have a specific logger, so we can potentially control their verbosity * Ensure stack shutdown is called even on script errors * Restyle
1 parent 201657a commit 1284339

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from .context import Context, IdlPostProcessor
2222
from .parsing import AttrsToAccessPrivilege, AttrsToAttribute, ParseInt
2323

24+
LOGGER = logging.getLogger('matter-xml-parser')
25+
2426

2527
class ClusterNameHandler(BaseHandler):
2628
"""Handles /configurator/cluster/name elements."""
@@ -137,7 +139,7 @@ def GetNextProcessor(self, name: str, attrs):
137139
elif attrs['op'] == 'write':
138140
self._attribute.writeacl = role
139141
else:
140-
logging.error("Unknown access: %r" % attrs['op'])
142+
LOGGER.error("Unknown access: %r" % attrs['op'])
141143

142144
return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG)
143145
elif name.lower() == 'description':
@@ -230,8 +232,8 @@ def FinalizeProcessing(self, idl: Idl):
230232
found = True
231233

232234
if not found:
233-
logging.error('Enum %s could not find cluster (code %d/0x%X)' %
234-
(self._struct.name, code, code))
235+
LOGGER.error('Enum %s could not find cluster (code %d/0x%X)' %
236+
(self._struct.name, code, code))
235237
else:
236238
idl.structs.append(self._struct)
237239

@@ -279,8 +281,8 @@ def FinalizeProcessing(self, idl: Idl):
279281
found = True
280282

281283
if not found:
282-
logging.error('Enum %s could not find its cluster (code %d/0x%X)' %
283-
(self._enum.name, self._cluster_code, self._cluster_code))
284+
LOGGER.error('Enum %s could not find its cluster (code %d/0x%X)' %
285+
(self._enum.name, self._cluster_code, self._cluster_code))
284286

285287
def EndProcessing(self):
286288
self.context.AddIdlPostProcessor(self)
@@ -319,7 +321,7 @@ def FinalizeProcessing(self, idl: Idl):
319321
# Log only instead of critical, as not our XML is well formed.
320322
# For example at the time of writing this, SwitchFeature in switch-cluster.xml
321323
# did not have a code associated with it.
322-
logging.error("Bitmap %r has no cluster codes" % self._bitmap)
324+
LOGGER.error("Bitmap %r has no cluster codes" % self._bitmap)
323325
return
324326

325327
for code in self._cluster_codes:
@@ -329,8 +331,8 @@ def FinalizeProcessing(self, idl: Idl):
329331
c.bitmaps.append(self._bitmap)
330332
found = True
331333
if not found:
332-
logging.error('Bitmap %s could not find its cluster (code %d/0x%X)' %
333-
(self._bitmap.name, code, code))
334+
LOGGER.error('Bitmap %s could not find its cluster (code %d/0x%X)' %
335+
(self._bitmap.name, code, code))
334336

335337
def EndProcessing(self):
336338
self.context.AddIdlPostProcessor(self)
@@ -413,7 +415,7 @@ def GetNextProcessor(self, name: str, attrs):
413415
if self._command:
414416
self._command.invokeacl = AttrsToAccessPrivilege(attrs)
415417
else:
416-
logging.warning(
418+
LOGGER.warning(
417419
"Ignored access role for reply %r" % self._struct)
418420
return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG)
419421
elif name.lower() == 'arg':
@@ -448,7 +450,7 @@ def GetNextProcessor(self, name: str, attrs):
448450
if name.lower() == 'featurebit':
449451
# It is uncler what featurebits mean. likely a bitmap should be created
450452
# here, however only one such example exists currently: door-lock-cluster.xml
451-
logging.info('Ignoring featurebit tag for global attribute 0x%X (%d)' % (
453+
LOGGER.info('Ignoring featurebit tag for global attribute 0x%X (%d)' % (
452454
self._code, self._code))
453455
return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG)
454456
else:
@@ -533,8 +535,8 @@ def FinalizeProcessing(self, idl: Idl):
533535
c.commands.extend(self._cluster.commands)
534536

535537
if not found:
536-
logging.error('Could not extend cluster 0x%X (%d): cluster not found' %
537-
(self._cluster_code, self._cluster_code))
538+
LOGGER.error('Could not extend cluster 0x%X (%d): cluster not found' %
539+
(self._cluster_code, self._cluster_code))
538540

539541

540542
class GlobalAttributeHandler(BaseHandler):
@@ -572,7 +574,7 @@ def GetNextProcessor(self, name, attrs):
572574
if attrs['side'].lower() == 'client':
573575
# We expect to also have 'server' equivalent, so ignore client
574576
# side attributes
575-
logging.debug(
577+
LOGGER.debug(
576578
'Ignoring global client-side attribute %s' % (attrs['code']))
577579
return BaseHandler(self.context, handled=HandledDepth.SINGLE_TAG)
578580

scripts/tests/chiptest/yamltest_with_chip_repl_tester.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import atexit
1718
import os
1819
import tempfile
1920
import traceback
@@ -39,6 +40,11 @@
3940
os.path.join(_DEFAULT_CHIP_ROOT, "src/app/zap-templates/zcl/data-model/"))
4041

4142

43+
def StackShutdown():
44+
certificateAuthorityManager.Shutdown()
45+
builtins.chipStack.Shutdown()
46+
47+
4248
@click.command()
4349
@click.option(
4450
'--setup-code',
@@ -78,9 +84,18 @@ def main(setup_code, yaml_path, node_id, pics_file):
7884
dev_ctrl = ca_list[0].adminList[0].NewController()
7985
dev_ctrl.CommissionWithCode(setup_code, node_id)
8086

87+
def _StackShutDown():
88+
# Tearing down chip stack. If not done in the correct order test will fail.
89+
certificate_authority_manager.Shutdown()
90+
chip_stack.Shutdown()
91+
92+
atexit.register(_StackShutDown)
93+
8194
try:
8295
# Creating Cluster definition.
83-
clusters_definitions = SpecDefinitionsFromPath(_CLUSTER_XML_DIRECTORY_PATH + '/*/*.xml')
96+
clusters_definitions = SpecDefinitionsFromPath(
97+
_CLUSTER_XML_DIRECTORY_PATH + '/*/*.xml',
98+
)
8499

85100
# Parsing YAML test and setting up chip-repl yamltests runner.
86101
yaml = TestParser(yaml_path, pics_file, clusters_definitions)
@@ -105,9 +120,6 @@ def main(setup_code, yaml_path, node_id, pics_file):
105120
exit(-2)
106121

107122
runner.shutdown()
108-
# Tearing down chip stack. If not done in the correct order test will fail.
109-
certificate_authority_manager.Shutdown()
110-
chip_stack.Shutdown()
111123

112124

113125
if __name__ == '__main__':

0 commit comments

Comments
 (0)