Skip to content

Commit

Permalink
Also write to a log file by default
Browse files Browse the repository at this point in the history
Write the log of outcome analysis to a log file by default. This is a cheap
way of getting the outcome analysis log in an easy-to-access form on the CI:
with our current CI scripts, they are now automatically available as an
artifact called `analyze_outcomes.log`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
  • Loading branch information
gilles-peskine-arm committed Oct 9, 2024
1 parent 48c005f commit 67e415f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions scripts/mbedtls_framework/outcome_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,20 @@
class Results:
"""Process analysis results."""

def __init__(self):
def __init__(self,
stderr: bool = True,
log_file: str = '') -> None:
"""Log and count errors.
Log to stderr if stderr is true.
Log to log_file if specified and non-empty.
"""
self.error_count = 0
self.warning_count = 0
self.stderr = stderr
self.log_file = None
if log_file:
self.log_file = open(log_file, 'w', encoding='utf-8')

def new_section(self, fmt, *args, **kwargs):
self._print_line('\n*** ' + fmt + ' ***\n', *args, **kwargs)
Expand All @@ -65,9 +76,12 @@ def warning(self, fmt, *args, **kwargs):
self.warning_count += 1
self._print_line('Warning: ' + fmt, *args, **kwargs)

@staticmethod
def _print_line(fmt, *args, **kwargs):
sys.stderr.write((fmt + '\n').format(*args, **kwargs))
def _print_line(self, fmt, *args, **kwargs):
line = (fmt + '\n').format(*args, **kwargs)
if self.stderr:
sys.stderr.write(line)
if self.log_file:
self.log_file.write(line)

def execute_reference_driver_tests(results: Results, ref_component: str, driver_component: str, \
outcome_file: str) -> None:
Expand Down Expand Up @@ -284,8 +298,6 @@ def run(self, results: Results, outcomes: Outcomes) -> None:


def main(known_tasks: typing.Dict[str, typing.Type[Task]]) -> None:
main_results = Results()

try:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Expand All @@ -297,6 +309,10 @@ def main(known_tasks: typing.Dict[str, typing.Type[Task]]) -> None:
'comma/space-separated list of tasks. ')
parser.add_argument('--list', action='store_true',
help='List all available tasks and exit.')
parser.add_argument('--log-file',
default='tests/analyze_outcomes.log',
help='Log file (default: tests/analyze_outcomes.log;'
' empty means no log file)')
parser.add_argument('--require-full-coverage', action='store_true',
dest='full_coverage', help="Require all available "
"test cases to be executed and issue an error "
Expand All @@ -309,6 +325,8 @@ def main(known_tasks: typing.Dict[str, typing.Type[Task]]) -> None:
print(task_name)
sys.exit(0)

main_results = Results(log_file=options.log_file)

if options.specified_tasks == 'all':
tasks_list = list(known_tasks.keys())
else:
Expand Down

0 comments on commit 67e415f

Please sign in to comment.