|
| 1 | +# |
| 2 | +# Copyright (c) 2024 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 | +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments |
| 19 | +# for details about the block below. |
| 20 | +# |
| 21 | +# === BEGIN CI TEST ARGUMENTS === |
| 22 | +# test-runner-runs: |
| 23 | +# run1: |
| 24 | +# app: ${ALL_CLUSTERS_APP} |
| 25 | +# app-args: > |
| 26 | +# --discriminator 1234 |
| 27 | +# --KVS kvs1 |
| 28 | +# --trace-to json:${TRACE_APP}.json |
| 29 | +# --enable-key 000102030405060708090a0b0c0d0e0f |
| 30 | +# script-args: > |
| 31 | +# --storage-path admin_storage.json |
| 32 | +# --commissioning-method on-network |
| 33 | +# --discriminator 1234 |
| 34 | +# --passcode 20202021 |
| 35 | +# --hex-arg enableKey:000102030405060708090a0b0c0d0e0f |
| 36 | +# --trace-to json:${TRACE_TEST_JSON}.json |
| 37 | +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
| 38 | +# --enable-key 000102030405060708090a0b0c0d0e0f |
| 39 | +# factory-reset: true |
| 40 | +# quiet: true |
| 41 | +# === END CI TEST ARGUMENTS === |
| 42 | +# |
| 43 | + |
| 44 | +import asyncio |
| 45 | + |
| 46 | +import chip.clusters as Clusters |
| 47 | +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 48 | +from mobly import asserts |
| 49 | + |
| 50 | + |
| 51 | +class TC_DGSW_2_2(MatterBaseTest): |
| 52 | + |
| 53 | + @staticmethod |
| 54 | + def is_valid_uint64_value(value): |
| 55 | + return isinstance(value, int) and 0 <= value <= 0xFFFFFFFFFFFFFFFF |
| 56 | + |
| 57 | + @staticmethod |
| 58 | + def is_valid_octet_string(value): |
| 59 | + return isinstance(value, (bytes, bytearray)) |
| 60 | + |
| 61 | + async def send_software_fault_test_event_trigger(self): |
| 62 | + await self.send_test_event_triggers(eventTrigger=0x0034000000000000) |
| 63 | + |
| 64 | + async def read_software_fault_events(self, endpoint): |
| 65 | + event_path = [(endpoint, Clusters.SoftwareDiagnostics.Events.SoftwareFault, 1)] |
| 66 | + events = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path) |
| 67 | + return events |
| 68 | + |
| 69 | + def desc_TC_DGSW_2_2(self) -> str: |
| 70 | + """Returns a description of this test""" |
| 71 | + return "[TC-DGSW-2.2] Attributes with Server as DUT" |
| 72 | + |
| 73 | + def pics_TC_DGSW_2_2(self) -> list[str]: |
| 74 | + return ["DGSW.S"] |
| 75 | + |
| 76 | + def steps_TC_DGSW_2_2(self) -> list[TestStep]: |
| 77 | + steps = [ |
| 78 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 79 | + TestStep(2, "Read the SoftwareFault event(s) from the DUT"), |
| 80 | + ] |
| 81 | + return steps |
| 82 | + |
| 83 | + @async_test_body |
| 84 | + async def test_TC_DGSW_2_2(self): |
| 85 | + |
| 86 | + endpoint = self.get_endpoint(default=0) |
| 87 | + |
| 88 | + # STEP 1: Commission DUT (already done) |
| 89 | + self.step(1) |
| 90 | + |
| 91 | + # STEP 2: DUT sends an event report to TH. TH reads a list of SoftwareFault structs from DUT. |
| 92 | + self.step(2) |
| 93 | + |
| 94 | + # Trigger a SoftwareFault event on the DUT |
| 95 | + await self.send_software_fault_test_event_trigger() |
| 96 | + |
| 97 | + # Allow some time for the event to be processed |
| 98 | + await asyncio.sleep(1) |
| 99 | + |
| 100 | + # Read the SoftwareFault events |
| 101 | + software_fault_events = await self.read_software_fault_events(endpoint) |
| 102 | + |
| 103 | + # There should be at least one SoftwareFault event for this test to be valid. |
| 104 | + asserts.assert_true(len(software_fault_events) > 0, "No SoftwareFault events received from the DUT.") |
| 105 | + |
| 106 | + # For each event, verify the data type requirements |
| 107 | + for event_data in software_fault_events: |
| 108 | + # According to the test plan and specification: |
| 109 | + # - Id is mandatory, uint64 |
| 110 | + # - Name is vendor-specific string |
| 111 | + # - FaultRecording is vendor-specific payload in octstr format |
| 112 | + |
| 113 | + # Validate Id |
| 114 | + asserts.assert_true(self.is_valid_uint64_value(event_data.Data.id), |
| 115 | + "Id field should be a uint64 type") |
| 116 | + |
| 117 | + # Validate Name (string) - assuming event_data.Name is a string |
| 118 | + asserts.assert_true(isinstance(event_data.Data.name, str), |
| 119 | + "Name field should be a string type") |
| 120 | + |
| 121 | + # Validate FaultRecording (octet_string) |
| 122 | + # Assuming event_data.FaultRecording is bytes or bytearray |
| 123 | + asserts.assert_true(self.is_valid_octet_string(event_data.Data.faultRecording), |
| 124 | + "FaultRecording field should be an octet string (bytes/bytearray)") |
| 125 | + |
| 126 | + |
| 127 | +if __name__ == "__main__": |
| 128 | + default_matter_test_main() |
0 commit comments