From 6527e1df163e5b31df121484cedf217f61576397 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 19 Dec 2024 13:24:18 -0500 Subject: [PATCH 1/3] Fix icdm 2.1 test case without uat --- src/python_testing/TC_ICDM_2_1.py | 6 +- .../test_testing/common_icdm_data.py | 72 +++++++++++++++++++ ...M_2_1.py => test_TC_ICDM_2_1_full_pics.py} | 53 +------------- .../test_testing/test_TC_ICDM_2_1_min_pics.py | 37 ++++++++++ 4 files changed, 114 insertions(+), 54 deletions(-) create mode 100644 src/python_testing/test_testing/common_icdm_data.py rename src/python_testing/test_testing/{test_TC_ICDM_2_1.py => test_TC_ICDM_2_1_full_pics.py} (81%) create mode 100644 src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py diff --git a/src/python_testing/TC_ICDM_2_1.py b/src/python_testing/TC_ICDM_2_1.py index 8d7f6d5ed876ec..5a2abc5e983d96 100644 --- a/src/python_testing/TC_ICDM_2_1.py +++ b/src/python_testing/TC_ICDM_2_1.py @@ -238,8 +238,8 @@ async def test_TC_ICDM_2_1(self): uatHintInstructionDepedentBitmap = uat( userActiveModeTriggerHint) & kUatInstructionDependentBitMask - asserts.assert_less_equal( - self.set_bits_count(uatHintInstructionDepedentBitmap), 1, "UserActiveModeTriggerHint has more than 1 bit that is dependent on the UserActiveModeTriggerInstruction") + asserts.assert_less_equal( + self.set_bits_count(uatHintInstructionDepedentBitmap), 1, "UserActiveModeTriggerHint has more than 1 bit that is dependent on the UserActiveModeTriggerInstruction") # Valdate UserActiveModeTriggerInstruction self.step(9) @@ -268,7 +268,7 @@ async def test_TC_ICDM_2_1(self): pattern = re.compile(r'^[0-9A-F]{6}$') asserts.assert_true(pattern.match(userActiveModeTriggerInstruction), "UserActiveModeTriggerInstruction is not in the correct format for the associated UserActiveModeTriggerHint") - else: + elif self.check_pics("ICDM.S.A0006"): # Check if the UserActiveModeTriggerInstruction was required asserts.assert_false(uatHintInstructionDepedentBitmap in kUatInstructionMandatoryBitMask, "UserActiveModeTriggerHint requires the UserActiveModeTriggerInstruction") diff --git a/src/python_testing/test_testing/common_icdm_data.py b/src/python_testing/test_testing/common_icdm_data.py new file mode 100644 index 00000000000000..5ff2ae93fd148e --- /dev/null +++ b/src/python_testing/test_testing/common_icdm_data.py @@ -0,0 +1,72 @@ +#!/usr/bin/env -S python3 -B +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import string +from dataclasses import dataclass +import chip.clusters as Clusters +from chip.clusters import Attribute +from MockTestRunner import MockTestRunner + + +c = Clusters.IcdManagement +attr = c.Attributes +uat = c.Bitmaps.UserActiveModeTriggerBitmap + + +@dataclass +class ICDMData(): + FeatureMap: int + IdleModeDuration: int + ActiveModeDuration: int + ActiveModeThreshold: int + RegisteredClients: list + ICDCounter: int + ClientsSupportedPerFabric: int + UserActiveModeTriggerHint: int + UserActiveModeTriggerInstruction: string + OperatingMode: c.Enums.OperatingModeEnum + MaximumCheckInBackOff: int + expect_pass: bool + + +def test_spec_to_attribute_cache(test_icdm: ICDMData) -> Attribute.AsyncReadTransaction.ReadResponse: + resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {}) + resp.attributes = {0: {c: {attr.FeatureMap: test_icdm.FeatureMap, attr.IdleModeDuration: test_icdm.IdleModeDuration, attr.ActiveModeDuration: test_icdm.ActiveModeDuration, attr.ActiveModeThreshold: test_icdm.ActiveModeThreshold, + attr.RegisteredClients: test_icdm.RegisteredClients, attr.ICDCounter: test_icdm.ICDCounter, + attr.ClientsSupportedPerFabric: test_icdm.ClientsSupportedPerFabric, attr.UserActiveModeTriggerHint: test_icdm.UserActiveModeTriggerHint, + attr.UserActiveModeTriggerInstruction: test_icdm.UserActiveModeTriggerInstruction, attr.OperatingMode: test_icdm.OperatingMode, attr.MaximumCheckInBackOff: test_icdm.MaximumCheckInBackOff}}} + return resp + + +def run_tests(pics, label, test_cases, test_name): + test_runner = MockTestRunner( + label, label, test_name, 0, pics) + failures = [] + for idx, t in enumerate(test_cases): + ok = test_runner.run_test_with_mock_read( + test_spec_to_attribute_cache(t)) == t.expect_pass + if not ok: + failures.append(f"Measured test case failure: {idx} {t}") + + test_runner.Shutdown() + print( + f"Test of tests: run {len(test_cases)}, test response correct: {len(test_cases) - len(failures)} | test response incorrect: {len(failures)}") + for f in failures: + print(f) + + return 1 if failures else 0 diff --git a/src/python_testing/test_testing/test_TC_ICDM_2_1.py b/src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py similarity index 81% rename from src/python_testing/test_testing/test_TC_ICDM_2_1.py rename to src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py index a337b91ccef41d..f56ea26fd4d465 100755 --- a/src/python_testing/test_testing/test_TC_ICDM_2_1.py +++ b/src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py @@ -16,34 +16,9 @@ # limitations under the License. # -import string import sys -from dataclasses import dataclass - -import chip.clusters as Clusters -from chip.clusters import Attribute -from MockTestRunner import MockTestRunner - -c = Clusters.IcdManagement -attr = c.Attributes -uat = c.Bitmaps.UserActiveModeTriggerBitmap - - -@dataclass -class ICDMData(): - FeatureMap: int - IdleModeDuration: int - ActiveModeDuration: int - ActiveModeThreshold: int - RegisteredClients: list - ICDCounter: int - ClientsSupportedPerFabric: int - UserActiveModeTriggerHint: int - UserActiveModeTriggerInstruction: string - OperatingMode: c.Enums.OperatingModeEnum - MaximumCheckInBackOff: int - expect_pass: bool +from common_icdm_data import ICDMData, c, run_tests, uat long_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e" too_long_string = long_string + "1" @@ -217,35 +192,11 @@ class ICDMData(): ] -def test_spec_to_attribute_cache(test_icdm: ICDMData) -> Attribute.AsyncReadTransaction.ReadResponse: - resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {}) - resp.attributes = {0: {c: {attr.FeatureMap: test_icdm.FeatureMap, attr.IdleModeDuration: test_icdm.IdleModeDuration, attr.ActiveModeDuration: test_icdm.ActiveModeDuration, attr.ActiveModeThreshold: test_icdm.ActiveModeThreshold, - attr.RegisteredClients: test_icdm.RegisteredClients, attr.ICDCounter: test_icdm.ICDCounter, - attr.ClientsSupportedPerFabric: test_icdm.ClientsSupportedPerFabric, attr.UserActiveModeTriggerHint: test_icdm.UserActiveModeTriggerHint, - attr.UserActiveModeTriggerInstruction: test_icdm.UserActiveModeTriggerInstruction, attr.OperatingMode: test_icdm.OperatingMode, attr.MaximumCheckInBackOff: test_icdm.MaximumCheckInBackOff}}} - return resp - - def main(): pics = {"ICDM.S.A0000": True, "ICDM.S.A0001": True, "ICDM.S.A0002": True, "ICDM.S.A0003": True, "ICDM.S.A0004": True, "ICDM.S.A0005": True, "ICDM.S.A0006": True, "ICDM.S.A0007": True, "ICDM.S.A0008": True, "ICDM.S.A0009": True, } - test_runner = MockTestRunner( - 'TC_ICDM_2_1', 'TC_ICDM_2_1', 'test_TC_ICDM_2_1', 0, pics) - failures = [] - for idx, t in enumerate(TEST_CASES): - ok = test_runner.run_test_with_mock_read( - test_spec_to_attribute_cache(t)) == t.expect_pass - if not ok: - failures.append(f"Measured test case failure: {idx} {t}") - - test_runner.Shutdown() - print( - f"Test of tests: run {len(TEST_CASES)}, test response correct: {len(TEST_CASES) - len(failures)} | test response incorrect: {len(failures)}") - for f in failures: - print(f) - - return 1 if failures else 0 + return run_tests(pics, 'TC_ICDM_2_1', TEST_CASES, 'test_TC_ICDM_2_1') if __name__ == "__main__": diff --git a/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py b/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py new file mode 100644 index 00000000000000..55893d0fefb68b --- /dev/null +++ b/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py @@ -0,0 +1,37 @@ +#!/usr/bin/env -S python3 -B +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import sys +from common_icdm_data import ICDMData, run_tests, c + +TEST_CASES = [ + # Validate that the test script can succeed with the minimum set of PICS + ICDMData(0, 1, 0, 100, [], 0, 2, 0, "", + c.Enums.OperatingModeEnum.kSit, 64800, True), +] + + +def main(): + pics = {"ICDM.S.A0000": True, "ICDM.S.A0001": True, "ICDM.S.A0002": True, "ICDM.S.A0003": False, "ICDM.S.A0004": False, + "ICDM.S.A0005": False, "ICDM.S.A0006": False, "ICDM.S.A0007": False, "ICDM.S.A0008": False, "ICDM.S.A0009": False, } + + return run_tests(pics, 'TC_ICDM_2_1', TEST_CASES, 'test_TC_ICDM_2_1') + + +if __name__ == "__main__": + sys.exit(main()) From 826d58eafc843f308601c1a0fad2c06689c0a544 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 19 Dec 2024 13:26:30 -0500 Subject: [PATCH 2/3] update CI --- .github/workflows/tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index df1cdb03745a99..9c9ca9c455cb50 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -523,7 +523,8 @@ jobs: - name: Verify Testing Support run: | scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_IDM_10_4.py' - scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1.py' + scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py' + scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py' scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_SC_7_1.py' scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/TestDecorators.py' scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/TestChoiceConformanceSupport.py' From b6eaf5168f7a9baf05ce90a997a8d4207b68c16a Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 19 Dec 2024 18:29:08 +0000 Subject: [PATCH 3/3] Restyled by isort --- src/python_testing/test_testing/common_icdm_data.py | 2 +- src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/common_icdm_data.py b/src/python_testing/test_testing/common_icdm_data.py index 5ff2ae93fd148e..aa2fb235e12371 100644 --- a/src/python_testing/test_testing/common_icdm_data.py +++ b/src/python_testing/test_testing/common_icdm_data.py @@ -18,11 +18,11 @@ import string from dataclasses import dataclass + import chip.clusters as Clusters from chip.clusters import Attribute from MockTestRunner import MockTestRunner - c = Clusters.IcdManagement attr = c.Attributes uat = c.Bitmaps.UserActiveModeTriggerBitmap diff --git a/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py b/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py index 55893d0fefb68b..1001b9bfe1fbd4 100644 --- a/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py +++ b/src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py @@ -17,7 +17,8 @@ # import sys -from common_icdm_data import ICDMData, run_tests, c + +from common_icdm_data import ICDMData, c, run_tests TEST_CASES = [ # Validate that the test script can succeed with the minimum set of PICS