Skip to content

Commit

Permalink
TC-IDM-12.1: Add a wildcard dump test (project-chip#33878)
Browse files Browse the repository at this point in the history
* TC-IDM-12.1: Add a wildcard dump test

This is a convenience test for the test harness that creates a
device dump for submission as a part of the certification materials.
Putting this as a separate test means we don't need to ask the
testers to mess around with setting parameters for this test in
the test harness.

* linter

* add wildcard read as a step

* slight re-wording
  • Loading branch information
cecille committed Jun 17, 2024
1 parent 7bc498b commit 61bf37e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
19 changes: 18 additions & 1 deletion src/python_testing/TC_DeviceBasicComposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from chip.interaction_model import InteractionModelError, Status
from chip.tlv import uint
from global_attribute_ids import GlobalAttributeIds
from matter_testing_support import (AttributePathLocation, ClusterPathLocation, CommandPathLocation, MatterBaseTest,
from matter_testing_support import (AttributePathLocation, ClusterPathLocation, CommandPathLocation, MatterBaseTest, TestStep,
async_test_body, default_matter_test_main)
from mobly import asserts
from taglist_and_topology_test_support import (create_device_type_list_for_root, create_device_type_lists, find_tag_list_problems,
Expand Down Expand Up @@ -748,6 +748,23 @@ def test_TC_DESC_2_2(self):
if problems or root_problems:
self.fail_current_test("Problems with tags lists")

def steps_TC_IDM_12_1(self):
return [TestStep(0, "TH performs a wildcard read of all attributes and endpoints on the device"),
TestStep(1, "TH creates a MatterTlvJson dump of the wildcard attributes for submission to certification.")]

def test_TC_IDM_12_1(self):
# wildcard read - already done.
self.step(0)

# Create the dump
self.step(1)
pid = self.endpoints[0][Clusters.BasicInformation][Clusters.BasicInformation.Attributes.ProductID]
vid = self.endpoints[0][Clusters.BasicInformation][Clusters.BasicInformation.Attributes.VendorID]
software_version = self.endpoints[0][Clusters.BasicInformation][Clusters.BasicInformation.Attributes.SoftwareVersion]
filename = f'device_dump_0x{vid:04X}_0x{pid:04X}_{software_version}.json'
dump_device_composition_path = self.user_params.get("dump_device_composition_path", filename)
self.dump_wildcard(dump_device_composition_path)


if __name__ == "__main__":
default_matter_test_main()
32 changes: 17 additions & 15 deletions src/python_testing/basic_composition_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
import pathlib
import sys
import typing
from pprint import pprint
from typing import Any, Optional

Expand Down Expand Up @@ -97,6 +98,16 @@ def ConvertValue(value) -> Any:


class BasicCompositionTests:
def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]):
node_dump_dict = {endpoint_id: MatterTlvToJson(self.endpoints_tlv[endpoint_id]) for endpoint_id in self.endpoints_tlv}
logging.debug(f"Raw TLV contents of Node: {json.dumps(node_dump_dict, indent=2)}")

if dump_device_composition_path is not None:
with open(pathlib.Path(dump_device_composition_path).with_suffix(".json"), "wt+") as outfile:
json.dump(node_dump_dict, outfile, indent=2)
with open(pathlib.Path(dump_device_composition_path).with_suffix(".txt"), "wt+") as outfile:
pprint(self.endpoints, outfile, indent=1, width=200, compact=True)

async def setup_class_helper(self, default_to_pase: bool = True):
dev_ctrl = self.default_controller
self.problems = []
Expand All @@ -114,29 +125,20 @@ async def setup_class_helper(self, default_to_pase: bool = True):
node_id = self.dut_node_id

wildcard_read = (await dev_ctrl.Read(node_id, [()]))
endpoints_tlv = wildcard_read.tlvAttributes

node_dump_dict = {endpoint_id: MatterTlvToJson(endpoints_tlv[endpoint_id]) for endpoint_id in endpoints_tlv}
logging.debug(f"Raw TLV contents of Node: {json.dumps(node_dump_dict, indent=2)}")

if dump_device_composition_path is not None:
with open(pathlib.Path(dump_device_composition_path).with_suffix(".json"), "wt+") as outfile:
json.dump(node_dump_dict, outfile, indent=2)
with open(pathlib.Path(dump_device_composition_path).with_suffix(".txt"), "wt+") as outfile:
pprint(wildcard_read.attributes, outfile, indent=1, width=200, compact=True)

logging.info("###########################################################")
logging.info("Start of actual tests")
logging.info("###########################################################")

# ======= State kept for use by all tests =======

# All endpoints in "full object" indexing format
self.endpoints = wildcard_read.attributes

# All endpoints in raw TLV format
self.endpoints_tlv = wildcard_read.tlvAttributes

self.dump_wildcard(dump_device_composition_path)

logging.info("###########################################################")
logging.info("Start of actual tests")
logging.info("###########################################################")

def get_test_name(self) -> str:
"""Return the function name of the caller. Used to create logging entries."""
return sys._getframe().f_back.f_code.co_name
Expand Down

0 comments on commit 61bf37e

Please sign in to comment.