From a9f3f398639ccd7329ffb8c200a96ee725a20c86 Mon Sep 17 00:00:00 2001 From: Nicolas Chevrier Date: Tue, 3 Dec 2024 13:17:44 +0100 Subject: [PATCH] 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:,(,)? 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). ``` --- fastcov.py | 5 ++-- .../expected_results/combine6.expected.info | 29 +++++++++++++++++++ .../test1.end_line_number_fn.info | 29 +++++++++++++++++++ test/functional/run_all.sh | 4 +++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/functional/expected_results/combine6.expected.info create mode 100644 test/functional/expected_results/test1.end_line_number_fn.info diff --git a/fastcov.py b/fastcov.py index b8202bc..fbebd25 100755 --- a/fastcov.py +++ b/fastcov.py @@ -806,9 +806,10 @@ def parseInfo(path): }) current_data = fastcov_json["sources"][current_sf][current_test_name] elif line.startswith("FN:"): - line_num, function_name = line[3:].strip().split(",") + line_nums, function_name = line[3:].strip().rsplit(",", maxsplit=1) + line_num_start = line_nums.split(",")[0] current_data["functions"][function_name] = {} - current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num) + current_data["functions"][function_name]["start_line"] = tryParseNumber(line_num_start) elif line.startswith("FNDA:"): count, function_name = line[5:].strip().split(",") current_data["functions"][function_name]["execution_count"] = tryParseNumber(count) diff --git a/test/functional/expected_results/combine6.expected.info b/test/functional/expected_results/combine6.expected.info new file mode 100644 index 0000000..9813142 --- /dev/null +++ b/test/functional/expected_results/combine6.expected.info @@ -0,0 +1,29 @@ +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source1.cpp +FN:3,_Z3foob +FNDA:1,_Z3foob +FNF:1 +FNH:1 +DA:3,1 +DA:5,1 +DA:7,1001 +DA:8,1000 +DA:10,1000 +DA:11,0 +DA:14,1 +LF:7 +LH:6 +end_of_record +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source2.cpp +FN:3,_Z3barbii +FNDA:10,_Z3barbii +FNF:1 +FNH:1 +DA:3,10 +DA:5,10 +DA:6,10 +DA:8,0 +LF:4 +LH:3 +end_of_record diff --git a/test/functional/expected_results/test1.end_line_number_fn.info b/test/functional/expected_results/test1.end_line_number_fn.info new file mode 100644 index 0000000..b4fe284 --- /dev/null +++ b/test/functional/expected_results/test1.end_line_number_fn.info @@ -0,0 +1,29 @@ +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source1.cpp +FN:3,10,_Z3foob +FNDA:1,_Z3foob +FNF:1 +FNH:1 +DA:3,1 +DA:5,1 +DA:7,1001 +DA:8,1000 +DA:10,1000 +DA:11,0 +DA:14,1 +LF:7 +LH:6 +end_of_record +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source2.cpp +FN:3,10,_Z3barbii +FNDA:10,_Z3barbii +FNF:1 +FNH:1 +DA:3,10 +DA:5,10 +DA:6,10 +DA:8,0 +LF:4 +LH:3 +end_of_record diff --git a/test/functional/run_all.sh b/test/functional/run_all.sh index c992ed2..f6ce88a 100755 --- a/test/functional/run_all.sh +++ b/test/functional/run_all.sh @@ -129,6 +129,10 @@ cmp combine3.actual.info ${TEST_DIR}/expected_results/combine3.expected.info 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 cmp combine4.actual.info ${TEST_DIR}/expected_results/combine4.expected.info +# Combine operation - End line number in FN +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 +cmp test1.end_line_number_fn.actual.info ${TEST_DIR}/expected_results/combine6.expected.info + # Run ctest_2 ${TEST_DIR}/fastcov.py --gcov gcov-9 --zerocounters # Clear previous test coverage ctest -R ctest_2