Skip to content

Commit

Permalink
RVC TC 3.2 - Handle null start up mode (#28297)
Browse files Browse the repository at this point in the history
* handle null start up mode

* read StartUpMode after power cycle

* clean up
  • Loading branch information
duyen-tran authored and pull[bot] committed Nov 15, 2023
1 parent 5f2c75f commit 1237179
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
44 changes: 37 additions & 7 deletions src/python_testing/TC_RVCCLEANM_3_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#

import logging
import random

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from chip.interaction_model import Status
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches
from mobly import asserts

Expand All @@ -38,6 +41,10 @@ async def send_change_to_mode_cmd(self, newMode) -> Clusters.Objects.RvcCleanMod
"Unexpected return type for ChangeToMode")
return ret

async def write_start_up_mode(self, newMode):
ret = await self.default_controller.WriteAttribute(self.dut_node_id, [(self.endpoint, Clusters.RvcCleanMode.Attributes.StartUpMode(newMode))])
asserts.assert_equal(ret[0].Status, Status.Success, "Writing to StartUpMode failed")

@async_test_body
async def test_TC_RVCCLEANM_3_2(self):

Expand Down Expand Up @@ -69,16 +76,32 @@ class CommonCodes(Enum):
startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode)

logging.info("StartUpMode: %s" % (startup_mode))
if startup_mode == NullValue:
self.print_step(3, "Read SupportedModes attribute")
supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes)

logging.info("SupportedModes: %s" % (supported_modes))

asserts.assert_greater_equal(len(supported_modes), 2, "SupportedModes must have at least two entries!")

modes = [m.mode for m in supported_modes]
new_startup_mode = random.choice(modes)

self.print_step(3, "Read CurrentMode attribute")
self.print_step(4, "Write the value %s to StartUpMode" % (new_startup_mode))

await self.write_start_up_mode(newMode=new_startup_mode)
else:
new_startup_mode = startup_mode

self.print_step(5, "Read CurrentMode attribute")

old_current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)

logging.info("CurrentMode: %s" % (old_current_mode))

if old_current_mode == startup_mode:
if old_current_mode == new_startup_mode:

self.print_step(4, "Read SupportedModes attribute")
self.print_step(6, "Read SupportedModes attribute")
supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes)

logging.info("SupportedModes: %s" % (supported_modes))
Expand All @@ -88,21 +111,28 @@ class CommonCodes(Enum):
new_mode = None

for m in supported_modes:
if m.mode != startup_mode:
if m.mode != new_startup_mode:
new_mode = m.mode
break

self.print_step(5, "Send ChangeToMode command with NewMode set to %d" % (new_mode))
self.print_step(7, "Send ChangeToMode command with NewMode set to %d" % (new_mode))

ret = await self.send_change_to_mode_cmd(newMode=new_mode)
asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing the mode should succeed")

self.default_controller.ExpireSessions(self.dut_node_id)

self.print_step(6, "Physically power cycle the device")
self.print_step(8, "Physically power cycle the device")
input("Press Enter when done.\n")

self.print_step(7, "Read CurrentMode attribute")
self.print_step(9, "Read StartUpMode attribute")

startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode)

logging.info("StartUpMode: %s" % (startup_mode))
asserts.assert_equal(startup_mode, new_startup_mode, "StartUpMode must match the value it was before a power cycle")

self.print_step(10, "Read CurrentMode attribute")

current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)

Expand Down
44 changes: 37 additions & 7 deletions src/python_testing/TC_RVCRUNM_3_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#

import logging
import random

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from chip.interaction_model import Status
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches
from mobly import asserts

Expand All @@ -38,6 +41,10 @@ async def send_change_to_mode_cmd(self, newMode) -> Clusters.Objects.RvcRunMode.
"Unexpected return type for ChangeToMode")
return ret

async def write_start_up_mode(self, newMode):
ret = await self.default_controller.WriteAttribute(self.dut_node_id, [(self.endpoint, Clusters.RvcRunMode.Attributes.StartUpMode(newMode))])
asserts.assert_equal(ret[0].Status, Status.Success, "Writing to StartUpMode failed")

@async_test_body
async def test_TC_RVCRUNM_3_2(self):

Expand Down Expand Up @@ -69,16 +76,32 @@ class CommonCodes(Enum):
startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode)

logging.info("StartUpMode: %s" % (startup_mode))
if startup_mode == NullValue:
self.print_step(3, "Read SupportedModes attribute")
supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes)

logging.info("SupportedModes: %s" % (supported_modes))

asserts.assert_greater_equal(len(supported_modes), 2, "SupportedModes must have at least two entries!")

modes = [m.mode for m in supported_modes]
new_startup_mode = random.choice(modes)

self.print_step(3, "Read CurrentMode attribute")
self.print_step(4, "Write the value %s to StartUpMode" % (new_startup_mode))

await self.write_start_up_mode(newMode=new_startup_mode)
else:
new_startup_mode = startup_mode

self.print_step(5, "Read CurrentMode attribute")

old_current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)

logging.info("CurrentMode: %s" % (old_current_mode))

if old_current_mode == startup_mode:
if old_current_mode == new_startup_mode:

self.print_step(4, "Read SupportedModes attribute")
self.print_step(6, "Read SupportedModes attribute")
supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes)

logging.info("SupportedModes: %s" % (supported_modes))
Expand All @@ -88,21 +111,28 @@ class CommonCodes(Enum):
new_mode = None

for m in supported_modes:
if m.mode != startup_mode:
if m.mode != new_startup_mode:
new_mode = m.mode
break

self.print_step(5, "Send ChangeToMode command with NewMode set to %d" % (new_mode))
self.print_step(7, "Send ChangeToMode command with NewMode set to %d" % (new_mode))

ret = await self.send_change_to_mode_cmd(newMode=new_mode)
asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing the mode should succeed")

self.default_controller.ExpireSessions(self.dut_node_id)

self.print_step(6, "Physically power cycle the device")
self.print_step(8, "Physically power cycle the device")
input("Press Enter when done.\n")

self.print_step(7, "Read CurrentMode attribute")
self.print_step(9, "Read StartUpMode attribute")

startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode)

logging.info("StartUpMode: %s" % (startup_mode))
asserts.assert_equal(startup_mode, new_startup_mode, "StartUpMode must match the value it was before a power cycle")

self.print_step(10, "Read CurrentMode attribute")

current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)

Expand Down

0 comments on commit 1237179

Please sign in to comment.