blob: 10c2f2f94b79544e46c804ede7baa2393e005a3d [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
7# This script will parse the serial console log file and create the required
8# gcda files.
9# Usage python3 ${ZEPHYR_BASE}/scripts/gen_gcov_files.py -i console_output.log
10# Add -v for verbose
11
12import argparse
13import os
14import re
15
16def retrieve_data(input_file):
17 extracted_coverage_info = {}
18 capture_data = False
Anas Nashifa34f3712019-01-25 09:26:39 -050019 reached_end = False
Adithya Baglody131edad2018-09-05 14:36:37 +053020 with open(input_file, 'r') as fp:
21 for line in fp.readlines():
22 if re.search("GCOV_COVERAGE_DUMP_START", line):
23 capture_data = True
24 continue
25 if re.search("GCOV_COVERAGE_DUMP_END", line):
Anas Nashifa34f3712019-01-25 09:26:39 -050026 reached_end = True
Adithya Baglody131edad2018-09-05 14:36:37 +053027 break
28 # Loop until the coverage data is found.
29 if not capture_data:
30 continue
31
32 # Remove the leading delimiter "*"
33 file_name = line.split("<")[0][1:]
34 # Remove the trailing new line char
35 hex_dump = line.split("<")[1][:-1]
36 extracted_coverage_info.update({file_name:hex_dump})
Anas Nashifa34f3712019-01-25 09:26:39 -050037
38 if not reached_end:
39 print("incomplete data captured from %s" %input_file)
Adithya Baglody131edad2018-09-05 14:36:37 +053040 return extracted_coverage_info
41
42def create_gcda_files(extracted_coverage_info):
43 if args.verbose:
44 print("Generating gcda files")
45 for filename, hexdump_val in extracted_coverage_info.items():
46 if args.verbose:
47 print(filename)
48 # if kobject_hash is given for coverage gcovr fails
49 # hence skipping it problem only in gcovr v4.1
50 if "kobject_hash" in filename:
Ulf Magnusson16b548f2019-09-05 19:16:10 +020051 filename = filename[:-4] + "gcno"
Adithya Baglody131edad2018-09-05 14:36:37 +053052 try:
53 os.remove(filename)
Ulf Magnusson16b548f2019-09-05 19:16:10 +020054 except Exception:
Adithya Baglody131edad2018-09-05 14:36:37 +053055 pass
56 continue
57
58 with open(filename, 'wb') as fp:
59 fp.write(bytes.fromhex(hexdump_val))
60
61
62def parse_args():
63 global args
64 parser = argparse.ArgumentParser(
65 description=__doc__,
66 formatter_class=argparse.RawDescriptionHelpFormatter)
67 parser.add_argument("-i", "--input", required=True,
68 help="Input dump data")
69 parser.add_argument("-v", "--verbose", action="count", default=0,
70 help="Verbose Output")
71 args = parser.parse_args()
72
73
74
75def main():
76 parse_args()
77 input_file = args.input
78
79 extracted_coverage_info = retrieve_data(input_file)
80 create_gcda_files(extracted_coverage_info)
81
82
83if __name__ == '__main__':
84 main()