Sonar-scanner ignoring code coverage for some files

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) I am using SonarQube Developer Edition Version 9.3 ,build wrapper,sonar-scanner-4.7.0.2747
  • what are you trying to achieve-I want to calculate code coverage for my project
  • what have you tried so far to achieve this -
    i am getting following massage for all the files which are getting ignored
**INFO:Parsing /home/**/pratik/*/BWRAPPER_GCOV_DIR/upixel_server_util.c.gcov**
**WARN: File not analysed by Sonar, **
**so ignoring coverage:/home/**/pratik/*/util/upixel_server_util.c**

i have used following script for generating gcov reports at one location

mkdir BWRAPPER_GCOV_DIR
pushd BWRAPPER_GCOV_DIR
for f in `find our/build/folder -name '*.o'`
do
  echo "Processing $f file..."
  gcov -o ${f} x
done
popd

My project.propeties file is

sonar.projectName=*******
sonar.projectVersion=1.0
sonar.projectKey=*******
sonar.branch.name=master
sonar.cfamily.build-wrapper-output=/home/**/pratik/**/build_output
sonar.exclusions=**/*.java,**/*.go,**/*.php,**/*.js,**/*.psql,**/*.py,**/*.xml,**/*.css,**/*.html,**/*.as,**/*.sh
sonar.sources=.
sonar.cfamily.gcov.reportsPath=BWRAPPER_GCOV_DIR
sonar.cfamily.threads=15
sonar.host.url=****************
sonar.login=*****************************
sonar.password=
sonar.sourceEncoding=UTF-8

I am getting coverage for only few files and rest of files are getting ignored
what should i do now?

Thanks,
Pratik

1 Like

Hello @pratik_kale,

Could you please send us your scanner log, with debug logs enabled?

Thank you!

Hi @JolyLoic

Thanks for reply.
I am not allowed to share project information out of organization so I can’t give you scanner logs and i am giving you some issue samples which are same for rest of files so hope they will help you to get issue.
I checked files whose gcov reports source file path is not matching with source files is getting ignored by sonar scanner
I am running (Can't get coverage from multiple test folders for C++ - #6 by mpaladin) in project root directory
following kind of massage getting for those files whose source file path is not matching

File '../cache/A.c'
Lines executed:69.23% of 104
Creating 'A.c.gcov'
Cannot open source file ../cache/A.c

File '../x_y_z/parse_response_common_utils.c'
Lines executed:66.18% of 68
Creating 'B.c.gcov'
Cannot open source file ../x_y_z/B.c

sonar-scanner ignoring above types of file by giving information

INFO: Parsing /home/dev/pratik/root_dir/./BWRAPPER_GCOV_DIR/A.c.gcov
WARN: File not analysed by Sonar, so ignoring coverage: /home/dev/pratik/root_dir/cache/A.c
INFO: Parsing /home/dev/pratik/root_dir/./BWRAPPER_GCOV_DIR/B.c.gcov
WARN: File not analysed by Sonar, so ignoring coverage: /home/dev/pratik/root_dir/x_y_z/B.c

I have tried other approach to solve relative path issue, by going in each directory where it can match source file then ran gcov command which generates gcov report without finding difficulty to open source file and then running sonar scanner from root directory which gives me code coverage .But I think this approach is not good because we can’t go in every directory and try to match relative path then generate gcov report and even if we do automate this task then it will fail if new directories gets added . So can you please provide me other approach?

we are having 450k LOC.

If you still need clarification with my issue please let me know what should i clarify.

Thanks,
Pratik

Hello @pratik_kale,

It’s hard to help when I only get a partial view of what you do… As you said, the issue is probably linked to paths and where you run each tool. More specifically, the doc from gcov says:

gcov should be run with the current directory the same as that
when you invoked the compiler. Otherwise it will not be able to
locate the source files.

It looks like this might be the cause of the errors you see. Can you double-check that this condition is respected? Alternatively, maybe you can create a tiny project that reproduced the structure of your real one, and you can share it, including the build/analyze scripts.

Thank you,

I am also facing the same issue, can you help me please

Hi @Sumanth_Anumolu,

Could you please open a new thread where you describe the issue you are facing, and add the analysis log?

Hello @pratik_kale,

Have you been able to make progress on this topic?