Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCppCoverage coverage report not working since upgrade to 1.2.x #1669

Closed
ericlemes opened this issue Jan 21, 2019 · 21 comments · Fixed by #1709
Closed

OpenCppCoverage coverage report not working since upgrade to 1.2.x #1669

ericlemes opened this issue Jan 21, 2019 · 21 comments · Fixed by #1709
Assignees
Labels
Milestone

Comments

@ericlemes
Copy link
Contributor

Description

I don't believe OpenCppCoverage ever worked properly with sonar-cxx, but was working fine with a little hack.

The issue is that in the coverage report, it uses the full path, without the drive specified (see OpenCppCoverage/OpenCppCoverage#46).

One example is:

<class name="asyncexecutionpolicy.h" filename="w\70c9368db3bcf0f1\handheld\src-deps\core\include\core\checkedresourceservice\asyncexecutionpolicy.h" line-rate="1" branch-rate="0" complexity="0">
To fix this issue, I've written this hack: https://github.com/ericlemes/CoberturaCoverageReportBaseDirFixer, which was working fine in sonar-cxx 1.1.0. The logic was just to strip a given file prefix (the working directory) and use the relative path.

It seems that the commit f8f599a broke this, because it now adds the drive, without the first "/" to the path, making the sensor not finding the file therefore not appending the measure.

Steps to reproduce the problem

Extract coverage report with OpenCppCoverage and publish analysis using the sonar-cxx coverage sensor.

It is expected that the coverage information is published, but it doesn't happen.

Known workarounds

None so far. I'll update my hack with the current behaviour, which should be available in https://github.com/ericlemes/CoberturaCoverageReportBaseDirFixer

LOG file

[16:11:57] : [Step 6/13] 16:11:57.357 DEBUG: save coverage measure for file: 'e:w/70c9368db3bcf0f1/handheld/src/common/world/attribute/attributemodifier.cpp' cxxFile = 'null'
[16:11:57] : [Step 6/13] 16:11:57.357 DEBUG: Cannot find the file 'e:w/70c9368db3bcf0f1/handheld/src/common/world/attribute/attributemodifier.cpp', ignoring coverage measures

Related information

  • cxx plugin version? 1.2.0
  • SonarQube version? 6.7.5
@ericlemes
Copy link
Contributor Author

Some updates about this: I've tried to append one "/" after the drive, and still fails. I'm not sure how are the expected values in the report to work properly.

[18:09:35] : [Step 7/14] 18:09:35.807 DEBUG: cached measures for 'E:\w\70c9368db3bcf0f1\tools\code_coverage\report_fixed.xml' : current cache content data = '0'
[18:09:35] : [Step 7/14] 18:09:35.808 DEBUG: save coverage measure for file: 'e:/w/70c9368db3bcf0f1/handheld/src/common/world/events/serverplayereventcoordinator.cpp' cxxFile = 'null'
[18:09:35] : [Step 7/14] 18:09:35.808 DEBUG: Cannot find the file 'e:/w/70c9368db3bcf0f1/handheld/src/common/world/events/serverplayereventcoordinator.cpp', ignoring coverage measures

@guwirth
Copy link
Collaborator

guwirth commented Jan 24, 2019

Hi @ericlemes,

could you make one sample please:

  • inital "filename" in report filename="w\70c9368db3bcf0f1\handheld\src-deps\core\include\core\checkedresourceservice\asyncexecutionpolicy.h"
  • resulting path after running your hack: filename="???"
  • root path you are using: ???
  • where is the file on your harddisk: ???
  • corresponding error message in log file: ???

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Jan 27, 2019

Hi @ericlemes, could you please answer questions above.

Looking to the code this part is no more available:

   if (new File(filename).isAbsolute()) {
      normalFilename = FilenameUtils.normalize(filename);
    } else {
      normalFilename = FilenameUtils.normalize("./" + filename);
    }

In our doku we normally recommend that relative paths in reports should start with ./
See
https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Path-and-path-separator-issues

@ericlemes
Copy link
Contributor Author

@guwirth Thanks for the comments. I'll have a look at this and get back to you as soon as I can. I'm just a bit busy now unfortunately :-(

@ericlemes
Copy link
Contributor Author

Hi @guwirth ,

I've finally got some time to get a fully working example. The code is in: https://github.com/ericlemes/StackTDDExample.

Running OpenCppCoverage with the following command: OpenCppCoverage --sources C:\SandBox\StackTDDExample\Stack.Core --export_type=cobertura -- Stack.Core.Tests.exe

I've got the coverage report (attached) and I've changed the coverage report as recommended using forward slashes and starting with ./, also trying to match the case. I didn't manage to get coverage published in any scenario

Sonar 6.7.6
sonar-cxx 1.2.2.

Stack.Core.TestsCoverage.xml.zip

@MarcoWagner
Copy link

MarcoWagner commented Feb 20, 2019

I am new to OpenCppCoverage and SonarQube. But I had success to get my coverage reports being recognized by editing the Cobertura file as followed:

  • replaced the original source node with: <source>.\</source>
  • modified the package node filename attribute to be relative to the .\
  • modified the package node name attribute to preserve case-sensitivity
  • modified the package node filename attribute to preserve case-sensitivity

@ericlemes
Copy link
Contributor Author

Hey @MarcoWagner ,

Thank you very much. This pretty much answer my question. It is a shame that the behaviour changed and broke my previous setup, but at least I can fix now.

@guwirth
Copy link
Collaborator

guwirth commented Feb 23, 2019

@ericlemes & @MarcoWagner an idea how this should be supported without patching the report? An extra sensor? What I also understood is that the error is in OpenCppCoverage and will be fixed, right?

@guwirth
Copy link
Collaborator

guwirth commented Feb 23, 2019

@jmecosta you are also using OpenCppCoverage? How you are doing it?

@MarcoWagner
Copy link

MarcoWagner commented Feb 23, 2019

I dont know the Cobertura file format that well.

On the OpenCppCoverage side: the --source path should be put in the <sources> section, the <class> entries should be relative (starting with ./?) and with correct case.

On the sonar-cxx side: the <source> path should be ignored / partly matched? @ericlemes should have a opinion on that.

OpenCppCoverage, case problem: OpenCppCoverage/OpenCppCoverage#53
OpenCppCoverage, absolute path problem: OpenCppCoverage/OpenCppCoverage#46

@jmecosta
Copy link
Member

@guwirth im not using OpenCppCover, ive used it only for local coverage analysis but the sonar builds are still done with bullseye. But it looks to me that OpenCppCover could provide absolute paths in the report.

@ericlemes
Copy link
Contributor Author

Hi @guwirth ,

There are reports in OpenCppCoverage issue tracker that it works fine with Jenkins and other tools. I don't think building a specific sensor would be the way to go. I think the issue happens because our sonar sensor expects the path to be relative to the sources directory. With OpenCppCoverage output if you compute the path following all the structure, the paths are not incorrect.

For me the information that @MarcoWagner is helpful because at least I can fix my hacking tool and make it work.

I believe the way to go would be to check if it is possible to the sensor discover the paths the way it is (since other tools can compute them with no issues), but also a fix from OpenCppCoverage would be interesting.

@guwirth
Copy link
Collaborator

guwirth commented Mar 3, 2019

Hi @ericlemes, @MarcoWagner, @ivangalkin,

think to solve this we should have first a common understanding about the involved parts:

  • SQ root folder: always absolute
  • source tag: could be empty, relative or absolute
  • filename tag: could be relative or absolute
root source filename comment
X X absolute use filename, ignore rest
X absolute relative combine source and filename to an absolute path
absolute relative or empty relative combine root, source and filename to absolute path

Question is also how to combine?
e.g. source=C: | filename=attribute/attributemodifier.cpp (additional path separator needed)
e.g. source=. | filename=./attributemodifier.cpp (to be normalized)
...

Any other points?

Regards,

@ericlemes
Copy link
Contributor Author

Hey @guwirth,

Also, I'd consider forward and backward slashes (/ and ) and case-insensitive file matching.

The how to combine is a tricky one. I think you should combine root + source + filename and always get the right file, so, it should automatically add slashes when combining.

Regards,

Eric

@guwirth guwirth added this to the 1.3.0 milestone Mar 4, 2019
@guwirth guwirth added bug and removed question labels Mar 4, 2019
@guwirth
Copy link
Collaborator

guwirth commented Mar 10, 2019

Looking into the sample from @ericlemes Stack.Core.TestsCoverage.xml.zip

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0" complexity="0" branches-covered="0" branches-valid="0" timestamp="0" lines-covered="73" lines-valid="73" version="0">
  <sources>
    <source>c:</source>
  </sources>
  <packages>
    <package>
      <classes>
        <class name="heapallocator.h" filename="./Stack.Core/HeapAllocator.h" line-rate="1" branch-rate="0" complexity="0">
        </class>
        <class name="stack.h" filename="sandbox\stacktddexample\stack.core\stack.h" line-rate="1" branch-rate="0" complexity="0">
        </class>
        <class name="givenastack.cpp" filename="sandbox\stacktddexample\stack.core.tests\givenastack.cpp" line-rate="1" branch-rate="0" complexity="0">
        </class>
        <class name="stack.core.tests.cpp" filename="sandbox\stacktddexample\stack.core.tests\stack.core.tests.cpp" line-rate="1" branch-rate="0" complexity="0">
        </class>
      </classes>
    </package>
  </packages>
</coverage>

@MarcoWagner
Copy link

MarcoWagner commented Mar 11, 2019

@guwirth before editing with my self build tool mine looks the same as @ericlemes given sample.
My tool produces the files like in your third variant. (absolute, relative, relative), also restoring case sensitivity.

@guwirth
Copy link
Collaborator

guwirth commented Apr 17, 2019

@ericlemes and @MarcoWagner I tried a fix with #1709. Please try with latest snapshot: https://ci.appveyor.com/project/SonarOpenCommunity/sonar-cxx/branch/master/artifacts

@ericlemes
Copy link
Contributor Author

Hey @guwirth, sorry for my delay. I'm adding this to my backlog here and we should see progress in the next couple of weeks.

@roryclaasen
Copy link

Hey @guwirth, I am working with @ericlemes on this.
I can confirm that with the latest snapshot it works

@MarcoWagner
Copy link

Works for me too. Thank you.

@guwirth
Copy link
Collaborator

guwirth commented May 4, 2019

@ericlemes & @MarcoWagner thx for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

5 participants