Skip to content

Commit bde91fb

Browse files
committed
Update tests per TP changes.
1 parent ab2907b commit bde91fb

File tree

3 files changed

+178
-3
lines changed

3 files changed

+178
-3
lines changed

src/python_testing/TC_MWOCTRL_2_1.py

+46-1
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,30 @@ async def set_cook_time_expect_success(self, endpoint, value):
3838
except InteractionModelError as e:
3939
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
4040

41-
async def set_bad_cook_time_value_expect_failure(self, endpoint, value):
41+
async def set_bad_cook_time_value_expect_failure(self, endpoint, value, expectedError=Status.ConstraintError):
4242
commands = Clusters.Objects.MicrowaveOvenControl.Commands
4343
try:
4444
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
4545
asserts.assert_fail("Expected an exception but received none.")
46+
except InteractionModelError as e:
47+
asserts.assert_equal(e.status, expectedError, "Unexpected error received.")
48+
49+
async def set_bad_cook_mode_value_expect_failure(self, endpoint, value):
50+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
51+
try:
52+
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookMode=value), endpoint=endpoint)
53+
asserts.assert_fail("Expected an exception but received none.")
4654
except InteractionModelError as e:
4755
asserts.assert_equal(e.status, Status.ConstraintError, "Expected a CONSTRAINT_ERROR but got a different response.")
4856

57+
async def send_bad_command_expect_failure(self, endpoint):
58+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
59+
try:
60+
await self.send_single_cmd(cmd=commands.SetCookingParameters(startAfterSetting=1), endpoint=endpoint)
61+
asserts.assert_fail("Expected an exception but received none.")
62+
except InteractionModelError as e:
63+
asserts.assert_equal(e.status, Status.InvalidCmmand, "Expected a INVALID_COMMAND but got a different response.")
64+
4965
async def read_and_check_cook_time_value(self, endpoint, value):
5066
attributes = Clusters.MicrowaveOvenControl.Attributes
5167
cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
@@ -75,6 +91,13 @@ def steps_TC_MWOCTRL_2_1(self) -> list[TestStep]:
7591
TestStep(10, "Read the WattRating attribute, if supported", "Verify that the DUT response contains a uint16 value."),
7692
TestStep(11, "Set the CookTime attribute to 0", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
7793
TestStep(12, "Set the CookTime attribute to MaxCookTime+1", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
94+
TestStep(13, "Set the CookMode attribute to 250", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
95+
96+
TestStep(14, "Manually set DUT into a state where it will respond with INVALID_IN_STATE", ""),
97+
TestStep(15, "Set the CookTime attribute to 60", "Verify DUT responds w/ INVALID_IN_STATE(0xCB)"),
98+
99+
TestStep(16, "Manually set DUT into a state where it will respond with INVALID_COMMAND", ""),
100+
TestStep(17, "Send the SetCookingParameters command with StartAfterSetting to True", "Verify DUT responds w/ INVALID_COMMAND(0x85)"),
78101
]
79102
return steps
80103

@@ -131,6 +154,28 @@ async def test_TC_MWOCTRL_2_1(self):
131154
self.step(12)
132155
await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1)
133156

157+
self.step(13)
158+
await self.set_bad_cook_mode_value_expect_failure(endpoint, 250)
159+
160+
if self.check_pics("MWOCTRL.S.M.ManualSetInvalidInState"):
161+
self.step(14)
162+
input("Press Enter when done.\n")
163+
164+
self.step(15)
165+
await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1, Status.InvalidInState)
166+
else:
167+
self.skip_step(14)
168+
self.skip_step(15)
169+
170+
if self.check_pics("MWOCTRL.S.M.ManualSetInvalidCommand"):
171+
self.step(16)
172+
input("Press Enter when done.\n")
173+
174+
self.step(17)
175+
await self.send_bad_command_expect_failure(endpoint)
176+
else:
177+
self.skip_step(16)
178+
self.skip_step(17)
134179

135180
if __name__ == "__main__":
136181
default_matter_test_main()

src/python_testing/TC_MWOCTRL_2_4.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def steps_TC_MWOCTRL_2_4(self) -> list[TestStep]:
4141
TestStep(1, "Commissioning, already done", is_commissioning=True),
4242
TestStep(2, "Read the SupportedWatts attribute"),
4343
TestStep(3, "Read the SelectedWattIndex attribute"),
44-
TestStep(4, "Send the SetCookingParameters command"),
44+
TestStep(4, "Send the SetCookingParameters command", "Verify DUT responds w/ status SUCCESS(0x00)."),
4545
TestStep(5, "Read and verify the SelectedWattIndex attribute"),
46+
TestStep(6, "Try to set SelectedWattIndex to an invalid value.", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
4647
]
4748
return steps
4849

@@ -88,12 +89,18 @@ async def test_TC_MWOCTRL_2_4(self):
8889
await self.send_single_cmd(cmd=commands.SetCookingParameters(wattSettingIndex=newWattIndex), endpoint=endpoint)
8990
except InteractionModelError as e:
9091
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
91-
pass
9292

9393
self.step(5)
9494
selectedWattIndex = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.SelectedWattIndex)
9595
asserts.assert_true(selectedWattIndex == newWattIndex, "SelectedWattIndex was not correctly set")
9696

97+
self.step(6)
98+
newWattIndex = len(supportedWattsList)
99+
try:
100+
await self.send_single_cmd(cmd=commands.SetCookingParameters(wattSettingIndex=newWattIndex), endpoint=endpoint)
101+
except InteractionModelError as e:
102+
asserts.assert_equal(e.status, Status.ConstraintError, "Unexpected error returned")
103+
97104

98105
if __name__ == "__main__":
99106
default_matter_test_main()

src/python_testing/TC_MWOCTRL_2_5.py

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 chip.interaction_model import InteractionModelError, Status
20+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
21+
from mobly import asserts
22+
import logging
23+
24+
# This test requires several additional command line arguments
25+
# run with
26+
# --endpoint endpoint
27+
28+
29+
class TC_MWOCTRL_2_5(MatterBaseTest):
30+
31+
async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute):
32+
cluster = Clusters.Objects.MicrowaveOvenControl
33+
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
34+
35+
async def set_cook_time_expect_success(self, endpoint, value):
36+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
37+
try:
38+
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
39+
except InteractionModelError as e:
40+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
41+
42+
async def send_add_more_time_command_expect_response(self, endpoint, value, expectedError = Status.Success):
43+
commands = Clusters.Objects.MicrowaveOvenControl.Commands
44+
try:
45+
await self.send_single_cmd(cmd=commands.AddMoreTime(timeToAdd=value), endpoint=endpoint)
46+
asserts.assert_equal(Status.Success, expectedError, "No error occured but unexpected response received.")
47+
except InteractionModelError as e:
48+
asserts.assert_equal(e.status, expectedError, "Unexpected error response received.")
49+
50+
async def read_and_check_cook_time_value(self, endpoint, value):
51+
attributes = Clusters.MicrowaveOvenControl.Attributes
52+
cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
53+
asserts.assert_equal(cooktime, value, "Cooktime value not as expected")
54+
55+
def desc_TC_MWOCTRL_2_5(self) -> str:
56+
return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server"
57+
58+
def steps_TC_MWOCTRL_2_5(self) -> list[TestStep]:
59+
steps = [
60+
TestStep(1, "Commissioning, already done", is_commissioning=True),
61+
TestStep(2, "Set the CookTime attribute to 60",
62+
"Verify DUT responds w/ status SUCCESS(0x00)."
63+
),
64+
TestStep(3, "Send the AddMoreTime command with a value of 30.",
65+
"Verify DUT responds w/ status SUCCESS(0x00)."
66+
),
67+
TestStep(4, "Read the CookTime attribute and verify it is 90",
68+
"Verify DUT responds w/ a value of 90."),
69+
TestStep(5, "Read the MaxCookTime attribute",
70+
"Save the response as MaxCookTime"),
71+
TestStep(6, "Send the AddMoreTime command with a value of MaxCookTime+1.",
72+
"Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)."
73+
),
74+
TestStep(7, "Manually set the device into a state where it will respond with INVALID_IN_STATE for the AddMoreTime command."),
75+
TestStep(8, "Send the AddMoreTime command with a value of 30.",
76+
"Verify DUT responds w/ status INVALID_IN_STATE(0xCB)."
77+
),
78+
]
79+
return steps
80+
81+
def pics_TC_MWOCTRL_2_5(self) -> list[str]:
82+
pics = [
83+
"MWOCTRL.S",
84+
"MWOCTRL.SC.ADD_MORE_TIME"
85+
]
86+
return pics
87+
88+
@async_test_body
89+
async def test_TC_MWOCTRL_2_5(self):
90+
91+
endpoint = self.user_params.get("endpoint", 1)
92+
93+
self.step(1)
94+
attributes = Clusters.MicrowaveOvenControl.Attributes
95+
96+
self.step(2)
97+
await self.set_cook_time_expect_success(endpoint, 60)
98+
99+
self.step(3)
100+
await self.send_add_more_time_command_expect_response(endpoint, 30)
101+
102+
self.step(4)
103+
await self.read_and_check_cook_time_value(endpoint, 90)
104+
105+
self.step(5)
106+
maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime)
107+
108+
self.step(6)
109+
await self.send_add_more_time_command_expect_response(endpoint, maxCookTime+1, Status.ConstraintError)
110+
111+
if self.check_pics("MWOCTRL.S.M.ManualInvalidAddTime"):
112+
self.step(7)
113+
input("Press Enter when done.\n")
114+
115+
self.step(8)
116+
await self.send_add_more_time_command_expect_response(endpoint, 30, Status.InvalidInState)
117+
else:
118+
self.skip_step(7)
119+
self.skip_step(8)
120+
121+
122+
if __name__ == "__main__":
123+
default_matter_test_main()

0 commit comments

Comments
 (0)