2020-06-25 18:36:28 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""Analyze the test outcomes from a full CI run.
|
|
|
|
|
|
|
|
This script can also run on outcomes from a partial run, but the results are
|
|
|
|
less likely to be useful.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
2020-06-25 18:37:43 +02:00
|
|
|
import check_test_cases
|
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
class Results:
|
|
|
|
"""Process analysis results."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.error_count = 0
|
|
|
|
self.warning_count = 0
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def log(fmt, *args, **kwargs):
|
|
|
|
sys.stderr.write((fmt + '\n').format(*args, **kwargs))
|
|
|
|
|
|
|
|
def error(self, fmt, *args, **kwargs):
|
|
|
|
self.log('Error: ' + fmt, *args, **kwargs)
|
|
|
|
self.error_count += 1
|
|
|
|
|
|
|
|
def warning(self, fmt, *args, **kwargs):
|
|
|
|
self.log('Warning: ' + fmt, *args, **kwargs)
|
|
|
|
self.warning_count += 1
|
|
|
|
|
|
|
|
class TestCaseOutcomes:
|
|
|
|
"""The outcomes of one test case across many configurations."""
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
|
|
|
|
def __init__(self):
|
2020-06-26 13:02:30 +02:00
|
|
|
# Collect a list of witnesses of the test case succeeding or failing.
|
|
|
|
# Currently we don't do anything with witnesses except count them.
|
|
|
|
# The format of a witness is determined by the read_outcome_file
|
|
|
|
# function; it's the platform and configuration joined by ';'.
|
2020-06-25 18:36:28 +02:00
|
|
|
self.successes = []
|
|
|
|
self.failures = []
|
|
|
|
|
|
|
|
def hits(self):
|
|
|
|
"""Return the number of times a test case has been run.
|
|
|
|
|
|
|
|
This includes passes and failures, but not skips.
|
|
|
|
"""
|
|
|
|
return len(self.successes) + len(self.failures)
|
|
|
|
|
2020-06-25 18:37:43 +02:00
|
|
|
def analyze_coverage(results, outcomes):
|
|
|
|
"""Check that all available test cases are executed at least once."""
|
2022-01-07 15:58:38 +01:00
|
|
|
available = check_test_cases.collect_available_test_cases()
|
2020-06-25 18:37:43 +02:00
|
|
|
for key in available:
|
|
|
|
hits = outcomes[key].hits() if key in outcomes else 0
|
|
|
|
if hits == 0:
|
|
|
|
# Make this a warning, not an error, as long as we haven't
|
|
|
|
# fixed this branch to have full coverage of test cases.
|
|
|
|
results.warning('Test case not executed: {}', key)
|
|
|
|
|
2022-11-09 12:07:29 +01:00
|
|
|
def analyze_driver_vs_reference(outcomes, component_ref,component_driver, ignored_tests):
|
2022-10-21 13:42:08 +02:00
|
|
|
"""Check that all tests executed in the reference component are also
|
|
|
|
executed in the corresponding driver component.
|
2022-11-09 10:50:29 +01:00
|
|
|
Skip test suites provided in ignored_tests list.
|
2022-10-21 13:42:08 +02:00
|
|
|
"""
|
|
|
|
available = check_test_cases.collect_available_test_cases()
|
|
|
|
result = True
|
|
|
|
|
|
|
|
for key in available:
|
|
|
|
# Skip ignored test suites
|
2022-11-09 10:50:29 +01:00
|
|
|
test_suite = key.split(';')[0] # retrieve test suit name
|
|
|
|
test_suite = test_suite.split('.')[0] # retrieve main part of test suit name
|
|
|
|
if test_suite in ignored_tests:
|
2022-10-21 13:42:08 +02:00
|
|
|
continue
|
|
|
|
# Continue if test was not executed by any component
|
|
|
|
hits = outcomes[key].hits() if key in outcomes else 0
|
2022-10-24 09:16:04 +02:00
|
|
|
if hits == 0:
|
2022-10-21 13:42:08 +02:00
|
|
|
continue
|
|
|
|
# Search for tests that run in reference component and not in driver component
|
|
|
|
driver_test_passed = False
|
|
|
|
reference_test_passed = False
|
|
|
|
for entry in outcomes[key].successes:
|
2022-11-09 12:07:29 +01:00
|
|
|
if component_driver in entry:
|
2022-10-21 13:42:08 +02:00
|
|
|
driver_test_passed = True
|
2022-11-09 12:07:29 +01:00
|
|
|
if component_ref in entry:
|
2022-10-21 13:42:08 +02:00
|
|
|
reference_test_passed = True
|
2022-10-24 09:16:04 +02:00
|
|
|
if(driver_test_passed is False and reference_test_passed is True):
|
2022-10-21 13:42:08 +02:00
|
|
|
print('{}: driver: skipped/failed; reference: passed'.format(key))
|
|
|
|
result = False
|
|
|
|
return result
|
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
def analyze_outcomes(outcomes):
|
|
|
|
"""Run all analyses on the given outcome collection."""
|
|
|
|
results = Results()
|
2020-06-25 18:37:43 +02:00
|
|
|
analyze_coverage(results, outcomes)
|
2020-06-25 18:36:28 +02:00
|
|
|
return results
|
|
|
|
|
|
|
|
def read_outcome_file(outcome_file):
|
|
|
|
"""Parse an outcome file and return an outcome collection.
|
|
|
|
|
|
|
|
An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
|
|
|
|
The keys are the test suite name and the test case description, separated
|
|
|
|
by a semicolon.
|
|
|
|
"""
|
|
|
|
outcomes = {}
|
|
|
|
with open(outcome_file, 'r', encoding='utf-8') as input_file:
|
|
|
|
for line in input_file:
|
|
|
|
(platform, config, suite, case, result, _cause) = line.split(';')
|
|
|
|
key = ';'.join([suite, case])
|
|
|
|
setup = ';'.join([platform, config])
|
|
|
|
if key not in outcomes:
|
|
|
|
outcomes[key] = TestCaseOutcomes()
|
|
|
|
if result == 'PASS':
|
|
|
|
outcomes[key].successes.append(setup)
|
|
|
|
elif result == 'FAIL':
|
|
|
|
outcomes[key].failures.append(setup)
|
|
|
|
return outcomes
|
|
|
|
|
2022-10-26 16:11:26 +02:00
|
|
|
def do_analyze_coverage(outcome_file, args):
|
2022-11-09 10:50:29 +01:00
|
|
|
"""Perform coverage analysis."""
|
2022-10-26 16:11:26 +02:00
|
|
|
del args # unused
|
2020-06-25 18:36:28 +02:00
|
|
|
outcomes = read_outcome_file(outcome_file)
|
2022-10-21 13:42:08 +02:00
|
|
|
results = analyze_outcomes(outcomes)
|
2022-10-24 09:16:04 +02:00
|
|
|
return results.error_count == 0
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2022-10-26 16:11:26 +02:00
|
|
|
def do_analyze_driver_vs_reference(outcome_file, args):
|
2022-10-21 13:42:08 +02:00
|
|
|
"""Perform driver vs reference analyze."""
|
2022-10-26 16:11:26 +02:00
|
|
|
ignored_tests = args['ignored'].split(',')
|
|
|
|
ignored_tests = ['test_suite_' + x for x in ignored_tests]
|
2022-11-09 12:07:29 +01:00
|
|
|
|
2022-10-21 13:42:08 +02:00
|
|
|
outcomes = read_outcome_file(outcome_file)
|
2022-11-09 12:07:29 +01:00
|
|
|
return analyze_driver_vs_reference(outcomes, args['component_ref'],
|
|
|
|
args['component_driver'], ignored_tests)
|
2020-06-25 18:36:28 +02:00
|
|
|
|
2022-11-09 10:50:29 +01:00
|
|
|
# List of tasks with a function that can handle this task and additional arguments if required
|
2022-10-26 16:11:26 +02:00
|
|
|
TASKS = {
|
|
|
|
'analyze_coverage': {
|
|
|
|
'test_function': do_analyze_coverage,
|
|
|
|
'args': {}},
|
|
|
|
'analyze_driver_vs_reference_hash': {
|
|
|
|
'test_function': do_analyze_driver_vs_reference,
|
|
|
|
'args': {
|
2022-11-09 12:07:29 +01:00
|
|
|
'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
|
|
|
|
'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
|
2022-10-26 16:11:26 +02:00
|
|
|
'ignored': 'md,mdx,shax,entropy,hmac_drbg,random,psa_crypto_init,hkdf'}}
|
|
|
|
}
|
|
|
|
|
2020-06-25 18:36:28 +02:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
2022-10-24 08:10:10 +02:00
|
|
|
parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
|
2020-06-25 18:36:28 +02:00
|
|
|
help='Outcome file to analyze')
|
2022-10-26 16:11:26 +02:00
|
|
|
parser.add_argument('--task', default='all',
|
2022-11-09 10:50:29 +01:00
|
|
|
help='Analysis to be done: all or analyze_coverage or '
|
2022-10-26 16:11:26 +02:00
|
|
|
'analyze_driver_vs_reference_hash')
|
2020-06-25 18:36:28 +02:00
|
|
|
options = parser.parse_args()
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2022-10-26 16:11:26 +02:00
|
|
|
result = True
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2022-10-26 16:11:26 +02:00
|
|
|
if options.task == 'all':
|
|
|
|
for task in TASKS:
|
|
|
|
if not TASKS[task]['test_function'](options.outcomes, TASKS[task]['args']):
|
|
|
|
result = False
|
|
|
|
elif options.task in TASKS:
|
|
|
|
if not TASKS[options.task]['test_function'](options.outcomes,
|
|
|
|
TASKS[options.task]['args']):
|
|
|
|
result = False
|
2022-10-21 13:42:08 +02:00
|
|
|
else:
|
|
|
|
print('Error: Unknown task: {}'.format(options.task))
|
2022-10-26 16:11:26 +02:00
|
|
|
result = False
|
2022-10-21 13:42:08 +02:00
|
|
|
|
2022-10-24 09:16:04 +02:00
|
|
|
if result is False:
|
2020-06-25 18:36:28 +02:00
|
|
|
sys.exit(1)
|
2022-10-21 13:42:08 +02:00
|
|
|
print("SUCCESS :-)")
|
2020-06-25 18:36:28 +02:00
|
|
|
except Exception: # pylint: disable=broad-except
|
|
|
|
# Print the backtrace and exit explicitly with our chosen status.
|
|
|
|
traceback.print_exc()
|
|
|
|
sys.exit(120)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|