Skip to content

Commit d64768e

Browse files
[ICD] Fix ICDM 2.1 Cert test when the UAT feature map isn't present (#36907)
* Fix icdm 2.1 test case without uat * update CI * Restyled by isort --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b02badf commit d64768e

File tree

5 files changed

+117
-55
lines changed

5 files changed

+117
-55
lines changed

.github/workflows/tests.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ jobs:
527527
- name: Verify Testing Support
528528
run: |
529529
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_IDM_10_4.py'
530-
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1.py'
530+
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py'
531+
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_ICDM_2_1_min_pics.py'
531532
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/test_TC_SC_7_1.py'
532533
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/test_testing/TestDecorators.py'
533534
scripts/run_in_python_env.sh out/venv 'python3 src/python_testing/TestChoiceConformanceSupport.py'

src/python_testing/TC_ICDM_2_1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ async def test_TC_ICDM_2_1(self):
238238
uatHintInstructionDepedentBitmap = uat(
239239
userActiveModeTriggerHint) & kUatInstructionDependentBitMask
240240

241-
asserts.assert_less_equal(
242-
self.set_bits_count(uatHintInstructionDepedentBitmap), 1, "UserActiveModeTriggerHint has more than 1 bit that is dependent on the UserActiveModeTriggerInstruction")
241+
asserts.assert_less_equal(
242+
self.set_bits_count(uatHintInstructionDepedentBitmap), 1, "UserActiveModeTriggerHint has more than 1 bit that is dependent on the UserActiveModeTriggerInstruction")
243243

244244
# Valdate UserActiveModeTriggerInstruction
245245
self.step(9)
@@ -268,7 +268,7 @@ async def test_TC_ICDM_2_1(self):
268268
pattern = re.compile(r'^[0-9A-F]{6}$')
269269
asserts.assert_true(pattern.match(userActiveModeTriggerInstruction),
270270
"UserActiveModeTriggerInstruction is not in the correct format for the associated UserActiveModeTriggerHint")
271-
else:
271+
elif self.check_pics("ICDM.S.A0006"):
272272
# Check if the UserActiveModeTriggerInstruction was required
273273
asserts.assert_false(uatHintInstructionDepedentBitmap in kUatInstructionMandatoryBitMask,
274274
"UserActiveModeTriggerHint requires the UserActiveModeTriggerInstruction")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env -S python3 -B
2+
#
3+
# Copyright (c) 2024 Project CHIP Authors
4+
# All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
import string
20+
from dataclasses import dataclass
21+
22+
import chip.clusters as Clusters
23+
from chip.clusters import Attribute
24+
from MockTestRunner import MockTestRunner
25+
26+
c = Clusters.IcdManagement
27+
attr = c.Attributes
28+
uat = c.Bitmaps.UserActiveModeTriggerBitmap
29+
30+
31+
@dataclass
32+
class ICDMData():
33+
FeatureMap: int
34+
IdleModeDuration: int
35+
ActiveModeDuration: int
36+
ActiveModeThreshold: int
37+
RegisteredClients: list
38+
ICDCounter: int
39+
ClientsSupportedPerFabric: int
40+
UserActiveModeTriggerHint: int
41+
UserActiveModeTriggerInstruction: string
42+
OperatingMode: c.Enums.OperatingModeEnum
43+
MaximumCheckInBackOff: int
44+
expect_pass: bool
45+
46+
47+
def test_spec_to_attribute_cache(test_icdm: ICDMData) -> Attribute.AsyncReadTransaction.ReadResponse:
48+
resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {})
49+
resp.attributes = {0: {c: {attr.FeatureMap: test_icdm.FeatureMap, attr.IdleModeDuration: test_icdm.IdleModeDuration, attr.ActiveModeDuration: test_icdm.ActiveModeDuration, attr.ActiveModeThreshold: test_icdm.ActiveModeThreshold,
50+
attr.RegisteredClients: test_icdm.RegisteredClients, attr.ICDCounter: test_icdm.ICDCounter,
51+
attr.ClientsSupportedPerFabric: test_icdm.ClientsSupportedPerFabric, attr.UserActiveModeTriggerHint: test_icdm.UserActiveModeTriggerHint,
52+
attr.UserActiveModeTriggerInstruction: test_icdm.UserActiveModeTriggerInstruction, attr.OperatingMode: test_icdm.OperatingMode, attr.MaximumCheckInBackOff: test_icdm.MaximumCheckInBackOff}}}
53+
return resp
54+
55+
56+
def run_tests(pics, label, test_cases, test_name):
57+
test_runner = MockTestRunner(
58+
label, label, test_name, 0, pics)
59+
failures = []
60+
for idx, t in enumerate(test_cases):
61+
ok = test_runner.run_test_with_mock_read(
62+
test_spec_to_attribute_cache(t)) == t.expect_pass
63+
if not ok:
64+
failures.append(f"Measured test case failure: {idx} {t}")
65+
66+
test_runner.Shutdown()
67+
print(
68+
f"Test of tests: run {len(test_cases)}, test response correct: {len(test_cases) - len(failures)} | test response incorrect: {len(failures)}")
69+
for f in failures:
70+
print(f)
71+
72+
return 1 if failures else 0

src/python_testing/test_testing/test_TC_ICDM_2_1.py src/python_testing/test_testing/test_TC_ICDM_2_1_full_pics.py

+2-51
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,9 @@
1616
# limitations under the License.
1717
#
1818

19-
import string
2019
import sys
21-
from dataclasses import dataclass
22-
23-
import chip.clusters as Clusters
24-
from chip.clusters import Attribute
25-
from MockTestRunner import MockTestRunner
26-
27-
c = Clusters.IcdManagement
28-
attr = c.Attributes
29-
uat = c.Bitmaps.UserActiveModeTriggerBitmap
30-
31-
32-
@dataclass
33-
class ICDMData():
34-
FeatureMap: int
35-
IdleModeDuration: int
36-
ActiveModeDuration: int
37-
ActiveModeThreshold: int
38-
RegisteredClients: list
39-
ICDCounter: int
40-
ClientsSupportedPerFabric: int
41-
UserActiveModeTriggerHint: int
42-
UserActiveModeTriggerInstruction: string
43-
OperatingMode: c.Enums.OperatingModeEnum
44-
MaximumCheckInBackOff: int
45-
expect_pass: bool
4620

21+
from common_icdm_data import ICDMData, c, run_tests, uat
4722

4823
long_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut e"
4924
too_long_string = long_string + "1"
@@ -217,35 +192,11 @@ class ICDMData():
217192
]
218193

219194

220-
def test_spec_to_attribute_cache(test_icdm: ICDMData) -> Attribute.AsyncReadTransaction.ReadResponse:
221-
resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {})
222-
resp.attributes = {0: {c: {attr.FeatureMap: test_icdm.FeatureMap, attr.IdleModeDuration: test_icdm.IdleModeDuration, attr.ActiveModeDuration: test_icdm.ActiveModeDuration, attr.ActiveModeThreshold: test_icdm.ActiveModeThreshold,
223-
attr.RegisteredClients: test_icdm.RegisteredClients, attr.ICDCounter: test_icdm.ICDCounter,
224-
attr.ClientsSupportedPerFabric: test_icdm.ClientsSupportedPerFabric, attr.UserActiveModeTriggerHint: test_icdm.UserActiveModeTriggerHint,
225-
attr.UserActiveModeTriggerInstruction: test_icdm.UserActiveModeTriggerInstruction, attr.OperatingMode: test_icdm.OperatingMode, attr.MaximumCheckInBackOff: test_icdm.MaximumCheckInBackOff}}}
226-
return resp
227-
228-
229195
def main():
230196
pics = {"ICDM.S.A0000": True, "ICDM.S.A0001": True, "ICDM.S.A0002": True, "ICDM.S.A0003": True, "ICDM.S.A0004": True,
231197
"ICDM.S.A0005": True, "ICDM.S.A0006": True, "ICDM.S.A0007": True, "ICDM.S.A0008": True, "ICDM.S.A0009": True, }
232198

233-
test_runner = MockTestRunner(
234-
'TC_ICDM_2_1', 'TC_ICDM_2_1', 'test_TC_ICDM_2_1', 0, pics)
235-
failures = []
236-
for idx, t in enumerate(TEST_CASES):
237-
ok = test_runner.run_test_with_mock_read(
238-
test_spec_to_attribute_cache(t)) == t.expect_pass
239-
if not ok:
240-
failures.append(f"Measured test case failure: {idx} {t}")
241-
242-
test_runner.Shutdown()
243-
print(
244-
f"Test of tests: run {len(TEST_CASES)}, test response correct: {len(TEST_CASES) - len(failures)} | test response incorrect: {len(failures)}")
245-
for f in failures:
246-
print(f)
247-
248-
return 1 if failures else 0
199+
return run_tests(pics, 'TC_ICDM_2_1', TEST_CASES, 'test_TC_ICDM_2_1')
249200

250201

251202
if __name__ == "__main__":
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env -S python3 -B
2+
#
3+
# Copyright (c) 2024 Project CHIP Authors
4+
# All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
import sys
20+
21+
from common_icdm_data import ICDMData, c, run_tests
22+
23+
TEST_CASES = [
24+
# Validate that the test script can succeed with the minimum set of PICS
25+
ICDMData(0, 1, 0, 100, [], 0, 2, 0, "",
26+
c.Enums.OperatingModeEnum.kSit, 64800, True),
27+
]
28+
29+
30+
def main():
31+
pics = {"ICDM.S.A0000": True, "ICDM.S.A0001": True, "ICDM.S.A0002": True, "ICDM.S.A0003": False, "ICDM.S.A0004": False,
32+
"ICDM.S.A0005": False, "ICDM.S.A0006": False, "ICDM.S.A0007": False, "ICDM.S.A0008": False, "ICDM.S.A0009": False, }
33+
34+
return run_tests(pics, 'TC_ICDM_2_1', TEST_CASES, 'test_TC_ICDM_2_1')
35+
36+
37+
if __name__ == "__main__":
38+
sys.exit(main())

0 commit comments

Comments
 (0)