From efa0f3db9ed6299f70eb12cb81abfe27f38ac7a4 Mon Sep 17 00:00:00 2001 From: Rob Bultman Date: Fri, 3 May 2024 17:05:25 -0400 Subject: [PATCH] Changes per comments --- src/python_testing/TC_DISHM_2_1.py | 92 +++++++++++++++++++----------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/src/python_testing/TC_DISHM_2_1.py b/src/python_testing/TC_DISHM_2_1.py index 834c902d96f285..62604cca4df062 100644 --- a/src/python_testing/TC_DISHM_2_1.py +++ b/src/python_testing/TC_DISHM_2_1.py @@ -18,7 +18,7 @@ import logging import chip.clusters as Clusters -from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts @@ -34,6 +34,34 @@ async def send_change_to_mode_cmd(self, newMode) -> Clusters.Objects.DishwasherM "Unexpected return type for ChangeToMode") return ret + def desc_TC_DISHM_2_1(self) -> str: + return "[TC-DISHM-2.1] Change to Mode functionality with DUT as Server" + + def steps_TC_DISHM_2_1(self) -> list[TestStep]: + steps = [ + TestStep(1, "Commissioning, already done", is_commissioning=True), + TestStep(2, "TH reads from the DUT the SupportedModes attribute."), + TestStep(3, "TH reads from the DUT the CurrentMode attribute."), + TestStep(4, "TH sends a ChangeToMode command to the DUT with NewMode set to old_current_mode_dut"), + TestStep(5, "Manually put the device in a state from which it will FAIL to transition to PIXIT.DISHM.MODE_CHANGE_FAIL"), + TestStep(6, "TH reads from the DUT the CurrentMode attribute."), + TestStep(7, "TH sends a ChangeToMode command to the DUT with NewMode set to PIXIT.DISHM.MODE_CHANGE_FAIL"), + TestStep(8, "TH reads from the DUT the CurrentMode attribute."), + TestStep(9, "Manually put the device in a state from which it will SUCCESSFULLY transition to PIXIT.DISHM.MODE_CHANGE_OK"), + TestStep(10, "TH reads from the DUT the CurrentMode attribute."), + TestStep(11, "TH sends a ChangeToMode command to the DUT with NewMode set to PIXIT.DISHM.MODE_CHANGE_OK"), + TestStep(12, "TH reads from the DUT the CurrentMode attribute."), + TestStep(13, "TH sends a ChangeToMode command to the DUT with NewMode set to invalid_mode_th"), + TestStep(14, "TH reads from the DUT the CurrentMode attribute."), + ] + return steps + + def pics_TC_DISHM_2_1(self) -> list[str]: + pics = [ + "DISHM.S", + ] + return pics + @async_test_body async def test_TC_DISHM_2_1(self): @@ -57,23 +85,23 @@ async def test_TC_DISHM_2_1(self): attributes = Clusters.DishwasherMode.Attributes - self.print_step(1, "Commissioning, already done") + self.step(1) - self.print_step(2, "Read SupportedModes attribute") + self.step(2) + # read the supported modes supported_modes = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes) - logging.info("SupportedModes: %s" % (supported_modes)) - + # need at least 2 modes asserts.assert_greater_equal(len(supported_modes), 2, "SupportedModes must have at least two entries!") - + # save them supported_modes_dut = [m.mode for m in supported_modes] + # check that mode change fail is present + asserts.assert_true(self.modeFail in supported_modes_dut, "SupportedModes must include MODE_CHANGE_FAIL") - self.print_step(3, "Read CurrentMode attribute") - + self.step(3) + # Read the current mode old_current_mode_dut = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (old_current_mode_dut)) - # pick a value that's not in the list of supported modes invalid_mode_th = max(supported_modes_dut) + 1 @@ -85,26 +113,27 @@ class CommonCodes(Enum): GENERIC_FAILURE = 0x02 INVALID_IN_MODE = 0x03 - self.print_step(4, "Send ChangeToMode command with NewMode set to %d" % (old_current_mode_dut)) - + self.step(4) + logging.info("Send ChangeToMode command with NewMode set to %d" % (old_current_mode_dut)) ret = await self.send_change_to_mode_cmd(newMode=old_current_mode_dut) asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing the mode to the current mode should be a no-op") if self.check_pics("DISHM.S.M.CAN_TEST_MODE_FAILURE"): - self.print_step(5, "Manually put the device in a state from which it will FAIL to transition to mode %d" % (self.modeFail)) + self.step(5) + logging.info("Manually put the device in a state from which it will FAIL to transition to mode %d" % (self.modeFail)) input("Press Enter when done.\n") - self.print_step(6, "Read CurrentMode attribute") + self.step(6) old_current_mode_dut = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (old_current_mode_dut)) - self.print_step(7, "Send ChangeToMode command with NewMode set to %d" % (self.modeFail)) + self.step(7) + logging.info("Send ChangeToMode command with NewMode set to %d" % (self.modeFail)) ret = await self.send_change_to_mode_cmd(newMode=self.modeFail) st = ret.status logging.info("ChangeToMode Status: %s" % (ret.status)) - is_mfg_code = st in range(0x80, 0xC0) + is_mfg_code = st in range(0x80, 0xBF) is_err_code = (st == CommonCodes.GENERIC_FAILURE.value) or (st == CommonCodes.INVALID_IN_MODE.value) or is_mfg_code asserts.assert_true( is_err_code, "Changing to mode %d must fail due to the current state of the device" % (self.modeFail)) @@ -112,46 +141,43 @@ class CommonCodes(Enum): st_text_len = len(ret.statusText) asserts.assert_true(st_text_len in range(1, 65), "StatusText length (%d) must be between 1 and 64" % (st_text_len)) - self.print_step(8, "Read CurrentMode attribute") + self.step(8) current_mode = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (current_mode)) - asserts.assert_true(current_mode == old_current_mode_dut, "CurrentMode changed after failed ChangeToMode command!") + else: + for x in range(5, 9): + self.skip(x) - self.print_step(9, "Manually put the device in a state from which it will SUCCESSFULLY transition to mode %d" % (self.modeOk)) + self.step(9) + logging.info("Manually put the device in a state from which it will SUCCESSFULLY transition to mode %d" % (self.modeOk)) input("Press Enter when done.\n") - self.print_step(10, "Read CurrentMode attribute") + self.step(10) old_current_mode_dut = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (old_current_mode_dut)) - self.print_step(11, "Send ChangeToMode command with NewMode set to %d" % (self.modeOk)) - + self.step(11) + logging.info("Send ChangeToMode command with NewMode set to %d" % (self.modeOk)) ret = await self.send_change_to_mode_cmd(newMode=self.modeOk) asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing to mode %d must succeed due to the current state of the device" % (self.modeOk)) - self.print_step(12, "Read CurrentMode attribute") + self.step(12) current_mode = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (current_mode)) - asserts.assert_true(current_mode == self.modeOk, "CurrentMode doesn't match the argument of the successful ChangeToMode command!") - self.print_step(13, "Send ChangeToMode command with NewMode set to %d" % (invalid_mode_th)) - + self.step(13) + logging.info("Send ChangeToMode command with NewMode set to %d" % (invalid_mode_th)) ret = await self.send_change_to_mode_cmd(newMode=invalid_mode_th) asserts.assert_true(ret.status == CommonCodes.UNSUPPORTED_MODE.value, "Attempt to change to invalid mode %d didn't fail as expected" % (invalid_mode_th)) - self.print_step(14, "Read CurrentMode attribute") + self.step(14) current_mode = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) - logging.info("CurrentMode: %s" % (current_mode)) - asserts.assert_true(current_mode == self.modeOk, "CurrentMode changed after failed ChangeToMode command!")