Skip to content

Commit 2c5d849

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
gcov.py: Supports parsing multiple sets of gcov outputs at the same time and merging the results
Use the "-a" parameter to pass in gcda files exported by multiple devices Signed-off-by: wangmingrong1 <[email protected]>
1 parent 66e074e commit 2c5d849

File tree

1 file changed

+59
-25
lines changed

1 file changed

+59
-25
lines changed

tools/gcov.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,22 @@ def arg_parser():
107107
)
108108
parser.add_argument("-i", "--input", help="Input dump data")
109109
parser.add_argument("-t", dest="gcov_tool", help="Path to gcov tool")
110-
parser.add_argument("-b", dest="base_dir", help="Compile base directory")
111-
parser.add_argument("-s", dest="gcno_dir", help="Directory containing gcno files")
112-
parser.add_argument("-a", dest="gcda_dir", help="Directory containing gcda files")
110+
parser.add_argument(
111+
"-b", dest="base_dir", default=os.getcwd(), help="Compile base directory"
112+
)
113+
parser.add_argument(
114+
"-s",
115+
dest="gcno_dir",
116+
default=os.getcwd(),
117+
help="Directory containing gcno files",
118+
)
119+
parser.add_argument(
120+
"-a",
121+
dest="gcda_dir",
122+
default=os.getcwd(),
123+
nargs="+",
124+
help="Directory containing gcda files",
125+
)
113126
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
114127
parser.add_argument(
115128
"-x",
@@ -118,7 +131,8 @@ def arg_parser():
118131
help="Only copy *.gcno and *.gcda files",
119132
)
120133
parser.add_argument(
121-
"gcov_dir",
134+
"-o",
135+
dest="gcov_dir",
122136
nargs="?",
123137
default=os.getcwd(),
124138
help="Directory to store gcov data and report",
@@ -132,12 +146,19 @@ def main():
132146

133147
root_dir = os.getcwd()
134148
gcov_dir = os.path.abspath(args.gcov_dir)
135-
gcno_dir = os.path.abspath(args.gcno_dir) if args.gcno_dir else root_dir
136-
gcda_dir = os.path.abspath(args.gcda_dir) if args.gcda_dir else root_dir
149+
gcno_dir = os.path.abspath(args.gcno_dir)
150+
151+
if os.path.exists(gcov_dir):
152+
shutil.rmtree(gcov_dir)
153+
154+
os.makedirs(gcov_dir)
155+
156+
gcda_dir = []
157+
for i in args.gcda_dir:
158+
gcda_dir.append(os.path.abspath(i))
137159

138160
coverage_file = os.path.join(gcov_dir, "coverage.info")
139161
result_dir = os.path.join(gcov_dir, "result")
140-
gcov_data_dir = os.path.join(gcov_dir, "data")
141162

142163
if args.debug:
143164
debug_file = os.path.join(gcov_dir, "debug.log")
@@ -146,11 +167,17 @@ def main():
146167
if args.input:
147168
parse_gcda_data(os.path.join(root_dir, args.input))
148169

149-
os.makedirs(os.path.join(gcov_dir, "data"), exist_ok=True)
170+
gcov_data_dir = []
150171

151172
# Collect gcno, gcda files
152-
copy_file_endswith(".gcno", gcno_dir, gcov_data_dir)
153-
copy_file_endswith(".gcda", gcda_dir, gcov_data_dir)
173+
for i in gcda_dir:
174+
175+
dir = os.path.join(gcov_dir + "/data", os.path.basename(i))
176+
gcov_data_dir.append(dir)
177+
os.makedirs(dir)
178+
179+
copy_file_endswith(".gcno", gcno_dir, dir)
180+
copy_file_endswith(".gcda", i, dir)
154181

155182
# Only copy files
156183
if args.only_copy:
@@ -166,21 +193,26 @@ def main():
166193
try:
167194

168195
# lcov collect coverage data to coverage_file
196+
command = [
197+
"lcov",
198+
"-c",
199+
"-o",
200+
coverage_file,
201+
"--rc",
202+
"lcov_branch_coverage=1",
203+
"--gcov-tool",
204+
args.gcov_tool,
205+
"--ignore-errors",
206+
"gcov",
207+
]
208+
for i in gcov_data_dir:
209+
command.append("-d")
210+
command.append(i)
211+
212+
print(command)
213+
169214
subprocess.run(
170-
[
171-
"lcov",
172-
"-c",
173-
"-d",
174-
gcov_data_dir,
175-
"-o",
176-
coverage_file,
177-
"--rc",
178-
"lcov_branch_coverage=1",
179-
"--gcov-tool",
180-
args.gcov_tool,
181-
"--ignore-errors",
182-
"gcov",
183-
],
215+
command,
184216
check=True,
185217
stdout=sys.stdout,
186218
stderr=sys.stdout,
@@ -214,7 +246,9 @@ def main():
214246
print("Failed to generate coverage file.")
215247
sys.exit(1)
216248

217-
shutil.rmtree(gcov_data_dir)
249+
for i in gcov_data_dir:
250+
shutil.rmtree(i)
251+
218252
os.remove(coverage_file)
219253

220254

0 commit comments

Comments
 (0)