Skip to content

Commit 59557f4

Browse files
TC-DGGEN-3.2: Add (#32995)
* TC-DGGEN-3.2: Add * Apply suggestions from code review * lint * move save out of expected outcome * Restyled by autopep8 * spelling * Apply suggestions from code review --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent f27b978 commit 59557f4

File tree

4 files changed

+122
-3
lines changed

4 files changed

+122
-3
lines changed

src/python_testing/TC_DGGEN_3_2.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Copyright (c) 2024 Project CHIP Authors
3+
# All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
import chip.clusters as Clusters
19+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
20+
from mobly import asserts
21+
22+
23+
class TC_DGGEN_3_2(MatterBaseTest):
24+
def steps_TC_DGGEN_3_2(self):
25+
return [TestStep(0, "Commission DUT (already done)", is_commissioning=True),
26+
TestStep(1, "TH reads the MaxPathsPerInvoke attribute from the Basic Information Cluster from DUT. Save the value as `max_paths_per_invoke",
27+
"Read is successful"),
28+
TestStep(2, "TH reads FeatureMap attribute from the General Diagnostics Cluster from DUT",
29+
"Verify that the FeatureMap value has the DMTEST feature bit (0) set to 1 if `max_path_per_invoke` > 1")
30+
]
31+
32+
@async_test_body
33+
async def test_TC_DGGEN_3_2(self):
34+
# commissioning - already done
35+
self.step(0)
36+
37+
self.step(1)
38+
max_paths_per_invoke = await self.read_single_attribute_check_success(cluster=Clusters.BasicInformation, attribute=Clusters.BasicInformation.Attributes.MaxPathsPerInvoke)
39+
40+
self.step(2)
41+
feature_map = await self.read_single_attribute_check_success(cluster=Clusters.GeneralDiagnostics, attribute=Clusters.GeneralDiagnostics.Attributes.FeatureMap)
42+
if max_paths_per_invoke > 1:
43+
asserts.assert_true(feature_map & Clusters.GeneralDiagnostics.Bitmaps.Feature.kDataModelTest,
44+
"DMTEST feature must be set if MaxPathsPerInvoke > 1")
45+
46+
47+
if __name__ == "__main__":
48+
default_matter_test_main()

src/python_testing/test_testing/MockTestRunner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ async def __call__(self, *args, **kwargs):
3737

3838

3939
class MockTestRunner():
40-
def __init__(self, filename: str, classname: str, test: str):
40+
def __init__(self, filename: str, classname: str, test: str, endpoint: int):
4141
self.config = MatterTestConfig(
42-
tests=[test], endpoint=1, dut_node_ids=[1])
42+
tests=[test], endpoint=endpoint, dut_node_ids=[1])
4343
self.stack = MatterStackState(self.config)
4444
self.default_controller = self.stack.certificate_authorities[0].adminList[0].NewController(
4545
nodeId=self.config.controller_node_id,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
from dataclasses import dataclass
21+
22+
import chip.clusters as Clusters
23+
from chip.clusters import Attribute
24+
from MockTestRunner import MockTestRunner
25+
26+
27+
@dataclass
28+
class TestSpec():
29+
max_paths: int
30+
dmtest_feature_map: int
31+
expect_pass: bool
32+
33+
34+
TEST_CASES = [
35+
TestSpec(1, 0, True),
36+
TestSpec(1, 1, True),
37+
TestSpec(2, 0, False),
38+
TestSpec(2, 1, True),
39+
]
40+
41+
42+
def test_spec_to_attribute_cache(test_spec: TestSpec) -> Attribute.AsyncReadTransaction.ReadResponse:
43+
bi = Clusters.BasicInformation
44+
bi_attr = bi.Attributes
45+
gd = Clusters.GeneralDiagnostics
46+
gd_attr = gd.Attributes
47+
resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {})
48+
resp.attributes = {0: {bi: {bi_attr.MaxPathsPerInvoke: test_spec.max_paths},
49+
gd: {gd_attr.FeatureMap: test_spec.dmtest_feature_map}}}
50+
return resp
51+
52+
53+
def main():
54+
test_runner = MockTestRunner('TC_DGGEN_3_2', 'TC_DGGEN_3_2', 'test_TC_DGGEN_3_2', 0)
55+
failures = []
56+
for idx, t in enumerate(TEST_CASES):
57+
ok = test_runner.run_test_with_mock_read(test_spec_to_attribute_cache(t)) == t.expect_pass
58+
if not ok:
59+
failures.append(f"Test case failure: {idx} {t}")
60+
61+
test_runner.Shutdown()
62+
print(
63+
f"Test of tests: run {len(TEST_CASES)}, test response correct: {len(TEST_CASES) - len(failures)} test response incorrect: {len(failures)}")
64+
for f in failures:
65+
print(f)
66+
67+
return 1 if failures else 0
68+
69+
70+
if __name__ == "__main__":
71+
sys.exit(main())

src/python_testing/test_testing/test_TC_TMP_2_1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_spec_to_attribute_cache(test_spec: TestSpec) -> Attribute.AsyncReadTran
160160

161161

162162
def main():
163-
test_runner = MockTestRunner('TC_TMP_2_1', 'TC_TMP_2_1', 'test_TC_TMP_2_1')
163+
test_runner = MockTestRunner('TC_TMP_2_1', 'TC_TMP_2_1', 'test_TC_TMP_2_1', 1)
164164
failures = []
165165
for idx, t in enumerate(TEST_CASES):
166166
ok = test_runner.run_test_with_mock_read(test_spec_to_attribute_cache(t)) == t.expect_pass

0 commit comments

Comments
 (0)