Skip to content

Commit

Permalink
IDM-12.1: Also dump to log (#35098)
Browse files Browse the repository at this point in the history
* IDM-12.1: Also dump to log

* simplify print command
  • Loading branch information
cecille authored and pull[bot] committed Nov 14, 2024
1 parent 8048b62 commit 3472850
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/python_testing/TC_DeviceBasicComposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,18 @@ def test_TC_IDM_12_1(self):
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)
json_str, txt_str = self.dump_wildcard(dump_device_composition_path)

# Structured dump so we can pull these back out of the logs
def log_structured_data(start_tag: str, dump_string):
lines = dump_string.splitlines()
logging.info(f'{start_tag}BEGIN ({len(lines)} lines)====')
for line in lines:
logging.info(f'{start_tag}{line}')
logging.info(f'{start_tag}END ====')

log_structured_data('==== json: ', json_str)
log_structured_data('==== txt: ', txt_str)


if __name__ == "__main__":
Expand Down
11 changes: 8 additions & 3 deletions src/python_testing/basic_composition_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pathlib
import sys
import typing
from pprint import pprint
from pprint import pformat, pprint
from typing import Any, Optional

import chip.clusters.ClusterObjects
Expand Down Expand Up @@ -105,15 +105,20 @@ async def connect_over_pase(self, dev_ctrl):
asserts.assert_equal(len(setupCode), 1, "Require one of either --qr-code or --manual-code.")
await dev_ctrl.FindOrEstablishPASESession(setupCode[0], self.dut_node_id)

def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]):
def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]) -> tuple[str, str]:
""" Dumps a json and a txt file of the attribute wildcard for this device if the dump_device_composition_path is supplied.
Returns the json and txt as strings.
"""
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)}")
json_dump_string = json.dumps(node_dump_dict, indent=2)
logging.debug(f"Raw TLV contents of Node: {json_dump_string}")

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)
return (json_dump_string, pformat(self.endpoints, indent=1, width=200, compact=True))

async def setup_class_helper(self, default_to_pase: bool = True):
dev_ctrl = self.default_controller
Expand Down

0 comments on commit 3472850

Please sign in to comment.