diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dccd846affddc1..b23e0fc1ba18ca 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -547,9 +547,9 @@ jobs: scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_OVENOPSTATE_2_3.py" --script-args "--endpoint 1 --int-arg PIXIT.WAITTIME.COUNTDOWN:5 --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-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_OVENOPSTATE_2_4.py" --script-args "--endpoint 1 --int-arg PIXIT.OVENOPSTATE.ErrorEventGen:1 --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-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --quiet --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_OVENOPSTATE_2_5.py" --script-args "--endpoint 1 --int-arg PIXIT.WAITTIME.REBOOT:5 --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 --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_3.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-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 --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_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_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"' diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp index 4a736cecd01ac6..d47742570ed2e0 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp @@ -296,7 +296,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: ChipLogError(Zcl, "Microwave Oven Control: Failed to set PowerSetting, PowerSetting value is out of range")); VerifyOrExit( - reqPowerSettingNum % powerStepNum == 0, status = Status::InvalidCommand; ChipLogError( + (reqPowerSettingNum - minPowerNum) % powerStepNum == 0, status = Status::ConstraintError; ChipLogError( Zcl, "Microwave Oven Control: Failed to set PowerSetting, PowerSetting value must be multiple of PowerStep number")); diff --git a/src/app/tests/suites/certification/Test_TC_MWOCTRL_2_1.yaml b/src/app/tests/suites/certification/Test_TC_MWOCTRL_2_1.yaml deleted file mode 100644 index cd3f26b7e59bb5..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_MWOCTRL_2_1.yaml +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Project CHIP Authors -# -# 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. - -name: 263.1.1. [TC-MWOCTRL-2.1] Primary functionality with DUT as Server - -PICS: - - MWOCTRL.S - -config: - nodeId: 0x12344321 - cluster: "Microwave Oven Control" - endpoint: 1 - -tests: - - label: "Step 1: Wait for the commissioned device to be retrieved" - cluster: "DelayCommands" - command: "WaitForCommissionee" - arguments: - values: - - name: "nodeId" - value: nodeId - - - label: "Step 2: Read the MaxCookTime attribute" - command: "readAttribute" - attribute: "MaxCookTime" - response: - saveAs: MaxCookTimeValue - constraints: - type: elapsed_s - minValue: 1 - maxValue: 86400 - - - label: "Step 3: Read the CookTime attribute" - command: "readAttribute" - attribute: "CookTime" - response: - constraints: - type: elapsed_s - minValue: 1 - maxValue: MaxCookTimeValue - - - label: "Step 4: Send the SetCookingParameters command" - command: "SetCookingParameters" - arguments: - values: - - name: CookTime - value: 60 - - - label: "Step 5: Read the CookTime attribute" - command: "readAttribute" - attribute: "CookTime" - response: - value: 60 - constraints: - type: elapsed_s - - - label: "Step 6: Read the WattRating attribute" - PICS: MWOCTRL.S.A0008 - command: "readAttribute" - attribute: "WattRating" - response: - constraints: - type: int16u diff --git a/src/python_testing/TC_MWOCTRL_2_1.py b/src/python_testing/TC_MWOCTRL_2_1.py new file mode 100644 index 00000000000000..658bdb3ae8e431 --- /dev/null +++ b/src/python_testing/TC_MWOCTRL_2_1.py @@ -0,0 +1,136 @@ +# +# 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_1(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 set_bad_cook_time_value_expect_failure(self, endpoint, value): + 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, Status.ConstraintError, "Expected a CONSTRAINT_ERROR 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) + asserts.assert_equal(cooktime, value, "Cooktime value not as expected") + + def desc_TC_MWOCTRL_2_1(self) -> str: + return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server" + + def steps_TC_MWOCTRL_2_1(self) -> list[TestStep]: + steps = [ + TestStep(1, "Commissioning, already done", is_commissioning=True), + TestStep(2, "Read the MaxCookTime attribute and check limits", + "Verify that the DUT response contains an elapsed-s value between 1 and 86400 inclusive. Save value as MaxCookTime." + ), + TestStep(3, "Read the CookTime attribute and check limits", + "Verify that the DUT response contains an elapsed-s value between 1 and MaxCookTime inclusive." + ), + TestStep(4, "Set the CookTime attribute to 60", "Verify DUT responds w/ status SUCCESS(0x00)."), + TestStep(5, "Read the CookTime attribute and check for 60", + "Verify that the DUT response contains the CookTime value 60."), + TestStep(6, "Set the CookTime attribute to 1", "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep(7, "Read the CookTime attribute and check for 1", + "Verify that the DUT response contains the CookTime value 1."), + TestStep(8, "Set the CookTime attribute to MaxCookTime", "Verify DUT responds w/ status SUCCESS(0x00)"), + TestStep(9, "Read the CookTime attribute and check for MaxCookTime", + "Verify that the DUT response contains the CookTime value MaxCookTime."), + 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)"), + ] + return steps + + def pics_TC_MWOCTRL_2_1(self) -> list[str]: + pics = [ + "MWOCTRL.S", + ] + return pics + + @async_test_body + async def test_TC_MWOCTRL_2_1(self): + + endpoint = self.user_params.get("endpoint", 1) + + self.step(1) + attributes = Clusters.MicrowaveOvenControl.Attributes + + self.step(2) + maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime) + asserts.assert_greater_equal(maxCookTime, 1, "maxCookTime is less than 1") + asserts.assert_less_equal(maxCookTime, 86400, "maxCookTime is greater than 86400") + + self.step(3) + cookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime) + asserts.assert_greater_equal(cookTime, 1, "cookTime is less than 1") + asserts.assert_less_equal(cookTime, maxCookTime, "cookTime is greater than maxCookTime") + + self.step(4) + newCookTime = 60 + await self.set_cook_time_expect_success(endpoint, newCookTime) + + self.step(5) + await self.read_and_check_cook_time_value(endpoint, newCookTime) + + self.step(6) + await self.set_cook_time_expect_success(endpoint, 1) + + self.step(7) + await self.read_and_check_cook_time_value(endpoint, 1) + + self.step(8) + await self.set_cook_time_expect_success(endpoint, maxCookTime) + + self.step(9) + await self.read_and_check_cook_time_value(endpoint, maxCookTime) + + self.step(10) + if self.pics_guard(self.check_pics("MWOCTRL.S.F01")): + await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.WattRating) + + self.step(11) + await self.set_bad_cook_time_value_expect_failure(endpoint, 0) + + self.step(12) + await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1) + + +if __name__ == "__main__": + default_matter_test_main() diff --git a/src/python_testing/TC_MWOCTRL_2_2.py b/src/python_testing/TC_MWOCTRL_2_2.py index a5484c586067c6..ae496f6a669387 100644 --- a/src/python_testing/TC_MWOCTRL_2_2.py +++ b/src/python_testing/TC_MWOCTRL_2_2.py @@ -33,22 +33,53 @@ 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_power_setting_expect_success(self, endpoint, value): + try: + await self.send_single_cmd(cmd=Clusters.Objects.MicrowaveOvenControl.Commands.SetCookingParameters(powerSetting=value), endpoint=endpoint) + except InteractionModelError as e: + asserts.assert_equal(e.status, Status.Success, "Error while trying to set the power setting.") + + async def set_power_setting_expect_failure(self, endpoint, value): + try: + await self.send_single_cmd(cmd=Clusters.Objects.MicrowaveOvenControl.Commands.SetCookingParameters(powerSetting=value), endpoint=endpoint) + asserts.assert_fail("Expected an exception but received none.") + except InteractionModelError as e: + asserts.assert_equal(e.status, Status.ConstraintError, + "Expected ConstraintError but received a different response") + + async def read_and_check_power_setting_value(self, endpoint, value): + powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=Clusters.MicrowaveOvenControl.Attributes.PowerSetting) + asserts.assert_equal(powerValue, value, "PowerSetting was not correctly set") + def desc_TC_MWOCTRL_2_2(self) -> str: return "[TC-MWOCTRL-2.2] Secondary functionality with DUT as Server" def steps_TC_MWOCTRL_2_2(self) -> list[TestStep]: steps = [ TestStep(1, "Commissioning, already done", is_commissioning=True), - TestStep(2, "Read the PowerSetting attribute"), - TestStep(3, "Send the SetCookingParameters command"), - TestStep(4, "Read and verify the PowerSetting attribute"), - TestStep(5, "Cause constraint error response"), + TestStep(2, "Set MinPowerValue variable"), + TestStep(3, "Read the MinPower attribute"), + TestStep(4, "Set the MaxPowerValue variable"), + TestStep(5, "Read the MaxPower attribute"), + TestStep(6, "Set the PowerStepValue variable"), + TestStep(7, "Read the PowerStep attribute"), + TestStep(8, "Read the PowerSetting attribute"), + TestStep(9, "Send the SetCookingParameters command"), + TestStep(10, "Read and verify the PowerSetting attribute"), + TestStep(11, "Set the PowerSetting attribute to the minimum value"), + TestStep(12, "Read and verify the PowerSetting attribute"), + TestStep(13, "Set the PowerSetting attribute to the maximum value"), + TestStep(14, "Read and verify the PowerSetting attribute"), + TestStep(15, "Set PowerSetting to an invalid value"), + TestStep(16, "If PowerStep=1, exit test case."), + TestStep(17, "Set PowerSetting to a value that is not an integer multiple of PowerStep"), ] return steps def pics_TC_MWOCTRL_2_2(self) -> list[str]: pics = [ "MWOCTRL.S", + "MWOCTRL.S.F00", ] return pics @@ -61,42 +92,93 @@ async def test_TC_MWOCTRL_2_2(self): attributes = Clusters.MicrowaveOvenControl.Attributes feature_map = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) features = Clusters.MicrowaveOvenControl.Bitmaps.Feature - commands = Clusters.Objects.MicrowaveOvenControl.Commands + is_pwrlmits_feature_supported = feature_map & features.kPowerNumberLimits + is_pwrnum_feature_supported = feature_map & features.kPowerAsNumber - feature_map = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) - - only_pwrnum_supported = feature_map == features.kPowerAsNumber - - if not only_pwrnum_supported: - logging.info("More than PWRNUM is supported so skipping remaining test steps") + if not is_pwrnum_feature_supported: + logging.info("PWRNUM is not supported so skipping remaining test steps") self.skip_all_remaining_steps(2) return - logging.info("Only the PWRNUM feature is supported so continuing with remaining test steps") + logging.info("The PWRNUM feature is supported so continuing with remaining test steps") + self.step(2) - powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting) - asserts.assert_greater_equal(powerValue, 10, "PowerSetting is less than 10") - asserts.assert_less_equal(powerValue, 100, "PowerSetting is greater than 100") - asserts.assert_true(powerValue % 10 == 0, "PowerSetting is not a multiple of 10") + minPowerValue = 10 self.step(3) - newPowerValue = (powerValue+10) % 100 - try: - await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint) - except InteractionModelError as e: - asserts.assert_equal(e.status, Status.Success, "Unexpected error returned") + if is_pwrlmits_feature_supported: + minPowerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MinPower) + asserts.assert_greater_equal(minPowerValue, 1, "MinPower is less than 1") + asserts.assert_less_equal(minPowerValue, 99, "MinPower is less than 1") + logging.info("MinPower is %s" % minPowerValue) self.step(4) - powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting) - asserts.assert_true(powerValue == newPowerValue, "PowerSetting was not correctly set") + maxPowerValue = 100 self.step(5) - newPowerValue = 125 - try: - await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint) - asserts.assert_fail("Expected an exception but received none.") - except InteractionModelError as e: - asserts.assert_equal(e.status, Status.ConstraintError, "Expected ConstraintError but received a different error.") + if is_pwrlmits_feature_supported: + maxPowerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxPower) + asserts.assert_greater(maxPowerValue, minPowerValue, "MaxPower is less than MinPower") + asserts.assert_less(maxPowerValue, 100, "MaxPower is greater than 100") + logging.info("MaxPower is %s" % maxPowerValue) + + self.step(6) + powerStepValue = 10 + + self.step(7) + if is_pwrlmits_feature_supported: + powerStepValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerStep) + asserts.assert_greater_equal(powerStepValue, 1, "PowerStep is less than 1") + asserts.assert_less_equal(powerStepValue, maxPowerValue, "PowerStep is greater than MaxPower") + asserts.assert_true((maxPowerValue - minPowerValue) % powerStepValue == + 0, "PowerStep is not correct for MaxPower - MinPower") + logging.info("PowerStep is %s" % powerStepValue) + + self.step(8) + powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting) + asserts.assert_greater_equal(powerValue, minPowerValue, "PowerSetting is less than the minimum.") + asserts.assert_less_equal(powerValue, maxPowerValue, "PowerSetting is greater than the maxium") + asserts.assert_true((powerValue-minPowerValue) % powerStepValue == 0, "PowerSetting is not a multiple of power step") + + self.step(9) + logging.info("minPowerValue is %s" % minPowerValue) + logging.info("maxPowerValue is %s" % maxPowerValue) + logging.info("powerStepValue is %s" % powerStepValue) + logging.info("powerValue is %s" % powerValue) + newPowerValue = (powerValue-minPowerValue) % (maxPowerValue-minPowerValue)+powerStepValue+minPowerValue + logging.info("newPowerValue is %s" % newPowerValue) + await self.set_power_setting_expect_success(endpoint, newPowerValue) + + self.step(10) + await self.read_and_check_power_setting_value(endpoint, newPowerValue) + + self.step(11) + await self.set_power_setting_expect_success(endpoint, minPowerValue) + + self.step(12) + await self.read_and_check_power_setting_value(endpoint, minPowerValue) + + self.step(13) + await self.set_power_setting_expect_success(endpoint, maxPowerValue) + + self.step(14) + await self.read_and_check_power_setting_value(endpoint, maxPowerValue) + + self.step(15) + newPowerValue = maxPowerValue+1 + await self.set_power_setting_expect_failure(endpoint, newPowerValue) + + self.step(16) + if powerStepValue == 1: + self.skip_step(17) + return + + self.step(17) + newPowerValue = minPowerValue + powerStepValue / 2 + logging.info("-------> MinPower = %d", minPowerValue) + logging.info("-------> PowerStep = %d", powerStepValue) + logging.info("-------> newPowerValue = %d", newPowerValue) + await self.set_power_setting_expect_failure(endpoint, newPowerValue) if __name__ == "__main__": diff --git a/src/python_testing/TC_MWOCTRL_2_3.py b/src/python_testing/TC_MWOCTRL_2_3.py deleted file mode 100644 index 20a1e730ab620a..00000000000000 --- a/src/python_testing/TC_MWOCTRL_2_3.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# 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 logging - -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_3(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) - - def desc_TC_MWOCTRL_2_3(self) -> str: - return "[TC-MWOCTRL-2.3] PWRNUM functionality with DUT as Server" - - def steps_TC_MWOCTRL_2_3(self) -> list[TestStep]: - steps = [ - TestStep(1, "Commissioning, already done", is_commissioning=True), - TestStep(2, "Read the MinPower attribute"), - TestStep(3, "Read the MaxPower attribute"), - TestStep(4, "Read the PowerStep attribute"), - TestStep(5, "Read the PowerSetting attribute"), - TestStep(6, "Send the SetCookingParameters command"), - TestStep(7, "Read and verify the PowerSetting attribute"), - TestStep(8, "Cause constraint error response"), - ] - return steps - - def pics_TC_MWOCTRL_2_3(self) -> list[str]: - pics = [ - "MWOCTRL.S", - ] - return pics - - @async_test_body - async def test_TC_MWOCTRL_2_3(self): - - endpoint = self.user_params.get("endpoint", 1) - - self.step(1) - attributes = Clusters.MicrowaveOvenControl.Attributes - feature_map = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) - features = Clusters.MicrowaveOvenControl.Bitmaps.Feature - commands = Clusters.Objects.MicrowaveOvenControl.Commands - - feature_map = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) - - supports_pwrnum_and_limits = feature_map & (features.kPowerAsNumber or features.kPowerNumberLimits) - - if not supports_pwrnum_and_limits: - logging.info("Device does not support PWRNUM and PWRLMTS so skipping the rest of the tests.") - self.skip_all_remaining_steps(2) - return - - self.step(2) - minPowerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MinPower) - logging.info("MinPower is %s" % minPowerValue) - asserts.assert_true(minPowerValue >= 1, "MinPower is less than 1") - - self.step(3) - maxPowerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxPower) - logging.info("MaxPower is %s" % maxPowerValue) - asserts.assert_true(maxPowerValue >= 1, "MaxPower is less than MinPower") - asserts.assert_true(maxPowerValue <= 100, "MaxPower is greater than 100") - - self.step(4) - powerStepValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerStep) - logging.info("PowerStep is %s" % powerStepValue) - asserts.assert_true(powerStepValue >= 1, "PowerStep is less than 1") - asserts.assert_true(powerStepValue <= maxPowerValue, "PowerStep is greater than MaxPower") - - self.step(5) - powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting) - logging.info("PowerSetting is %s" % powerValue) - asserts.assert_true(powerValue >= minPowerValue, "PowerSetting is less than MinPower") - asserts.assert_true(powerValue <= maxPowerValue, "PowerSetting is greater than MaxPower") - asserts.assert_true((powerValue-minPowerValue) % powerStepValue == 0, "PowerSetting is not a multiple of 10") - - self.step(6) - newPowerValue = (powerValue-minPowerValue) % (maxPowerValue-minPowerValue)+powerStepValue+minPowerValue - try: - await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint) - except InteractionModelError as e: - asserts.assert_equal(e.status, Status.Success, "Unexpected error returned") - - self.step(7) - powerValue = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.PowerSetting) - asserts.assert_true(powerValue == newPowerValue, "PowerSetting was not correctly set") - - self.step(8) - newPowerValue = maxPowerValue+1 - try: - await self.send_single_cmd(cmd=commands.SetCookingParameters(powerSetting=newPowerValue), endpoint=endpoint) - asserts.assert_fail("Expected an exception but received none.") - except InteractionModelError as e: - asserts.assert_equal(e.status, Status.ConstraintError, "Expected ConstraintError but received a different response.") - - -if __name__ == "__main__": - default_matter_test_main()