From b0bfa7e5d5e761a5225e93a9046b519774f8ce51 Mon Sep 17 00:00:00 2001 From: Song Guo Date: Wed, 16 Mar 2022 16:33:51 +0800 Subject: [PATCH] Fix --- scripts/tests/run_python_test.py | 2 +- .../python/test/test_scripts/base.py | 7 ++- .../test_scripts/network_commissioning.py | 53 +++++++++---------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/scripts/tests/run_python_test.py b/scripts/tests/run_python_test.py index 3a6aeec08cb469..229e26594a4694 100755 --- a/scripts/tests/run_python_test.py +++ b/scripts/tests/run_python_test.py @@ -106,7 +106,7 @@ def main(app: str, factoryreset: bool, app_params: str, script: str, script_args app_process = subprocess.Popen( app_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) DumpProgramOutputToQueue( - log_cooking_threads, "\33[34mAPP \33[0m", test_script_process, log_queue) + log_cooking_threads, "\33[34mAPP \33[0m", app_process, log_queue) script_command = ["/usr/bin/env", "python3", script, '--log-format', '%(message)s'] + [v for v in script_args] diff --git a/src/controller/python/test/test_scripts/base.py b/src/controller/python/test/test_scripts/base.py index 0dd205c6bc3f3a..2db688e9fd11d1 100644 --- a/src/controller/python/test/test_scripts/base.py +++ b/src/controller/python/test/test_scripts/base.py @@ -15,8 +15,10 @@ # limitations under the License. # +import asyncio from dataclasses import dataclass from inspect import Attribute +import inspect from typing import Any import typing from chip import ChipDeviceCtrl @@ -97,7 +99,10 @@ def test_case(func): def CheckEnableBeforeRun(*args, **kwargs): if TestIsEnabled(test_name=test_name): - func(*args, **kwargs) + return func(*args, **kwargs) + elif inspect.iscoroutinefunction(func): + # noop, so users can use await as usual + return asyncio.sleep(0) return CheckEnableBeforeRun diff --git a/src/controller/python/test/test_scripts/network_commissioning.py b/src/controller/python/test/test_scripts/network_commissioning.py index 553f2cdb4e662d..3038a17cdd114d 100644 --- a/src/controller/python/test/test_scripts/network_commissioning.py +++ b/src/controller/python/test/test_scripts/network_commissioning.py @@ -298,33 +298,32 @@ async def test_thread(self, endpointId): @base.test_case async def Test(self): - try: - clusters = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(Clusters.Descriptor.Attributes.ServerList)], returnClusterObject=True) - if Clusters.NetworkCommissioning.id not in clusters[0][Clusters.Descriptor].serverList: + clusters = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(Clusters.Descriptor.Attributes.ServerList)], returnClusterObject=True) + if Clusters.NetworkCommissioning.id not in clusters[0][Clusters.Descriptor].serverList: + logger.info( + f"Network commissioning cluster {endpoint} is not enabled on this device.") + return + endpoints = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(Clusters.NetworkCommissioning.Attributes.FeatureMap)], returnClusterObject=True) + logger.info(endpoints) + for endpoint, obj in endpoints.items(): + clus = obj[Clusters.NetworkCommissioning] + if clus.featureMap == WIFI_NETWORK_FEATURE_MAP: logger.info( - f"Network commissioning cluster {endpoint} is not enabled on this device.") - return True - endpoints = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(Clusters.NetworkCommissioning.Attributes.FeatureMap)], returnClusterObject=True) - logger.info(endpoints) - for endpoint, obj in endpoints.items(): - clus = obj[Clusters.NetworkCommissioning] - if clus.featureMap == WIFI_NETWORK_FEATURE_MAP: - logger.info( - f"Endpoint {endpoint} is configured as WiFi network, run WiFi commissioning test.") - await self.test_negative(endpoint) - await self.test_wifi(endpoint) - elif clus.featureMap == THREAD_NETWORK_FEATURE_MAP: - logger.info( - f"Endpoint {endpoint} is configured as Thread network, run Thread commissioning test.") - await self.test_negative(endpoint) - await self.test_thread(endpoint) - else: - logger.info( - f"Skip endpoint {endpoint} with featureMap {clus.featureMap}") - except Exception as ex: - logger.exception(ex) - return False - return True + f"Endpoint {endpoint} is configured as WiFi network, run WiFi commissioning test.") + await self.test_negative(endpoint) + await self.test_wifi(endpoint) + elif clus.featureMap == THREAD_NETWORK_FEATURE_MAP: + logger.info( + f"Endpoint {endpoint} is configured as Thread network, run Thread commissioning test.") + await self.test_negative(endpoint) + await self.test_thread(endpoint) + else: + logger.info( + f"Skip endpoint {endpoint} with featureMap {clus.featureMap}") async def run(self): - return await self.Test() + try: + await self.Test() + return True + except Exception as ex: + return False