Skip to content

Commit e8e86bc

Browse files
committed
TC-DGGEN-3.2: Add
1 parent cb07513 commit e8e86bc

File tree

4 files changed

+122
-3
lines changed

4 files changed

+122
-3
lines changed

src/python_testing/TC_DGGEN_3_2.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Copyright (c) 2023 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 form the Basic Information Cluster from DUT",
27+
"Save the value as `max_paths_per_invoke`"),
28+
TestStep(2, "TH reads FeatureMap attribute form 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, "DMTEST feature must be set if MaxPathsPerInvoke > 1")
44+
45+
46+
if __name__ == "__main__":
47+
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,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 sys
20+
import typing
21+
from dataclasses import dataclass
22+
23+
import chip.clusters as Clusters
24+
from chip.clusters import Attribute
25+
from chip.clusters.Types import NullValue
26+
from MockTestRunner import MockTestRunner
27+
28+
29+
@dataclass
30+
class TestSpec():
31+
max_paths: int
32+
dmtest_feature_map: int
33+
expect_pass: bool
34+
35+
36+
TEST_CASES = [
37+
TestSpec(1, 0, True),
38+
TestSpec(1, 1, True), # I think this is ok...to have the feature on when it's not needed?
39+
TestSpec(2, 0, False),
40+
TestSpec(2, 1, True),
41+
]
42+
43+
44+
def test_spec_to_attribute_cache(test_spec: TestSpec) -> Attribute.AsyncReadTransaction.ReadResponse:
45+
bi = Clusters.BasicInformation
46+
bi_attr = bi.Attributes
47+
gd = Clusters.GeneralDiagnostics
48+
gd_attr = gd.Attributes
49+
resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {})
50+
resp.attributes = {0: {bi: {bi_attr.MaxPathsPerInvoke: test_spec.max_paths}, gd: {gd_attr.FeatureMap: test_spec.dmtest_feature_map}}}
51+
return resp
52+
53+
54+
def main():
55+
test_runner = MockTestRunner('TC_DGGEN_3_2', 'TC_DGGEN_3_2', 'test_TC_DGGEN_3_2', 0)
56+
failures = []
57+
for idx, t in enumerate(TEST_CASES):
58+
ok = test_runner.run_test_with_mock_read(test_spec_to_attribute_cache(t)) == t.expect_pass
59+
if not ok:
60+
failures.append(f"Test case failure: {idx} {t}")
61+
62+
test_runner.Shutdown()
63+
print(
64+
f"Test of tests: run {len(TEST_CASES)}, test response correct: {len(TEST_CASES) - len(failures)} test response incorrect: {len(failures)}")
65+
for f in failures:
66+
print(f)
67+
68+
return 1 if failures else 0
69+
70+
71+
if __name__ == "__main__":
72+
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)