Skip to content

Commit e12bc2c

Browse files
committed
Fix #69
Description: - Add a bandaid for some gcov/build system issue where sometimes empty gcno/gcda crop up - Create new exit code 8 if this happens
1 parent 9bdf5b7 commit e12bc2c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

fastcov.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"unsupported_coverage_format": 5,
5151
"excl_not_found": 6,
5252
"bad_chunk_file": 7,
53+
"missing_json_key": 8,
5354
}
5455

5556
# Disable all logging in case developers are using this as a module
@@ -272,7 +273,12 @@ def gcovWorker(data_q, metrics_q, args, chunk, gcov_filter_options):
272273
except json.decoder.JSONDecodeError as e:
273274
logging.error("Could not process chunk file '{}' ({}/{})".format(chunk[i], i+1, len(chunk)))
274275
logging.error(str(e))
275-
error_exit = True
276+
setExitCode("bad_chunk_file")
277+
continue
278+
279+
if "current_working_directory" not in intermediate_json:
280+
logging.error("Missing 'current_working_directory' for data file: {}".format(intermediate_json))
281+
setExitCode("missing_json_key")
276282
continue
277283

278284
intermediate_json_files = processGcovs(args.cdirectory, intermediate_json["files"], intermediate_json["current_working_directory"], gcov_filter_options)
@@ -285,8 +291,7 @@ def gcovWorker(data_q, metrics_q, args, chunk, gcov_filter_options):
285291
data_q.put(base_report)
286292
metrics_q.put((gcovs_total, gcovs_skipped))
287293

288-
if error_exit:
289-
sys.exit(1)
294+
sys.exit(EXIT_CODE)
290295

291296
def processGcdas(args, coverage_files, gcov_filter_options):
292297
chunk_size = max(args.minimum_chunk, int(len(coverage_files) / args.jobs) + 1)
@@ -309,7 +314,7 @@ def processGcdas(args, coverage_files, gcov_filter_options):
309314
for p in processes:
310315
p.join()
311316
if p.exitcode != 0:
312-
setExitCode("bad_chunk_file")
317+
setExitCodeRaw(p.exitcode)
313318

314319
base_fastcov = fastcov_jsons.pop()
315320
for fj in fastcov_jsons:

test/functional/run_all.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ cat print_coverage.info.log | grep 'Lines Coverage: 60.00%, 9/15'
207207
coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/diff_filter_data/basic.json --diff-filter ${TEST_DIR}/expected_results/diff_filter_data/exclude_each_item.diff --diff-base-dir /mnt/workspace -o exclude_each_item.actual.json
208208
${TEST_DIR}/json_cmp.py exclude_each_item.actual.json ${TEST_DIR}/expected_results/diff_filter_data/exclude_each_item.expected.json
209209

210+
# Test (empty gcno)
211+
touch empty.gcno
212+
rc=0
213+
coverage run -a ${TEST_DIR}/fastcov.py --gcov gcov-9 --process-gcno || rc=$?
214+
test $rc -eq 8
215+
210216
# Write out coverage as xml
211217
coverage combine
212218
coverage xml -o coverage.xml

0 commit comments

Comments
 (0)