-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement python test for TC_DGSW_2_2 #36900
Open
yufengwangca
wants to merge
4
commits into
project-chip:master
Choose a base branch
from
yufengwangca:pr/cluster/soft_diag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# | ||
# 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: ${LIGHTING_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 | ||
# --trace-to json:${TRACE_TEST_JSON}.json | ||
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto | ||
# factory-reset: true | ||
# quiet: true | ||
# === END CI TEST ARGUMENTS === | ||
# | ||
|
||
import asyncio | ||
import logging | ||
import subprocess | ||
|
||
import chip.clusters as Clusters | ||
import psutil | ||
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main | ||
from mobly import asserts | ||
|
||
|
||
def get_pid(name): | ||
pid = None | ||
|
||
for proc in psutil.process_iter(): | ||
if name in proc.name(): | ||
pid = proc.pid | ||
break | ||
|
||
return pid | ||
|
||
|
||
class TC_DGSW_2_2(MatterBaseTest): | ||
|
||
@staticmethod | ||
def is_valid_uint64_value(value): | ||
return isinstance(value, int) and 0 <= value <= 0xFFFFFFFFFFFFFFFF | ||
|
||
@staticmethod | ||
def is_valid_octet_string(value): | ||
return isinstance(value, (bytes, bytearray)) | ||
|
||
async def send_software_fault_event(self, endpoint, pid): | ||
# Construct the FIFO path. The PID should be known beforehand or discovered as part of the setup. | ||
fifo_path = f"/tmp/chip_lighting_fifo_{pid}" | ||
|
||
# Construct the shell command that simulates the software fault event | ||
command = f'echo \'{{"Name":"SoftwareFault"}}\' > {fifo_path}' | ||
|
||
logging.info(f"Sending SoftwareFault event: {command}") | ||
|
||
try: | ||
# Run the command locally. If this code is not running on the DUT itself, | ||
# you may need an SSH command or a test framework method to run it remotely. | ||
subprocess.run(command, shell=True, check=True) | ||
except subprocess.CalledProcessError as e: | ||
logging.exception(f"Failed to send SoftwareFault event via FIFO: {e}") | ||
asserts.fail("Failed to send SoftwareFault event") | ||
|
||
async def read_software_fault_events(self, endpoint): | ||
event_path = [(endpoint, Clusters.SoftwareDiagnostics.Events.SoftwareFault, 1)] | ||
events = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path) | ||
return events | ||
|
||
def desc_TC_DGSW_2_2(self) -> str: | ||
"""Returns a description of this test""" | ||
return "[TC-DGSW-2.2] Attributes with Server as DUT" | ||
|
||
def pics_TC_DGSW_2_2(self) -> list[str]: | ||
return ["DGSW.S"] | ||
|
||
def steps_TC_DGSW_2_2(self) -> list[TestStep]: | ||
steps = [ | ||
TestStep(1, "Commissioning, already done", is_commissioning=True), | ||
TestStep(2, "Read the SoftwareFault event(s) from the DUT"), | ||
] | ||
return steps | ||
|
||
@async_test_body | ||
async def test_TC_DGSW_2_2(self): | ||
|
||
endpoint = self.get_endpoint(default=0) | ||
|
||
# STEP 1: Commission DUT (already done) | ||
self.step(1) | ||
|
||
# STEP 2: DUT sends an event report to TH. TH reads a list of SoftwareFault structs from DUT. | ||
self.step(2) | ||
|
||
app_pid = self.matter_test_config.app_pid | ||
if app_pid == 0: | ||
app_pid = get_pid("chip-lighting-app") | ||
if app_pid is None: | ||
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set") | ||
|
||
# Trigger a SoftwareFault event on the DUT | ||
await self.send_software_fault_event(endpoint, app_pid) | ||
|
||
# Allow some time for the event to be processed | ||
await asyncio.sleep(1) | ||
|
||
# Read the SoftwareFault events | ||
software_fault_events = await self.read_software_fault_events(endpoint) | ||
|
||
# There should be at least one SoftwareFault event for this test to be valid. | ||
asserts.assert_true(len(software_fault_events) > 0, "No SoftwareFault events received from the DUT.") | ||
|
||
# For each event, verify the data type requirements | ||
for event_data in software_fault_events: | ||
# According to the test plan and specification: | ||
# - Id is mandatory, uint64 | ||
# - Name is vendor-specific string | ||
# - FaultRecording is vendor-specific payload in octstr format | ||
|
||
# Validate Id | ||
asserts.assert_true(self.is_valid_uint64_value(event_data.Data.id), | ||
"Id field should be a uint64 type") | ||
|
||
# Validate Name (string) - assuming event_data.Name is a string | ||
asserts.assert_true(isinstance(event_data.Data.name, str), | ||
"Name field should be a string type") | ||
|
||
# Validate FaultRecording (octet_string) | ||
# Assuming event_data.FaultRecording is bytes or bytearray | ||
asserts.assert_true(self.is_valid_octet_string(event_data.Data.faultRecording), | ||
"FaultRecording field should be an octet string (bytes/bytearray)") | ||
|
||
|
||
if __name__ == "__main__": | ||
default_matter_test_main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works only for linux platforms. Can we implement the trigger using a test event trigger as a generic mechanism ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjandhyala I think fifo was introduced to replace software interrupt as a generic mechanism to simulate event trigger on posix platforms, the more generic mechanism will be non-generic cluster command, do we really want that?