From 58896ab304b7b7e1b7e0ae279c1a4ba271952d5e Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 22 Aug 2024 16:58:21 +0200 Subject: [PATCH] Fix CHIP REPL tests runner after changes in e407d40 (#34453) * Fix CHIP REPL tests runner after changes in e407d40 The click framework does not have a support for async functions. The async needs to be synchronized before applying click wrappers. * Accept 0x, 0b or 0o prefix for int values * Fix for non-string numbers * Exclude Test_TC_BRBINFO_2_1 from chip-repl engine * Log what happened in case of pseudo cluster creation failure * Fix typo * Fix typo when accessing TestGlobalStruct * Fix new line --- scripts/tests/chiptest/__init__.py | 1 + .../tests/chiptest/yamltest_with_chip_repl_tester.py | 11 ++++++++++- src/controller/python/chip/yaml/format_converter.py | 7 ++++--- src/controller/python/chip/yaml/runner.py | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/tests/chiptest/__init__.py b/scripts/tests/chiptest/__init__.py index aef22e030eae8d..03ac663427ce84 100644 --- a/scripts/tests/chiptest/__init__.py +++ b/scripts/tests/chiptest/__init__.py @@ -234,6 +234,7 @@ def _GetChipReplUnsupportedTests() -> Set[str]: "TestEventsById.yaml", # chip-repl does not support AnyCommands (06/06/2023) "TestReadNoneSubscribeNone.yaml", # chip-repl does not support AnyCommands (07/27/2023) "Test_TC_IDM_1_2.yaml", # chip-repl does not support AnyCommands (19/07/2023) + "Test_TC_BRBINFO_2_1.yaml", # chip-repl does not support AnyCommands (24/07/2024) "TestIcdManagementCluster.yaml", # TODO(#30430): add ICD registration support in chip-repl "Test_TC_ICDM_3_4.yaml", # chip-repl does not support ICD registration # chip-repl and chip-tool disagree on what the YAML here should look like: https://github.com/project-chip/connectedhomeip/issues/29110 diff --git a/scripts/tests/chiptest/yamltest_with_chip_repl_tester.py b/scripts/tests/chiptest/yamltest_with_chip_repl_tester.py index 1b301c572874d0..70f9215f5456be 100644 --- a/scripts/tests/chiptest/yamltest_with_chip_repl_tester.py +++ b/scripts/tests/chiptest/yamltest_with_chip_repl_tester.py @@ -16,6 +16,7 @@ import asyncio import atexit +import functools import logging import os import tempfile @@ -84,6 +85,13 @@ async def execute_test(yaml, runner): raise Exception(f'Test step failed {test_step.label}') +def asyncio_executor(f): + @functools.wraps(f) + def wrapper(*args, **kwargs): + return asyncio.run(f(*args, **kwargs)) + return wrapper + + @click.command() @click.option( '--setup-code', @@ -101,6 +109,7 @@ async def execute_test(yaml, runner): '--pics-file', default=None, help='Optional PICS file') +@asyncio_executor async def main(setup_code, yaml_path, node_id, pics_file): # Setting up python environment for running YAML CI tests using python parser. with tempfile.NamedTemporaryFile() as chip_stack_storage: @@ -153,4 +162,4 @@ def _StackShutDown(): if __name__ == '__main__': - asyncio.run(main()) + main() diff --git a/src/controller/python/chip/yaml/format_converter.py b/src/controller/python/chip/yaml/format_converter.py index eefe61f172ee15..1be051155b6040 100644 --- a/src/controller/python/chip/yaml/format_converter.py +++ b/src/controller/python/chip/yaml/format_converter.py @@ -198,10 +198,11 @@ def convert_to_data_model_type(field_value, field_type): return field_value # YAML conversion treats all numbers as ints. Convert to a uint type if the schema # type indicates so. - elif (field_type == uint): + elif (type(field_value) is str and field_type == uint): # Longer number are stored as strings. Need to make this conversion first. - value = int(field_value) - return field_type(value) + # The value can be represented in binary, octal, decimal or hexadecimal + # format. + return field_type(int(field_value, 0)) # YAML treats enums as ints. Convert to the typed enum class. elif (issubclass(field_type, MatterIntEnum)): return field_type.extend_enum_if_value_doesnt_exist(field_value) diff --git a/src/controller/python/chip/yaml/runner.py b/src/controller/python/chip/yaml/runner.py index 00e0de2154e5ec..8a19109439e3cf 100644 --- a/src/controller/python/chip/yaml/runner.py +++ b/src/controller/python/chip/yaml/runner.py @@ -832,7 +832,8 @@ def _commissioner_command_action_factory(self, test_step): def _default_pseudo_cluster(self, test_step): try: return DefaultPseudoCluster(test_step) - except ActionCreationError: + except ActionCreationError as e: + logger.warn(f"Failed create default pseudo cluster: {e}") return None def encode(self, request) -> Optional[BaseAction]: