twister: Add test suite filtering on twister.json compose
When Twister composes resulting twister.json reports, add optional filtering by a test instance resulting status and/or its individual properties to be allowed/denied on output to the JSON file. This internal feature is introduced to facilitate JSON reports with a custom data schema. Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
This commit is contained in:
parent
1ef42731fd
commit
a425db20b1
1 changed files with 16 additions and 1 deletions
|
@ -234,7 +234,7 @@ class Reporting:
|
|||
with open(filename, 'wb') as report:
|
||||
report.write(result)
|
||||
|
||||
def json_report(self, filename, version="NA", platform=None):
|
||||
def json_report(self, filename, version="NA", platform=None, filters=None):
|
||||
logger.info(f"Writing JSON report {filename}")
|
||||
|
||||
if self.env.options.report_all_options:
|
||||
|
@ -261,6 +261,14 @@ class Reporting:
|
|||
continue
|
||||
if instance.status == "filtered" and not self.env.options.report_filtered:
|
||||
continue
|
||||
if (filters and 'allow_status' in filters and instance.status not in filters['allow_status']):
|
||||
logger.debug(f"Skip test suite '{instance.testsuite.name}' status '{instance.status}' "
|
||||
f"not allowed for {filename}")
|
||||
continue
|
||||
if (filters and 'deny_status' in filters and instance.status in filters['deny_status']):
|
||||
logger.debug(f"Skip test suite '{instance.testsuite.name}' status '{instance.status}' "
|
||||
f"denied for {filename}")
|
||||
continue
|
||||
suite = {}
|
||||
handler_log = os.path.join(instance.build_dir, "handler.log")
|
||||
pytest_log = os.path.join(instance.build_dir, "twister_harness.log")
|
||||
|
@ -366,6 +374,13 @@ class Reporting:
|
|||
if instance.recording is not None:
|
||||
suite['recording'] = instance.recording
|
||||
|
||||
# Pass suite properties through the context filters.
|
||||
if filters and 'allow_suite' in filters:
|
||||
suite = {k:v for k,v in suite.items() if k in filters['allow_suite']}
|
||||
|
||||
if filters and 'deny_suite' in filters:
|
||||
suite = {k:v for k,v in suite.items() if k not in filters['deny_suite']}
|
||||
|
||||
suites.append(suite)
|
||||
|
||||
report["testsuites"] = suites
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue