Skip to content

Commit a3cedc0

Browse files
committed
handle lcov end line number
According to the lcov documentation, `FN` field can contain optional end line number. Right now the code crashes in this case. This commit makes sure it doesn't and it's well parsed. Ref: https://manpages.ubuntu.com/manpages/noble/man1/geninfo.1.html ``` Following is a list of line numbers for each function name found in the source file: FN:<line number of function start>,(<line number of function end>,)?<function name> The 'end' line number is optional, and is generated only if the compiler/toolchain version is recent enough to generate the data (e.g., gcc 9 or newer). ```
1 parent 900877e commit a3cedc0

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

fastcov.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,10 @@ def parseInfo(path):
806806
})
807807
current_data = fastcov_json["sources"][current_sf][current_test_name]
808808
elif line.startswith("FN:"):
809-
line_num, function_name = line[3:].strip().split(",")
809+
line_nums, function_name = line[3:].strip().rsplit(",", maxsplit=1)
810+
line_num_start = line_nums.split(",")[0]
810811
current_data["functions"][function_name] = {}
811-
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num)
812+
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num_start)
812813
elif line.startswith("FNDA:"):
813814
count, function_name = line[5:].strip().split(",")
814815
current_data["functions"][function_name]["execution_count"] = tryParseNumber(count)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TN:
2+
SF:/mnt/workspace/test/functional/cmake_project/src/source1.cpp
3+
FN:3,10,_Z3foob
4+
FNDA:1,_Z3foob
5+
FNF:1
6+
FNH:1
7+
DA:3,1
8+
DA:5,1
9+
DA:7,1001
10+
DA:8,1000
11+
DA:10,1000
12+
DA:11,0
13+
DA:14,1
14+
LF:7
15+
LH:6
16+
end_of_record
17+
TN:
18+
SF:/mnt/workspace/test/functional/cmake_project/src/source2.cpp
19+
FN:3,10,_Z3barbii
20+
FNDA:10,_Z3barbii
21+
FNF:1
22+
FNH:1
23+
DA:3,10
24+
DA:5,10
25+
DA:6,10
26+
DA:8,0
27+
LF:4
28+
LH:3
29+
end_of_record

test/functional/run_all.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ cmp combine3.actual.info ${TEST_DIR}/expected_results/combine3.expected.info
129129
coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/combine4a.info ${TEST_DIR}/expected_results/combine4b.info ${TEST_DIR}/expected_results/combine4c.info --lcov -o combine4.actual.info
130130
cmp combine4.actual.info ${TEST_DIR}/expected_results/combine4.expected.info
131131

132+
# Combine operation - End line number in FN
133+
coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/test1.end_line_number_fn.info --lcov -o test1.end_line_number_fn.actual.info
134+
cmp test1.end_line_number_fn.actual.info ${TEST_DIR}/expected_results/combine6.expected.info
135+
132136
# Run ctest_2
133137
${TEST_DIR}/fastcov.py --gcov gcov-9 --zerocounters # Clear previous test coverage
134138
ctest -R ctest_2

0 commit comments

Comments
 (0)