Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWOCTRL] Add error checks MWOCTRL test scripts #33990

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -551,6 +551,7 @@ jobs:
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-microwave-oven-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-microwave-oven-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_MWOCTRL_2_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-microwave-oven-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-microwave-oven-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_MWOCTRL_2_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-microwave-oven-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-microwave-oven-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_MWOCTRL_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-microwave-oven-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-microwave-oven-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_MWOCTRL_2_5.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-microwave-oven-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-microwave-oven-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_MWOM_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-rvc-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-rvc-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_RVCRUNM_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-rvc-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-rvc-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace_file json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_RVCRUNM_2_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values --endpoint 1 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto --int-arg PIXIT.RVCRUNM.MODE_CHANGE_OK:0 PIXIT.RVCRUNM.MODE_CHANGE_FAIL:2"'
55 changes: 0 additions & 55 deletions src/app/tests/suites/certification/Test_TC_MWOCTRL_2_5.yaml

This file was deleted.

49 changes: 48 additions & 1 deletion src/python_testing/TC_MWOCTRL_2_1.py
Original file line number Diff line number Diff line change
@@ -38,14 +38,30 @@ async def set_cook_time_expect_success(self, endpoint, value):
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")

async def set_bad_cook_time_value_expect_failure(self, endpoint, value):
async def set_bad_cook_time_value_expect_failure(self, endpoint, value, expectedError=Status.ConstraintError):
commands = Clusters.Objects.MicrowaveOvenControl.Commands
try:
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
asserts.assert_fail("Expected an exception but received none.")
except InteractionModelError as e:
asserts.assert_equal(e.status, expectedError, "Unexpected error received.")

async def set_bad_cook_mode_value_expect_failure(self, endpoint, value):
commands = Clusters.Objects.MicrowaveOvenControl.Commands
try:
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookMode=value), endpoint=endpoint)
asserts.assert_fail("Expected an exception but received none.")
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.ConstraintError, "Expected a CONSTRAINT_ERROR but got a different response.")

async def send_bad_command_expect_failure(self, endpoint):
commands = Clusters.Objects.MicrowaveOvenControl.Commands
try:
await self.send_single_cmd(cmd=commands.SetCookingParameters(startAfterSetting=1), endpoint=endpoint)
asserts.assert_fail("Expected an exception but received none.")
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.InvalidCmmand, "Expected a INVALID_COMMAND but got a different response.")

async def read_and_check_cook_time_value(self, endpoint, value):
attributes = Clusters.MicrowaveOvenControl.Attributes
cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
@@ -75,6 +91,14 @@ def steps_TC_MWOCTRL_2_1(self) -> list[TestStep]:
TestStep(10, "Read the WattRating attribute, if supported", "Verify that the DUT response contains a uint16 value."),
TestStep(11, "Set the CookTime attribute to 0", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
TestStep(12, "Set the CookTime attribute to MaxCookTime+1", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
TestStep(13, "Set the CookMode attribute to 250", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),

TestStep(14, "Manually set DUT into a state where it will respond with INVALID_IN_STATE", ""),
TestStep(15, "Set the CookTime attribute to 60", "Verify DUT responds w/ INVALID_IN_STATE(0xCB)"),

TestStep(16, "Manually set DUT into a state where it will respond with INVALID_COMMAND", ""),
TestStep(17, "Send the SetCookingParameters command with StartAfterSetting to True",
"Verify DUT responds w/ INVALID_COMMAND(0x85)"),
]
return steps

@@ -131,6 +155,29 @@ async def test_TC_MWOCTRL_2_1(self):
self.step(12)
await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1)

self.step(13)
await self.set_bad_cook_mode_value_expect_failure(endpoint, 250)

if self.check_pics("MWOCTRL.S.M.ManualSetInvalidInState"):
self.step(14)
input("Press Enter when done.\n")

self.step(15)
await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1, Status.InvalidInState)
else:
self.skip_step(14)
self.skip_step(15)

if self.check_pics("MWOCTRL.S.M.ManualSetInvalidCommand"):
self.step(16)
input("Press Enter when done.\n")

self.step(17)
await self.send_bad_command_expect_failure(endpoint)
else:
self.skip_step(16)
self.skip_step(17)


if __name__ == "__main__":
default_matter_test_main()
12 changes: 10 additions & 2 deletions src/python_testing/TC_MWOCTRL_2_4.py
Original file line number Diff line number Diff line change
@@ -41,8 +41,10 @@ def steps_TC_MWOCTRL_2_4(self) -> list[TestStep]:
TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Read the SupportedWatts attribute"),
TestStep(3, "Read the SelectedWattIndex attribute"),
TestStep(4, "Send the SetCookingParameters command"),
TestStep(4, "Send the SetCookingParameters command", "Verify DUT responds w/ status SUCCESS(0x00)."),
TestStep(5, "Read and verify the SelectedWattIndex attribute"),
TestStep(6, "Try to set SelectedWattIndex to an invalid value.",
"Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"),
]
return steps

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

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

self.step(6)
newWattIndex = len(supportedWattsList)
try:
await self.send_single_cmd(cmd=commands.SetCookingParameters(wattSettingIndex=newWattIndex), endpoint=endpoint)
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.ConstraintError, "Unexpected error returned")


if __name__ == "__main__":
default_matter_test_main()
122 changes: 122 additions & 0 deletions src/python_testing/TC_MWOCTRL_2_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import chip.clusters as Clusters
from chip.interaction_model import InteractionModelError, Status
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
from mobly import asserts

# This test requires several additional command line arguments
# run with
# --endpoint endpoint


class TC_MWOCTRL_2_5(MatterBaseTest):

async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.MicrowaveOvenControl
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)

async def set_cook_time_expect_success(self, endpoint, value):
commands = Clusters.Objects.MicrowaveOvenControl.Commands
try:
await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint)
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")

async def send_add_more_time_command_expect_response(self, endpoint, value, expectedError=Status.Success):
commands = Clusters.Objects.MicrowaveOvenControl.Commands
try:
await self.send_single_cmd(cmd=commands.AddMoreTime(timeToAdd=value), endpoint=endpoint)
asserts.assert_equal(Status.Success, expectedError, "No error occured but unexpected response received.")
except InteractionModelError as e:
asserts.assert_equal(e.status, expectedError, "Unexpected error response received.")

async def read_and_check_cook_time_value(self, endpoint, value):
attributes = Clusters.MicrowaveOvenControl.Attributes
cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime)
asserts.assert_equal(cooktime, value, "Cooktime value not as expected")

def desc_TC_MWOCTRL_2_5(self) -> str:
return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server"

def steps_TC_MWOCTRL_2_5(self) -> list[TestStep]:
steps = [
TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Set the CookTime attribute to 60",
"Verify DUT responds w/ status SUCCESS(0x00)."
),
TestStep(3, "Send the AddMoreTime command with a value of 30.",
"Verify DUT responds w/ status SUCCESS(0x00)."
),
TestStep(4, "Read the CookTime attribute and verify it is 90",
"Verify DUT responds w/ a value of 90."),
TestStep(5, "Read the MaxCookTime attribute",
"Save the response as MaxCookTime"),
TestStep(6, "Send the AddMoreTime command with a value of MaxCookTime+1.",
"Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)."
),
TestStep(7, "Manually set the device into a state where it will respond with INVALID_IN_STATE for the AddMoreTime command."),
TestStep(8, "Send the AddMoreTime command with a value of 30.",
"Verify DUT responds w/ status INVALID_IN_STATE(0xCB)."
),
]
return steps

def pics_TC_MWOCTRL_2_5(self) -> list[str]:
pics = [
"MWOCTRL.S",
"MWOCTRL.SC.ADD_MORE_TIME"
]
return pics

@async_test_body
async def test_TC_MWOCTRL_2_5(self):

endpoint = self.user_params.get("endpoint", 1)

self.step(1)
attributes = Clusters.MicrowaveOvenControl.Attributes

self.step(2)
await self.set_cook_time_expect_success(endpoint, 60)

self.step(3)
await self.send_add_more_time_command_expect_response(endpoint, 30)

self.step(4)
await self.read_and_check_cook_time_value(endpoint, 90)

self.step(5)
maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime)

self.step(6)
await self.send_add_more_time_command_expect_response(endpoint, maxCookTime+1, Status.ConstraintError)

if self.check_pics("MWOCTRL.S.M.ManualInvalidAddTime"):
self.step(7)
input("Press Enter when done.\n")

self.step(8)
await self.send_add_more_time_command_expect_response(endpoint, 30, Status.InvalidInState)
else:
self.skip_step(7)
self.skip_step(8)


if __name__ == "__main__":
default_matter_test_main()
Loading