Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (c) 2018 Intel Corporation |
| 4 | # |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
Ruslan Mstoi | e406c9c | 2020-06-03 18:05:30 +0300 | [diff] [blame] | 7 | |
| 8 | """This script will parse the serial console log file and create the required |
| 9 | gcda files. |
| 10 | """ |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 11 | |
| 12 | import argparse |
| 13 | import os |
| 14 | import re |
| 15 | |
Ruslan Mstoi | 69b07e3 | 2020-06-03 17:55:39 +0300 | [diff] [blame] | 16 | |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 17 | def retrieve_data(input_file): |
| 18 | extracted_coverage_info = {} |
| 19 | capture_data = False |
Anas Nashif | a34f371 | 2019-01-25 09:26:39 -0500 | [diff] [blame] | 20 | reached_end = False |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 21 | with open(input_file, 'r') as fp: |
| 22 | for line in fp.readlines(): |
| 23 | if re.search("GCOV_COVERAGE_DUMP_START", line): |
| 24 | capture_data = True |
| 25 | continue |
| 26 | if re.search("GCOV_COVERAGE_DUMP_END", line): |
Anas Nashif | a34f371 | 2019-01-25 09:26:39 -0500 | [diff] [blame] | 27 | reached_end = True |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 28 | break |
| 29 | # Loop until the coverage data is found. |
| 30 | if not capture_data: |
| 31 | continue |
| 32 | |
| 33 | # Remove the leading delimiter "*" |
| 34 | file_name = line.split("<")[0][1:] |
| 35 | # Remove the trailing new line char |
| 36 | hex_dump = line.split("<")[1][:-1] |
Ruslan Mstoi | 69b07e3 | 2020-06-03 17:55:39 +0300 | [diff] [blame] | 37 | extracted_coverage_info.update({file_name: hex_dump}) |
Anas Nashif | a34f371 | 2019-01-25 09:26:39 -0500 | [diff] [blame] | 38 | |
| 39 | if not reached_end: |
Ruslan Mstoi | 69b07e3 | 2020-06-03 17:55:39 +0300 | [diff] [blame] | 40 | print("incomplete data captured from %s" % input_file) |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 41 | return extracted_coverage_info |
| 42 | |
Ruslan Mstoi | 69b07e3 | 2020-06-03 17:55:39 +0300 | [diff] [blame] | 43 | |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 44 | def create_gcda_files(extracted_coverage_info): |
| 45 | if args.verbose: |
| 46 | print("Generating gcda files") |
| 47 | for filename, hexdump_val in extracted_coverage_info.items(): |
| 48 | if args.verbose: |
| 49 | print(filename) |
| 50 | # if kobject_hash is given for coverage gcovr fails |
| 51 | # hence skipping it problem only in gcovr v4.1 |
| 52 | if "kobject_hash" in filename: |
Ulf Magnusson | 16b548f | 2019-09-05 19:16:10 +0200 | [diff] [blame] | 53 | filename = filename[:-4] + "gcno" |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 54 | try: |
| 55 | os.remove(filename) |
Ulf Magnusson | 16b548f | 2019-09-05 19:16:10 +0200 | [diff] [blame] | 56 | except Exception: |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 57 | pass |
| 58 | continue |
| 59 | |
| 60 | with open(filename, 'wb') as fp: |
| 61 | fp.write(bytes.fromhex(hexdump_val)) |
| 62 | |
| 63 | |
| 64 | def parse_args(): |
| 65 | global args |
| 66 | parser = argparse.ArgumentParser( |
| 67 | description=__doc__, |
| 68 | formatter_class=argparse.RawDescriptionHelpFormatter) |
| 69 | parser.add_argument("-i", "--input", required=True, |
| 70 | help="Input dump data") |
| 71 | parser.add_argument("-v", "--verbose", action="count", default=0, |
| 72 | help="Verbose Output") |
| 73 | args = parser.parse_args() |
| 74 | |
| 75 | |
Adithya Baglody | 131edad | 2018-09-05 14:36:37 +0530 | [diff] [blame] | 76 | def main(): |
| 77 | parse_args() |
| 78 | input_file = args.input |
| 79 | |
| 80 | extracted_coverage_info = retrieve_data(input_file) |
| 81 | create_gcda_files(extracted_coverage_info) |
| 82 | |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | main() |