Skip to content

Commit 167ef52

Browse files
committed
Creating TC_MOD_1_2 python module:
- Creating TC_MOD_1_2 python module based on task by Cecille @ project-chip/matter-test-scripts#483
1 parent 3044eeb commit 167ef52

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

src/python_testing/TC_MOD_1_2.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
# === BEGIN CI TEST ARGUMENTS ===
18+
# test-runner-runs:
19+
# run1:
20+
# app: ${ALL_CLUSTERS_APP}
21+
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
22+
# script-args: >
23+
# --storage-path admin_storage.json
24+
# --commissioning-method on-network
25+
# --discriminator 1234
26+
# --passcode 20202021
27+
# --trace-to json:${TRACE_TEST_JSON}.json
28+
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
29+
# --PICS src/app/tests/suites/certification/ci-pics-values
30+
# --endpoint 1
31+
# factory-reset: true
32+
# quiet: true
33+
# === END CI TEST ARGUMENTS ===
34+
35+
import logging
36+
import random
37+
from time import sleep
38+
39+
import chip.clusters as Clusters
40+
from chip import ChipDeviceCtrl
41+
from chip.ChipDeviceCtrl import CommissioningParameters
42+
from chip.clusters.Types import Nullable
43+
from chip.exceptions import ChipStackError
44+
from chip.native import PyChipError
45+
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
46+
from chip.tlv import uint
47+
from mobly import asserts
48+
49+
class TC_MOD_1_2(MatterBaseTest):
50+
51+
def steps_TC_MOD_1_2(self) -> list[TestStep]:
52+
return [
53+
TestStep(1, "TH reads the SupportedModes attribute from DUT", is_commissioning=True),
54+
TestStep(2, "TH reads the CurrentMode attribute from the DUT", "Verify that the DUT response is an integer that is in the list of modes returned in step 1"),
55+
TestStep(3, "TH reads the OnMode attribute from the DUT", "Verify that the DUT response is an integer that is in the list of modes returned in step 1 ()"),
56+
TestStep(4, "TH reads the StartUpMode attribute from the DUT", "Verify that the DUT response is an integer that is in the list of modes returned in step 1"),
57+
TestStep(5, "TH reads the Description attribute from the DUT", "Verify that the DUT response provides human readable text string that describes the purpose of the mode select server."),
58+
TestStep(6, "TH reads the StandardNamespace attribute from the DUT", "Verify that the DUT response provides a 16 bit enum (null is also acceptable)."),
59+
]
60+
61+
def pics_TC_MOD_1_2(self) -> list[str]:
62+
return ["MOD.S"]
63+
64+
@async_test_body
65+
async def test_TC_MOD_1_2(self):
66+
self.step(1)
67+
# Establishing TH1
68+
self.endpoint = self.get_endpoint()
69+
self.th1 = self.default_controller
70+
MOD_cluster = Clusters.ModeSelect
71+
attributes = MOD_cluster.Attributes
72+
73+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.SupportedModes):
74+
mode_options = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.SupportedModes)
75+
modes = [option.mode for option in mode_options]
76+
77+
self.step(2)
78+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.CurrentMode):
79+
Current_Mode_ID = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.CurrentMode)
80+
asserts.assert_in(Current_Mode_ID, modes, "Current Mode ID should have been in supported modes")
81+
82+
self.step(3)
83+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.OnMode):
84+
# This returns Nullable and not an int
85+
# yaml script shows that this is expected to return a null value as the default value according to spec
86+
On_Mode_ID = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.OnMode)
87+
self.print_step("On Mode ID", f"On Mode ID is of {type(On_Mode_ID)} and its value is {On_Mode_ID}")
88+
if not isinstance(On_Mode_ID, (Clusters.Types.Nullable, int)):
89+
raise ValueError("Invalid return value: must be Nullable or an int")
90+
91+
self.step(4)
92+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.StartUpMode):
93+
Start_Up_Mode_ID = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.StartUpMode)
94+
asserts.assert_in(Start_Up_Mode_ID, modes, "Current Mode ID should have been in supported modes")
95+
96+
self.step(5)
97+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.Description):
98+
Description = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.Description)
99+
assert isinstance(Description, str), "Description was not a human readable string"
100+
101+
self.step(6)
102+
if await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.StandardNamespace):
103+
Standard_Namespace = await self.read_single_attribute(dev_ctrl=self.th1, node_id=self.dut_node_id, endpoint=self.endpoint, attribute=attributes.StandardNamespace)
104+
if not isinstance(Standard_Namespace, (uint, int)):
105+
raise ValueError("Standard Namespace value: must be of type uint or an int")
106+
107+
if __name__ == "__main__":
108+
default_matter_test_main()

0 commit comments

Comments
 (0)