From 9f10e00d18e6cab7f1d045333d709d7d79b0da0f Mon Sep 17 00:00:00 2001 From: Moises Terrones Date: Wed, 4 Dec 2024 10:46:16 -0600 Subject: [PATCH 1/5] Create initial test draft for WasherCtrl --- src/python_testing/TC_WASHERCTRL_2_1.py | 129 ++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/python_testing/TC_WASHERCTRL_2_1.py diff --git a/src/python_testing/TC_WASHERCTRL_2_1.py b/src/python_testing/TC_WASHERCTRL_2_1.py new file mode 100644 index 00000000000000..18de4f22b0790c --- /dev/null +++ b/src/python_testing/TC_WASHERCTRL_2_1.py @@ -0,0 +1,129 @@ +# +# 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. +# + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: +# run1: +# app: ${ALL_CLUSTERS_APP} +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# 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:${TRACE_TEST_JSON}.json +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# factory-reset: true +# quiet: true +# === END CI TEST ARGUMENTS === + +import logging +import random + +import chip.clusters as Clusters +from chip.interaction_model import Status +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts + +logger = logging.getLogger(__name__) + + +MAX_SPIN_SPEEDS = 16 + + +class TC_WASHERCTRL_2_1(MatterBaseTest): + + def desc_TC_WASHERCTRL_2_1(self) -> str: + """Returns a description of this test""" + return "[TC-WASHERCTRL-2.1] Optional Spin attributes with DUT as Server" + + def pics_TC_WASHERCTRL_2_1(self) -> list[str]: + pics = [ + "WASHERCTRL.S.F00", + ] + return pics + + def steps_TC_WASHERCTRL_2_1(self) -> list[TestStep]: + steps = [ + TestStep(1, "Commissioning, already done", + is_commissioning=True), + TestStep(2, "TH reads from the DUT the SpinSpeeds attribute"), + TestStep(3, "TH reads from the DUT the SpinSpeedCurrent attribute"), + TestStep(4, "TH writes a supported SpinSpeedCurrent attribute that is a valid index into the list" + + "of spin speeds (0 to numSpinSpeeds - 1)"), + TestStep(5, "After a few seconds, TH reads from the DUT the SpinSpeedCurrent attribute"), + TestStep(6, "TH writes an unsupported SpinSpeedCurrent attribute that is other than 0 to DUT") + ] + + return steps + + @async_test_body + async def test_TC_WASHERCTRL_2_1(self): + + endpoint = self.get_endpoint(default=1) + + self.step(1) + + # Read the SpinSpeeds attributes + self.step(2) + logger.info("Doing Step 2") + list_speed_speeds = await self.read_single_attribute_check_success(endpoint=endpoint, + cluster=Clusters.Objects.LaundryWasherControls, + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeeds) + + numSpinSpeeds = len(list_speed_speeds) + asserts.assert_less_equal(numSpinSpeeds, MAX_SPIN_SPEEDS, "List of SpinSpeeds larger than maximum allowed") + + # Read the SpinSpeedCurrent attribute + self.step(3) + logger.info("Doing Step 3") + spin_speed_current = await self.read_single_attribute_check_success(endpoint=endpoint, + cluster=Clusters.Objects.LaundryWasherControls, + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) + asserts.assert_true(isinstance(spin_speed_current, int), "SpinSpeedCurrent has an invalid value") + asserts.assert_true(0 <= spin_speed_current <= (numSpinSpeeds - 1), 0, "SpinSpeedCurrent outside valid range") + + # Write a valid SpinSpeedCurrent value + self.step(4) + logger.info("Doing Step 4") + requested_speed = random.randint(0, numSpinSpeeds - 1) + result = await self.default_controller.WriteAttribute(self.dut_node_id, + [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed))]) + asserts.assert_equal(result[0].Status, Status.Success, "Failed to write SpinSpeed value") + + # Read SpinSpeedCurrent value and verify that was changed. + self.step(5) + logger.info("Doing Step 5") + current_value = await self.read_single_attribute_check_success(endpoint=endpoint, + cluster=Clusters.Objects.LaundryWasherControls, + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) + asserts.assert_equal(current_value, requested_speed, "Value obtained different than the previously written one") + + # Try to write an invalid value (outside supported range) + self.step(6) + logger.info("Doing Step 6") + result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds))]) + asserts.assert_equal(result[0].Status, Status.ConstraintError, + "Trying to write an invalid value should return ConstraintError") + + +if __name__ == "__main__": + default_matter_test_main() From a6da576512a4054d17b76f66f060bf1f0643f2b5 Mon Sep 17 00:00:00 2001 From: Moises Terrones Date: Wed, 4 Dec 2024 10:54:05 -0600 Subject: [PATCH 2/5] Remove test logs --- src/python_testing/TC_WASHERCTRL_2_1.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/python_testing/TC_WASHERCTRL_2_1.py b/src/python_testing/TC_WASHERCTRL_2_1.py index 18de4f22b0790c..2d354bd0792ce8 100644 --- a/src/python_testing/TC_WASHERCTRL_2_1.py +++ b/src/python_testing/TC_WASHERCTRL_2_1.py @@ -84,7 +84,6 @@ async def test_TC_WASHERCTRL_2_1(self): # Read the SpinSpeeds attributes self.step(2) - logger.info("Doing Step 2") list_speed_speeds = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.Objects.LaundryWasherControls, attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeeds) @@ -94,7 +93,6 @@ async def test_TC_WASHERCTRL_2_1(self): # Read the SpinSpeedCurrent attribute self.step(3) - logger.info("Doing Step 3") spin_speed_current = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.Objects.LaundryWasherControls, attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) @@ -103,7 +101,6 @@ async def test_TC_WASHERCTRL_2_1(self): # Write a valid SpinSpeedCurrent value self.step(4) - logger.info("Doing Step 4") requested_speed = random.randint(0, numSpinSpeeds - 1) result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed))]) @@ -111,7 +108,6 @@ async def test_TC_WASHERCTRL_2_1(self): # Read SpinSpeedCurrent value and verify that was changed. self.step(5) - logger.info("Doing Step 5") current_value = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.Objects.LaundryWasherControls, attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) @@ -119,7 +115,6 @@ async def test_TC_WASHERCTRL_2_1(self): # Try to write an invalid value (outside supported range) self.step(6) - logger.info("Doing Step 6") result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds))]) asserts.assert_equal(result[0].Status, Status.ConstraintError, "Trying to write an invalid value should return ConstraintError") From 5f86eb252da7933d02d045f449100a3bf1420da6 Mon Sep 17 00:00:00 2001 From: Moises Terrones Date: Wed, 4 Dec 2024 11:33:27 -0600 Subject: [PATCH 3/5] Fix and add missing assert --- src/python_testing/TC_WASHERCTRL_2_1.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_WASHERCTRL_2_1.py b/src/python_testing/TC_WASHERCTRL_2_1.py index 2d354bd0792ce8..4446ef2cec5e21 100644 --- a/src/python_testing/TC_WASHERCTRL_2_1.py +++ b/src/python_testing/TC_WASHERCTRL_2_1.py @@ -88,6 +88,7 @@ async def test_TC_WASHERCTRL_2_1(self): cluster=Clusters.Objects.LaundryWasherControls, attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeeds) + asserts.assert_true(isinstance(list_speed_speeds, list), "Returned value was not a list") numSpinSpeeds = len(list_speed_speeds) asserts.assert_less_equal(numSpinSpeeds, MAX_SPIN_SPEEDS, "List of SpinSpeeds larger than maximum allowed") @@ -97,7 +98,7 @@ async def test_TC_WASHERCTRL_2_1(self): cluster=Clusters.Objects.LaundryWasherControls, attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) asserts.assert_true(isinstance(spin_speed_current, int), "SpinSpeedCurrent has an invalid value") - asserts.assert_true(0 <= spin_speed_current <= (numSpinSpeeds - 1), 0, "SpinSpeedCurrent outside valid range") + asserts.assert_true(0 <= spin_speed_current <= (numSpinSpeeds - 1), "SpinSpeedCurrent outside valid range") # Write a valid SpinSpeedCurrent value self.step(4) From 4a1e6850545699a0b14f1e2932a2c5ce5292c53d Mon Sep 17 00:00:00 2001 From: Moises Terrones Date: Wed, 4 Dec 2024 19:42:04 -0600 Subject: [PATCH 4/5] replace WriteAttribute with write_single_attribute --- src/python_testing/TC_WASHERCTRL_2_1.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_WASHERCTRL_2_1.py b/src/python_testing/TC_WASHERCTRL_2_1.py index 4446ef2cec5e21..28f8855169975f 100644 --- a/src/python_testing/TC_WASHERCTRL_2_1.py +++ b/src/python_testing/TC_WASHERCTRL_2_1.py @@ -103,9 +103,8 @@ async def test_TC_WASHERCTRL_2_1(self): # Write a valid SpinSpeedCurrent value self.step(4) requested_speed = random.randint(0, numSpinSpeeds - 1) - result = await self.default_controller.WriteAttribute(self.dut_node_id, - [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed))]) - asserts.assert_equal(result[0].Status, Status.Success, "Failed to write SpinSpeed value") + result = await self.write_single_attribute(attribute_value=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed), + endpoint_id=endpoint) # Read SpinSpeedCurrent value and verify that was changed. self.step(5) From f4450f04d6f85ef1e19ba6ba3681833116cf97d6 Mon Sep 17 00:00:00 2001 From: Moises Terrones Date: Wed, 4 Dec 2024 19:59:27 -0600 Subject: [PATCH 5/5] Change second write --- src/python_testing/TC_WASHERCTRL_2_1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_WASHERCTRL_2_1.py b/src/python_testing/TC_WASHERCTRL_2_1.py index 28f8855169975f..c7078d335e93ab 100644 --- a/src/python_testing/TC_WASHERCTRL_2_1.py +++ b/src/python_testing/TC_WASHERCTRL_2_1.py @@ -115,9 +115,9 @@ async def test_TC_WASHERCTRL_2_1(self): # Try to write an invalid value (outside supported range) self.step(6) - result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds))]) - asserts.assert_equal(result[0].Status, Status.ConstraintError, - "Trying to write an invalid value should return ConstraintError") + result = await self.write_single_attribute(attribute_value=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds), + endpoint_id=endpoint, expect_success=False) + asserts.assert_equal(result, Status.ConstraintError, "Trying to write an invalid value should return ConstraintError") if __name__ == "__main__":