Xinyu Zhang | 0f78e7a | 2022-10-17 13:55:52 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | __copyright__ = """ |
| 4 | /* |
| 5 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 6 | * |
| 7 | * SPDX-License-Identifier: BSD-3-Clause |
| 8 | * |
| 9 | */ |
| 10 | """ |
| 11 | |
| 12 | """ |
| 13 | Script to create report summary CSV file. |
| 14 | """ |
| 15 | |
| 16 | import csv |
| 17 | import argparse |
| 18 | |
| 19 | |
| 20 | def get_extra_config_name(extra_param): |
| 21 | return extra_param.replace(', ', '_') if extra_param != 'N.A' else ' Default' |
| 22 | |
| 23 | |
| 24 | def generate_headers(config_results): |
| 25 | |
| 26 | # Keys: [CONFIG_NAME, TFM_PLATFORM, COMPILER, LIB_MODEL, ISOLATION_LEVEL, TEST_REGRESSION, |
| 27 | # TEST_PSA_API, CMAKE_BUILD_TYPE, BL2, PROFILE, EXTRA_PARAMS, RESULT] |
| 28 | |
| 29 | common_params = list(config_results[0].keys())[1:-2] |
| 30 | extra_params = set() |
| 31 | |
| 32 | for config in config_results: |
| 33 | extra_params.add(get_extra_config_name(config['EXTRA_PARAMS'])) |
| 34 | |
| 35 | csv_headers = common_params + sorted(list(extra_params)) |
| 36 | return csv_headers |
| 37 | |
| 38 | |
| 39 | def generate_result_rows(config_results): |
| 40 | for config in config_results: |
| 41 | config[get_extra_config_name(config['EXTRA_PARAMS'])] = config['RESULT'] |
| 42 | return sorted(config_results, key = lambda x: x['TFM_PLATFORM']) |
| 43 | |
| 44 | |
| 45 | def main(user_args): |
| 46 | with open(user_args.input_file, newline='') as csvfile: |
| 47 | config_results = csv.DictReader(csvfile) |
| 48 | config_results = [dict(config) for config in config_results] |
| 49 | csv_headers = generate_headers(config_results) |
| 50 | with open(user_args.output_file, 'w', newline='') as csvfile: |
| 51 | writer = csv.DictWriter(csvfile, fieldnames=csv_headers, restval='', extrasaction='ignore') |
| 52 | writer.writeheader() |
| 53 | writer.writerows(generate_result_rows(config_results)) |
| 54 | |
| 55 | |
| 56 | def get_cmd_args(): |
| 57 | """Parse command line arguments""" |
| 58 | |
| 59 | # Parse command line arguments to override config |
| 60 | parser = argparse.ArgumentParser(description="Create CSV report file") |
| 61 | cmdargs = parser.add_argument_group("Create CSV file") |
| 62 | |
| 63 | # Configuration control |
| 64 | cmdargs.add_argument( |
| 65 | "--input-file", |
| 66 | dest="input_file", |
| 67 | action="store", |
| 68 | help="Build or test result of the config", |
| 69 | ) |
| 70 | cmdargs.add_argument( |
| 71 | "--output-file", |
| 72 | dest="output_file", |
| 73 | action="store", |
| 74 | help="File name of CSV report", |
| 75 | ) |
| 76 | |
| 77 | return parser.parse_args() |
| 78 | |
| 79 | if __name__ == "__main__": |
| 80 | main(get_cmd_args()) |