Skip to content

Commit 740b553

Browse files
authored
handle lcov end line number (#105)
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 3b0abdb commit 740b553

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

fastcov.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,10 @@ def parseInfo(path):
807807
})
808808
current_data = fastcov_json["sources"][current_sf][current_test_name]
809809
elif line.startswith("FN:"):
810-
line_num, function_name = line[3:].strip().split(",")
810+
line_nums, function_name = line[3:].strip().rsplit(",", maxsplit=1)
811+
line_num_start = line_nums.split(",")[0]
811812
current_data["functions"][function_name] = {}
812-
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num)
813+
current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num_start)
813814
elif line.startswith("FNDA:"):
814815
count, function_name = line[5:].strip().split(",")
815816
current_data["functions"][function_name]["execution_count"] = tryParseNumber(count)
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,_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,_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
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

+4
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
# Combine operation - Missing TN
133137
coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/test1.no_tn.info --lcov -o test1.no_tn.actual.info
134138
cmp test1.no_tn.actual.info ${TEST_DIR}/expected_results/combine5.expected.info

0 commit comments

Comments
 (0)