Skip to content

Bug: Gcov coverage report's link to source code is broken #2717

@mharshe

Description

@mharshe

Describe the bug

Currently the link in the coverage report uses a filename/path which does not exist. Additionally, when running this on C++ code the function names provided by gcov do not match the function names detected by treesitter (in the reader_c.py).

For example, namespaces are not captured by strictdoc, and the paramater names are ignored by gcov.

To Reproduce

  1. Compile the following minimal C++ code:

functions.h

namespace test {
class Adder {
public:
static int add(const int& a, const int& b);
};

class Multiplier {
public:
static int multiply(int a, const int& b);
};
}

functions.cpp

#include "functions.h"

namespace test {
  
int Adder::add(const int& a, const int& b) {
  return a + b;
}

int Multiplier::multiply(int a, const int& b) {
  return a * b;
}
}

main.cpp

#include <iostream>
#include <functions.h>

int main() {
  std::cout << test::Adder::add(2, 3) << std::endl;
};

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)

project(Test LANGUAGES CXX)

set(CMAKE_CXX_FLAGS "-g --coverage")

add_executable(test functions.cpp main.cpp functions.h)
target_include_directories(test PRIVATE .)

Generating coverage:

cmake  -S . -B build
cmake --build build
./build/bin/test
gcovr --json coverage.gcov.json -r . --object-directory=./build

The coverage report generated has the following structure:

{
  "files": [
    {
      "file": "functions.cpp",
      "functions": [
        {
          "blocks_percent": 100.0,
          "execution_count": 1,
          "lineno": 5,
          "name": "test::Adder::add(int const&, int const&)",
          "returned_count": 1
        },
        {
          "blocks_percent": 0.0,
          "execution_count": 0,
          "lineno": 9,
          "name": "test::Multiplier::multiply(int, int const&)",
          "returned_count": 0
        }
      ],
      "lines": [
        {
          "branches": [],
          "count": 1,
          "gcovr/md5": "8c8b1e6d3b6f7890e4c5414014476d71",
          "line_number": 5
        },
        {
          "branches": [],
          "count": 1,
          "gcovr/md5": "a8f13a4d730a6cbd1325f27e5ce8f30e",
          "line_number": 6
        },
        {
          "branches": [],
          "count": 0,
          "gcovr/md5": "756d8eab30360280911600a5a72ec1b7",
          "line_number": 9
        },
        {
          "branches": [],
          "count": 0,
          "gcovr/md5": "9a9c328eaa6b7daa2c1e04d633edb6d2",
          "line_number": 10
        }
      ]
    },
    {
      "file": "main.cpp",
      "functions": [
        {
          "blocks_percent": 86.0,
          "execution_count": 1,
          "lineno": 4,
          "name": "main",
          "returned_count": 1
        }
      ],
      "lines": [
        {
          "branches": [],
          "count": 1,
          "gcovr/md5": "d9d7d650613a8ac26f6dfe250d77e8ea",
          "line_number": 4
        },
        {
          "branches": [
            {
              "blockno": 0,
              "count": 1,
              "fallthrough": true,
              "throw": false
            },
            {
              "blockno": 0,
              "count": 0,
              "fallthrough": false,
              "throw": true
            },
            {
              "blockno": 1,
              "count": 1,
              "fallthrough": true,
              "throw": false
            },
            {
              "blockno": 1,
              "count": 0,
              "fallthrough": false,
              "throw": true
            },
            {
              "blockno": 2,
              "count": 1,
              "fallthrough": true,
              "throw": false
            },
            {
              "blockno": 2,
              "count": 0,
              "fallthrough": false,
              "throw": true
            }
          ],
          "count": 1,
          "gcovr/md5": "384462c03226d875aa1a49889b9d1937",
          "line_number": 5
        },
        {
          "branches": [],
          "count": 1,
          "gcovr/md5": "2145c1b6992c0d519ad223f91671329b",
          "line_number": 6
        }
      ]
    }
  ],
  "gcovr/format_version": "0.6"
}

By adding print statements in the FileTraceabilityIndex I get the following logs:

Appending function Adder::add(const int& a, const int& b)
Appending function Multiplier::multiply(int a, const int& b)

However, gcov function names are : test::Adder::add(int const&, int const&) and test::Multiplier::multiply(int, int const&), so they don't match.

Expected behavior

Gcov function names should match the function names detected from the source by strictdoc

Screenshots

Environment

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions