Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure repl tests stack cleanup even on errors. #24665

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from .context import Context, IdlPostProcessor
from .parsing import AttrsToAccessPrivilege, AttrsToAttribute, ParseInt

LOGGER = logging.getLogger('matter-xml-parser')


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

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

if not found:
logging.error('Enum %s could not find cluster (code %d/0x%X)' %
(self._struct.name, code, code))
LOGGER.error('Enum %s could not find cluster (code %d/0x%X)' %
(self._struct.name, code, code))
else:
idl.structs.append(self._struct)

Expand Down Expand Up @@ -279,8 +281,8 @@ def FinalizeProcessing(self, idl: Idl):
found = True

if not found:
logging.error('Enum %s could not find its cluster (code %d/0x%X)' %
(self._enum.name, self._cluster_code, self._cluster_code))
LOGGER.error('Enum %s could not find its cluster (code %d/0x%X)' %
(self._enum.name, self._cluster_code, self._cluster_code))

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

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

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

if not found:
logging.error('Could not extend cluster 0x%X (%d): cluster not found' %
(self._cluster_code, self._cluster_code))
LOGGER.error('Could not extend cluster 0x%X (%d): cluster not found' %
(self._cluster_code, self._cluster_code))


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

Expand Down
20 changes: 16 additions & 4 deletions scripts/tests/chiptest/yamltest_with_chip_repl_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import atexit
import os
import tempfile
import traceback
Expand All @@ -39,6 +40,11 @@
os.path.join(_DEFAULT_CHIP_ROOT, "src/app/zap-templates/zcl/data-model/"))


def StackShutdown():
certificateAuthorityManager.Shutdown()
builtins.chipStack.Shutdown()


@click.command()
@click.option(
'--setup-code',
Expand Down Expand Up @@ -78,9 +84,18 @@ def main(setup_code, yaml_path, node_id, pics_file):
dev_ctrl = ca_list[0].adminList[0].NewController()
dev_ctrl.CommissionWithCode(setup_code, node_id)

def _StackShutDown():
# Tearing down chip stack. If not done in the correct order test will fail.
certificate_authority_manager.Shutdown()
chip_stack.Shutdown()

atexit.register(_StackShutDown)

try:
# Creating Cluster definition.
clusters_definitions = SpecDefinitionsFromPath(_CLUSTER_XML_DIRECTORY_PATH + '/*/*.xml')
clusters_definitions = SpecDefinitionsFromPath(
_CLUSTER_XML_DIRECTORY_PATH + '/*/*.xml',
)

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

runner.shutdown()
# Tearing down chip stack. If not done in the correct order test will fail.
certificate_authority_manager.Shutdown()
chip_stack.Shutdown()


if __name__ == '__main__':
Expand Down