Skip to content

Commit

Permalink
[ICD] Fix ICDM 2.1 Cert test when the UAT feature map isn't present (p…
Browse files Browse the repository at this point in the history
…roject-chip#36907)

* Fix icdm 2.1 test case without uat

* update CI

* Restyled by isort

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
mkardous-silabs and restyled-commits authored Jan 20, 2025
1 parent b02badf commit d64768e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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'
Expand Down
6 changes: 3 additions & 3 deletions src/python_testing/TC_ICDM_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
72 changes: 72 additions & 0 deletions src/python_testing/test_testing/common_icdm_data.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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__":
Expand Down
38 changes: 38 additions & 0 deletions src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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, c, run_tests

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())

0 comments on commit d64768e

Please sign in to comment.