3
3
# Copyright (c) 2018-2025 Intel Corporation
4
4
# SPDX-License-Identifier: Apache-2.0
5
5
6
+ import collections
6
7
import contextlib
7
8
import filecmp
8
9
import glob
@@ -52,7 +53,7 @@ def factory(tool, jobs=None):
52
53
@staticmethod
53
54
def retrieve_gcov_data (input_file ):
54
55
logger .debug (f"Working on { input_file } " )
55
- extracted_coverage_info = {}
56
+ extracted_coverage_info = collections . defaultdict ( list )
56
57
capture_data = False
57
58
capture_complete = False
58
59
with open (input_file ) as fp :
@@ -78,10 +79,8 @@ def retrieve_gcov_data(input_file):
78
79
continue
79
80
else :
80
81
continue
81
- if file_name in extracted_coverage_info :
82
- extracted_coverage_info [file_name ].append (hex_dump )
83
- else :
84
- extracted_coverage_info [file_name ] = [hex_dump ]
82
+ hex_bytes = bytes .fromhex (hex_dump )
83
+ extracted_coverage_info [file_name ].append (hex_bytes )
85
84
if not capture_data :
86
85
capture_complete = True
87
86
return {'complete' : capture_complete , 'data' : extracted_coverage_info }
@@ -99,7 +98,7 @@ def merge_hexdumps(self, hexdumps):
99
98
os .mkdir (subdir )
100
99
dirs .append (subdir )
101
100
with open (f'{ subdir } /tmp.gcda' , 'wb' ) as fp :
102
- fp .write (bytes . fromhex ( dump ) )
101
+ fp .write (dump )
103
102
104
103
# Iteratively call gcov-tool (not gcov) to merge the files
105
104
merge_tool = self .gcov_tool + '-tool'
@@ -109,7 +108,7 @@ def merge_hexdumps(self, hexdumps):
109
108
110
109
# Read back the final output file
111
110
with open (f'{ dirs [- 1 ]} /tmp.gcda' , 'rb' ) as fp :
112
- return fp .read (- 1 ). hex ()
111
+ return fp .read (- 1 )
113
112
114
113
def create_gcda_files (self , extracted_coverage_info ):
115
114
gcda_created = True
@@ -125,9 +124,8 @@ def create_gcda_files(self, extracted_coverage_info):
125
124
126
125
try :
127
126
hexdump_val = self .merge_hexdumps (hexdumps )
128
- hex_bytes = bytes .fromhex (hexdump_val )
129
127
with open (filename , 'wb' ) as fp :
130
- fp .write (hex_bytes )
128
+ fp .write (hexdump_val )
131
129
except ValueError :
132
130
logger .exception (f"Unable to convert hex data for file: { filename } " )
133
131
gcda_created = False
0 commit comments