-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Debug] Add automatic device attribute dump on composition test failures #41020
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
base: master
Are you sure you want to change the base?
Changes from 15 commits
c6908e9
e2154ab
9c36c19
5edf777
1438550
9abde9b
dc5df9e
6756ca7
10f1ca6
a026a85
b1b1a4e
b149ff6
6992404
fee2649
855d881
13fb594
530ac3a
f2fc773
7c93c8c
914426f
127cb15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,7 +206,7 @@ def setup_class(self): | |
| self.stored_global_wildcard = None | ||
|
|
||
| def teardown_class(self): | ||
| """Final teardown after all tests: log all problems. | ||
| """Final teardown after all tests: log all problems and dump device attributes if available. | ||
| Test authors may overwrite this method in the derived class to perform teardown that is common for all tests | ||
| This function is called only once per class. To perform teardown after each test, use teardown_test. | ||
| Test authors that implement steps in this function need to be careful of step handling if there is | ||
|
|
@@ -222,8 +222,54 @@ def teardown_class(self): | |
| for problem in self.problems: | ||
| LOGGER.info(str(problem)) | ||
| LOGGER.info("###########################################################") | ||
|
|
||
| # Attempt to dump device attribute data for debugging when problems are found | ||
| self._dump_device_attributes_on_failure() | ||
|
||
| super().teardown_class() | ||
|
|
||
| def _dump_device_attributes_on_failure(self): | ||
| """ | ||
| Dump device attribute data when problems are found for debugging purposes. | ||
|
|
||
| This method attempts to generate a device attribute dump if the test has | ||
| collected endpoint data. It's designed to be safe and not interfere with | ||
| the original test failure reporting. | ||
| """ | ||
| try: | ||
| # Check if we have endpoints_tlv data (from BasicCompositionTests or similar) | ||
| if hasattr(self, 'endpoints_tlv') and self.endpoints_tlv: | ||
| LOGGER.info("MatterBaseTest: Problems detected - generating device attribute dump") | ||
|
|
||
| # Check if we have the dump_wildcard method (from BasicCompositionTests) | ||
| if hasattr(self, 'dump_wildcard'): | ||
| LOGGER.info("Device attribute data available - generating dump") | ||
| _, txt_str = self.dump_wildcard(None) | ||
| # Only dump the text format - it's more readable for debugging | ||
| self._log_structured_data('==== FAILURE_DUMP_txt: ', txt_str) | ||
| else: | ||
|
||
| LOGGER.info("dump_wildcard method not available - skipping device attribute dump") | ||
| else: | ||
| LOGGER.debug("No device attribute data available (endpoints_tlv not populated)") | ||
| except Exception as e: | ||
|
||
| # Don't let logging errors interfere with the original test failure | ||
| LOGGER.warning(f"Failed to generate device attribute dump: {e}") | ||
|
|
||
| def _log_structured_data(self, start_tag: str, dump_string: str): | ||
|
||
| """Log structured data with a clear start and end marker. | ||
|
|
||
| This function is used to output device attribute dumps and other structured | ||
| data to logs in a format that can be easily extracted for debugging. | ||
|
|
||
| Args: | ||
| start_tag: A prefix tag to identify the type of data being logged | ||
| dump_string: The data to be logged | ||
| """ | ||
| lines = dump_string.splitlines() | ||
| LOGGER.info(f'{start_tag}BEGIN ({len(lines)} lines)====') | ||
| for line in lines: | ||
| LOGGER.info(f'{start_tag}{line}') | ||
| LOGGER.info(f'{start_tag}END ====') | ||
|
|
||
| def setup_test(self): | ||
| """Set up for each individual test execution. | ||
|
|
||
|
|
||
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.
We're about to update the restyler so this doesn't happen - there was a bug in the restyler that is causing this weirdness. When that lands, would you mind reverting these changes? I think this might break python prior to 3.12.
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.
Merged in master after the PR for your restylizer change got merged and reverted the changes for the f-str lines in this file here now.