Skip to content

Commit da22449

Browse files
committed
Updates to meet test plan
1 parent 6ae664f commit da22449

File tree

3 files changed

+183
-95
lines changed

3 files changed

+183
-95
lines changed

src/app/tests/suites/certification/Test_TC_MWOCTRL_2_1.yaml

-74
This file was deleted.

src/python_testing/TC_MWOCTRL_2_1.py

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 logging
19+
20+
import chip.clusters as Clusters
21+
from chip.interaction_model import InteractionModelError, Status
22+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
23+
from mobly import asserts
24+
25+
# This test requires several additional command line arguments
26+
# run with
27+
# --endpoint endpoint
28+
29+
30+
class TC_MWOCTRL_2_1(MatterBaseTest):
31+
32+
async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute):
33+
cluster = Clusters.Objects.MicrowaveOvenControl
34+
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
35+
36+
async def set_cook_time_expect_success(self, endpoint, value):
37+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
38+
try:
39+
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
40+
except InteractionModelError as e:
41+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
42+
43+
async def set_bad_cook_time_value_expect_failure(self, endpoint, value):
44+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
45+
try:
46+
await self.send_single_cmd(cmd=Clusters.Objects.MicrowaveOvenControl.Commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
47+
asserts.assert_fail("Expected an exception but received none.")
48+
except InteractionModelError as e:
49+
asserts.assert_equal(e.status, Status.ConstraintError, "Expected a CONSTRAINT_ERROR but got a different response.")
50+
51+
async def read_and_check_cook_time_value(self, endpoint, value):
52+
attributes = Clusters.MicrowaveOvenControl.Attributes
53+
cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
54+
asserts.assert_equal(cooktime, value, "Cooktime value not as expected")
55+
56+
def desc_TC_MWOCTRL_2_1(self) -> str:
57+
return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server"
58+
59+
def steps_TC_MWOCTRL_2_1(self) -> list[TestStep]:
60+
steps = [
61+
TestStep(1, "Commissioning, already done", is_commissioning=True),
62+
TestStep(2, "Read the MaxCookTime attribute and check limits",
63+
"Verify that the DUT response contains an elapsed-s value between 1 and 86400 inclusive. Save value as MaxCookTime."
64+
),
65+
TestStep(3, "Read the CookTime attribute and check limits",
66+
"Verify that the DUT response contains an elapsed-s value between 1 and MaxCookTime inclusive."
67+
),
68+
TestStep(4, "Set the CookTime attribute to 60", "Verify DUT responds w/ status SUCCESS(0x00)."),
69+
TestStep(5, "Read the CookTime attribute and check for 60", "Verify that the DUT response contains the CookTime value 60."),
70+
TestStep(6, "Set the CookTime attribute to 1", "Verify DUT responds w/ status SUCCESS(0x00)"),
71+
TestStep(7, "Read the CookTime attribute and check for 1", "Verify that the DUT response contains the CookTime value 1."),
72+
TestStep(8, "Set the CookTime attribute to MaxCookTime", "Verify DUT responds w/ status SUCCESS(0x00)"),
73+
TestStep(9, "Read the CookTime attribute and check for MaxCookTime", "Verify that the DUT response contains the CookTime value MaxCookTime."),
74+
TestStep(10, "Read the WattRating attribute, if supported", "Verify that the DUT response contains a uint16 value."),
75+
TestStep(11, "Set the CookTime attribute to 0", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
76+
TestStep(12, "Set the CookTime attribute to MaxCookTime+1", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
77+
]
78+
return steps
79+
80+
def pics_TC_MWOCTRL_2_1(self) -> list[str]:
81+
pics = [
82+
"MWOCTRL.S",
83+
]
84+
return pics
85+
86+
@async_test_body
87+
async def test_TC_MWOCTRL_2_1(self):
88+
89+
endpoint = self.user_params.get("endpoint", 1)
90+
91+
self.step(1)
92+
attributes = Clusters.MicrowaveOvenControl.Attributes
93+
features = Clusters.MicrowaveOvenControl.Bitmaps.Feature
94+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
95+
96+
self.step(2)
97+
maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime)
98+
asserts.assert_greater_equal(maxCookTime, 1, "maxCookTime is less than 1")
99+
asserts.assert_less_equal(maxCookTime, 86400, "maxCookTime is greater than 86400")
100+
101+
self.step(3)
102+
cookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
103+
asserts.assert_greater_equal(cookTime, 1, "cookTime is less than 1")
104+
asserts.assert_less_equal(cookTime, maxCookTime, "cookTime is greater than maxCookTime")
105+
106+
self.step(4)
107+
newCookTime = 60
108+
await self.set_cook_time_expect_success(endpoint, newCookTime)
109+
110+
self.step(5)
111+
await self.read_and_check_cook_time_value(endpoint, newCookTime)
112+
113+
self.step(6)
114+
await self.set_cook_time_expect_success(endpoint, 1)
115+
116+
self.step(7)
117+
await self.read_and_check_cook_time_value(endpoint, 1)
118+
119+
self.step(8)
120+
await self.set_cook_time_expect_success(endpoint, maxCookTime)
121+
122+
self.step(9)
123+
await self.read_and_check_cook_time_value(endpoint, maxCookTime)
124+
125+
self.step(10)
126+
if self.pics_guard(self.check_pics("MWOCTRL.S.F01")):
127+
await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.WattRating)
128+
129+
self.step(11)
130+
await self.set_bad_cook_time_value_expect_failure(endpoint, 0)
131+
132+
self.step(12)
133+
await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1)
134+
135+
136+
if __name__ == "__main__":
137+
default_matter_test_main()

src/python_testing/TC_MWOCTRL_2_2.py

+46-21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute):
3333
cluster = Clusters.Objects.MicrowaveOvenControl
3434
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
3535

36+
async def set_power_setting_expect_success(self, endpoint, value):
37+
try:
38+
await self.send_single_cmd(cmd=Clusters.Objects.MicrowaveOvenControl.Commands.SetCookingParameters(powerSetting=value), endpoint=endpoint)
39+
except InteractionModelError as e:
40+
asserts.assert_equal(e.status, Status.Success, "Error while trying to set the power setting.")
41+
42+
async def set_power_setting_expect_failure(self, endpoint, value):
43+
try:
44+
await self.send_single_cmd(cmd=Clusters.Objects.MicrowaveOvenControl.Commands.SetCookingParameters(powerSetting=value), endpoint=endpoint)
45+
asserts.assert_fail("Expected an exception but received none.")
46+
except InteractionModelError as e:
47+
asserts.assert_equal(e.status, Status.ConstraintError, "Expected ConstraintError but received a different response: %x", e.status)
48+
49+
async def read_and_check_power_setting_value(self, endpoint, value):
50+
powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=Clusters.MicrowaveOvenControl.Attributes.PowerSetting)
51+
asserts.assert_equal(powerValue, value, "PowerSetting was not correctly set")
52+
3653
def desc_TC_MWOCTRL_2_2(self) -> str:
3754
return "[TC-MWOCTRL-2.2] Secondary functionality with DUT as Server"
3855

@@ -49,8 +66,12 @@ def steps_TC_MWOCTRL_2_2(self) -> list[TestStep]:
4966
TestStep(9, "Send the SetCookingParameters command"),
5067
TestStep(10, "Read and verify the PowerSetting attribute"),
5168
TestStep(11, "Set the PowerSetting attribute to the minimum value"),
52-
TestStep(12, "Set the PowerSetting attribute to the maximum value"),
53-
TestStep(13, "Cause constraint error response"),
69+
TestStep(12, "Read and verify the PowerSetting attribute"),
70+
TestStep(13, "Set the PowerSetting attribute to the maximum value"),
71+
TestStep(14, "Read and verify the PowerSetting attribute"),
72+
TestStep(15, "Set PowerSetting to an invalid value"),
73+
TestStep(16, "If PowerStep=1, exit test case."),
74+
TestStep(17, "Set PowerSetting to a value that is not an integer multiple of PowerStep"),
5475
]
5576
return steps
5677

@@ -116,34 +137,38 @@ async def test_TC_MWOCTRL_2_2(self):
116137

117138
self.step(9)
118139
newPowerValue = (powerValue-minPowerValue) % (maxPowerValue-minPowerValue)+powerStepValue+minPowerValue
119-
try:
120-
await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint)
121-
except InteractionModelError as e:
122-
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
140+
await self.set_power_setting_expect_success(endpoint, newPowerValue)
123141

124142
self.step(10)
125-
powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting)
126-
asserts.assert_true(powerValue == newPowerValue, "PowerSetting was not correctly set")
143+
await self.read_and_check_power_setting_value(endpoint, newPowerValue)
127144

128145
self.step(11)
129-
try:
130-
await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=minPowerValue), endpoint=endpoint)
131-
except InteractionModelError as e:
132-
asserts.assert_equal(e.status, Status.Success, "Unable to set power value to minimum")
146+
await self.set_power_setting_expect_success(endpoint, minPowerValue)
133147

134148
self.step(12)
135-
try:
136-
await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=maxPowerValue), endpoint=endpoint)
137-
except InteractionModelError as e:
138-
asserts.assert_equal(e.status, Status.Success, "Unable to set power value to maximum")
149+
await self.read_and_check_power_setting_value(endpoint, minPowerValue)
139150

140151
self.step(13)
152+
await self.set_power_setting_expect_success(endpoint, maxPowerValue)
153+
154+
self.step(14)
155+
await self.read_and_check_power_setting_value(endpoint, maxPowerValue)
156+
157+
self.step(15)
141158
newPowerValue = maxPowerValue+1
142-
try:
143-
await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint)
144-
asserts.assert_fail("Expected an exception but received none.")
145-
except InteractionModelError as e:
146-
asserts.assert_equal(e.status, Status.ConstraintError, "Expected ConstraintError but received a different response.")
159+
await self.set_power_setting_expect_failure(endpoint, newPowerValue)
160+
161+
self.step(16)
162+
if powerStepValue == 1:
163+
self.skip_step(17)
164+
return
165+
166+
self.step(17)
167+
newPowerValue = minPowerValue + powerStepValue / 2
168+
logging.info("-------> MinPower = %d", minPowerValue)
169+
logging.info("-------> PowerStep = %d", powerStepValue)
170+
logging.info("-------> newPowerValue = %d", newPowerValue)
171+
await self.set_power_setting_expect_failure(endpoint, newPowerValue)
147172

148173

149174
if __name__ == "__main__":

0 commit comments

Comments
 (0)