|
6 | 6 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
7 | 7 | """Test tool."""
|
8 | 8 |
|
| 9 | +import math |
9 | 10 | import os
|
10 | 11 | import csv
|
11 | 12 | import pickle
|
@@ -94,6 +95,9 @@ def add_tool_arguments(self, parser, defaults):
|
94 | 95 | help='exit with status FAIL(2) if the test result'
|
95 | 96 | ' is less than this value.',
|
96 | 97 | metavar='<float>')
|
| 98 | + parser.add_argument('--calculate-average', |
| 99 | + action="store_true", |
| 100 | + help='calculate the average score of every test run') |
97 | 101 | super(Tool, self).add_tool_arguments(parser, defaults)
|
98 | 102 |
|
99 | 103 | def _build_test_case(self):
|
@@ -226,6 +230,19 @@ def _handle_results(self) -> ReturnCode:
|
226 | 230 | if not options.verbose:
|
227 | 231 | self.context.o.auto('\n')
|
228 | 232 |
|
| 233 | + if options.calculate_average: |
| 234 | + # Calculate and print the average score |
| 235 | + score_sum = 0.0 |
| 236 | + num_tests = 0 |
| 237 | + for test_case in self._test_cases: |
| 238 | + score = test_case.score |
| 239 | + if not test_case.error and not math.isnan(score): |
| 240 | + score_sum += test_case.score |
| 241 | + num_tests += 1 |
| 242 | + |
| 243 | + if num_tests != 0: |
| 244 | + print("@avg: ({:.4f})".format(score_sum/num_tests)) |
| 245 | + |
229 | 246 | summary_path = os.path.join(options.results_directory, 'summary.csv')
|
230 | 247 | with open(summary_path, mode='w', newline='') as fp:
|
231 | 248 | writer = csv.writer(fp, delimiter=',')
|
|
0 commit comments