blob: f4837c00b2554900c0a6eafb72a9f71e97f67ab8 [file] [log] [blame]
Adithya Baglody131edad2018-09-05 14:36:37 +05301#!/usr/bin/env python3
2#
3# Copyright (c) 2018 Intel Corporation
4#
5# SPDX-License-Identifier: Apache-2.0
6
Ruslan Mstoie406c9c2020-06-03 18:05:30 +03007
8"""This script will parse the serial console log file and create the required
9gcda files.
10"""
Adithya Baglody131edad2018-09-05 14:36:37 +053011
12import argparse
13import os
14import re
15
Ruslan Mstoi69b07e32020-06-03 17:55:39 +030016
Adithya Baglody131edad2018-09-05 14:36:37 +053017def retrieve_data(input_file):
18 extracted_coverage_info = {}
19 capture_data = False
Anas Nashifa34f3712019-01-25 09:26:39 -050020 reached_end = False
Adithya Baglody131edad2018-09-05 14:36:37 +053021 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 Nashifa34f3712019-01-25 09:26:39 -050027 reached_end = True
Adithya Baglody131edad2018-09-05 14:36:37 +053028 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 Mstoi69b07e32020-06-03 17:55:39 +030037 extracted_coverage_info.update({file_name: hex_dump})
Anas Nashifa34f3712019-01-25 09:26:39 -050038
39 if not reached_end:
Ruslan Mstoi69b07e32020-06-03 17:55:39 +030040 print("incomplete data captured from %s" % input_file)
Adithya Baglody131edad2018-09-05 14:36:37 +053041 return extracted_coverage_info
42
Ruslan Mstoi69b07e32020-06-03 17:55:39 +030043
Adithya Baglody131edad2018-09-05 14:36:37 +053044def 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 Magnusson16b548f2019-09-05 19:16:10 +020053 filename = filename[:-4] + "gcno"
Adithya Baglody131edad2018-09-05 14:36:37 +053054 try:
55 os.remove(filename)
Ulf Magnusson16b548f2019-09-05 19:16:10 +020056 except Exception:
Adithya Baglody131edad2018-09-05 14:36:37 +053057 pass
58 continue
59
60 with open(filename, 'wb') as fp:
61 fp.write(bytes.fromhex(hexdump_val))
62
63
64def 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 Baglody131edad2018-09-05 14:36:37 +053076def 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
84if __name__ == '__main__':
85 main()