|
| 1 | +# |
| 2 | +# Copyright (c) 2022 Project CHIP Authors |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +from imaplib import Commands |
| 19 | +from matter_testing_support import MatterBaseTest, default_matter_test_main, async_test_body |
| 20 | +from chip.interaction_model import Status, InteractionModelError |
| 21 | +import chip.clusters as Clusters |
| 22 | +import logging |
| 23 | +from mobly import asserts |
| 24 | + |
| 25 | +# Assumes `--enable-key 000102030405060708090a0b0c0d0e0f` on Linux app command line, or a DUT |
| 26 | +# that has that Enable Key |
| 27 | +kExpectedKey = bytes([b for b in range(16)]) |
| 28 | + |
| 29 | +kBadKey = bytes([(b + 1) for b in range(16)]) |
| 30 | + |
| 31 | +kAllZerosKey = bytes(b"\x00" * 16) |
| 32 | + |
| 33 | +# Assumes `SampleTestEventTriggerDelegate` as it exists in Linux AppMain.cpp |
| 34 | +kValidEventTrigger = 0xFFFF_FFFF_FFF1_0000 |
| 35 | +kInvalidEventTrigger = 0 # Per TC-DGEN-2.3 |
| 36 | + |
| 37 | + |
| 38 | +class TestEventTrigger(MatterBaseTest): |
| 39 | + @async_test_body |
| 40 | + async def test_all_zeros_key(self): |
| 41 | + dev_ctrl = self.default_controller |
| 42 | + with asserts.assert_raises_regex(InteractionModelError, "ConstraintError", "All-zero TestEventTrigger key must return ConstraintError"): |
| 43 | + await dev_ctrl.SendCommand(self.dut_node_id, endpoint=0, payload=Clusters.GeneralDiagnostics.Commands.TestEventTrigger(enableKey=kAllZerosKey, eventTrigger=kValidEventTrigger)) |
| 44 | + |
| 45 | + @async_test_body |
| 46 | + async def test_incorrect_key(self): |
| 47 | + dev_ctrl = self.default_controller |
| 48 | + test_event_triggers_enabled = await self.read_single_attribute(dev_ctrl, self.dut_node_id, endpoint=0, attribute=Clusters.GeneralDiagnostics.Attributes.TestEventTriggersEnabled) |
| 49 | + asserts.assert_true(test_event_triggers_enabled, "This test expects Test Event Triggers are Enabled") |
| 50 | + |
| 51 | + with asserts.assert_raises_regex(InteractionModelError, "ConstraintError", "Bad TestEventTrigger key must return ConstraintError"): |
| 52 | + await dev_ctrl.SendCommand(self.dut_node_id, endpoint=0, payload=Clusters.GeneralDiagnostics.Commands.TestEventTrigger(enableKey=kBadKey, eventTrigger=kValidEventTrigger)) |
| 53 | + |
| 54 | + @async_test_body |
| 55 | + async def test_correct_key_valid_code(self): |
| 56 | + dev_ctrl = self.default_controller |
| 57 | + test_event_triggers_enabled = await self.read_single_attribute(dev_ctrl, self.dut_node_id, endpoint=0, attribute=Clusters.GeneralDiagnostics.Attributes.TestEventTriggersEnabled) |
| 58 | + asserts.assert_true(test_event_triggers_enabled, "This test expects Test Event Triggers are Enabled") |
| 59 | + |
| 60 | + # No response to command --> Success yields "None". |
| 61 | + asserts.assert_is_none(await dev_ctrl.SendCommand(self.dut_node_id, endpoint=0, payload=Clusters.GeneralDiagnostics.Commands.TestEventTrigger(enableKey=kExpectedKey, eventTrigger=kValidEventTrigger))) |
| 62 | + |
| 63 | + @async_test_body |
| 64 | + async def test_correct_key_invalid_code(self): |
| 65 | + dev_ctrl = self.default_controller |
| 66 | + test_event_triggers_enabled = await self.read_single_attribute(dev_ctrl, self.dut_node_id, endpoint=0, attribute=Clusters.GeneralDiagnostics.Attributes.TestEventTriggersEnabled) |
| 67 | + asserts.assert_true(test_event_triggers_enabled, "This test expects Test Event Triggers are Enabled") |
| 68 | + |
| 69 | + with asserts.assert_raises_regex(InteractionModelError, "InvalidCommand", "Unsupported EventTrigger must return InvalidCommand"): |
| 70 | + await dev_ctrl.SendCommand(self.dut_node_id, endpoint=0, payload=Clusters.GeneralDiagnostics.Commands.TestEventTrigger(enableKey=kExpectedKey, eventTrigger=kInvalidEventTrigger)) |
| 71 | + |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + default_matter_test_main() |
0 commit comments