is Gcov an application based coverage or system based coverage - code-coverage

Is Gcov an application based coverage or system based coverage
.gcda files doesn't get generated for all the files. the gcda files are created only for few source files. gcno files are created for all the source files complied with the gcov complilation flags. My project also has QT based modules for which i don't get .gcda files.
Question here is : is gcov application based coverage tool or system based coverage tool ??
I have added the -fprofile-arcs -ftest-coverage in CFLAGS LDFLAGS and CXXFLAGS.

Compiling your code with -fprofile-arcs -ftest-coverage will generate .gcno files.
After executing your binary .gcda will be generated.So in your case some of the binary will not be executed . If .gcno files are w.r.t files then surely it will generate .gcda after executing your binary.

To answer your question, you need to understand how gcov work. Just read this (essentially there are four steps):
How do the code coverage options of GCC work?
To summarize even further, basically gcc will compile and "instrument" the functions so every execution of the function will increase or update some counters. In this way, you can get functions statistics when the program end.
To answer your question: you have just compile some C program with gcov, but did not compile Qt with gcov, but only link to it as a Qt library, so definitely there will be no gcov related statistics.
So it is not application nor system based generated statistics, but is depending on which C files which have gcov enabled during compilation.

Related

Bazel C++ code coverage with a custom coverage tool (Squish Coco)

I couldn't find anything in the official documentation on this. We're using Squish Coco for code coverage and can't use lcov for certification reasons, which is the only tool supported by bazel coverage.
We're trying to get this running in Bazel. For this we added a toolchain for the Squish Coco Wrappers. Which seems to be the standard way to add different compilers, shown here https://bazel.build/tutorials/ccp-toolchain-config.
However linking fails with undefined reference to '__cs_tb...', because Bazel deletes all the instrumentation files (*.o.csmes and *.csmes). The same toolchain for clang or gcc works, as presented in the tutorial.
Is there any way to tell Bazel to keep any files with the ending *.csmes? I'd like to declare that cc_library produces .o files and maybe ( not always, depends on instrumentation options) *.o.csmes. cc_binary amd cc_test may create no extension files and .csmes files.

AOSP native code coverage issue, gcno:version '402*', prefer 'a75*' on soong build system

I am working on native code coverage for AOSP11, I am referring following links.
Native Code coverage with android soong build system
Android Native Unit test Coverage for cpp via gcov and lcov
I have generated *.gcno and also genrated *.gcov, but after running
lcov --directory . --base-directory . --gcov-tool /usr/bin/gcov --capture -o cov.info .gcno
to collect the code coverage results, I am getting version mismatch issue, i.e.
gcno:version '402', prefer 'a75'
So I checked, and can see my host machine's gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) and gcov version (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0. And I ran "file *.gcno" (on generated *.gcno intermediates). Its printing GCC--> gcno coverage (-ftest-coverage), version 4.2 So, root cause is quite clear, but how to resolve this for Soong build system?

Catkin_make with Gcov

These days I have tried so hard to test my rosapp. I want to use Gcov when testing my rosapp. However, I am not so familiar with that. I have tried to add Gcov in my CMakeList.txt but no .gcda files were generated. Does anyone konw how to solve it?
The following options can be passed to catkin tools to add coverage instrumentation to the files within your catkin workspace:
$ catkin config --cmake-args \
-DCMAKE_CXX_FLAGS="--coverage" \
-DCMAKE_LD_FLAGS="--coverage"

Using scan-build command for clang code analysis

I have installed scan-build/clang version 2.9 on Ubuntu desktop. I build my C++ source code there using make . As it said scan-build would analyze a project which is built using make if you give
scan-build make
to
but after the make i see a message
scan-build: Removing '/tmp/scan-build-2013-10-16-1' because it contains no reports.
Also tried
scan-build --use-c++=/use/bin/clang++ make
Q1 - What am i doing wrong/missing here. How to use scan-build to analyze all source files.
Q2 - Is there any option to use clang++ --analyze myfile.cpp
to analyze single source file. But it gives an error about a header file included not found 'fatal' error' my.h
what is the option to clang analyze to point it to the folder having header files.
As for Q2, you should be able to use:
scan-build clang++ -c myfile.cpp
or what you suggested:
clang++ --analyze myfile.cpp
but you need to make sure that the compiler knows about all the includes and libraries (you should be able to successfully compile myfile.cpp to an object file without analysis). That includes especially the -I directories.
There is also the -o option to scan-build, which specifies the target directory for HTML report files. Subdirectories will be created as needed to represent separate "runs" of the analyzer. If this option is not specified, a directory is created in /tmp to store the reports, as you already know.
Another useful option would be -v (verbose), which should print any errors that the analyzer might run into.
Last but not least, you should use the analysis with debug builds where the optimization is disabled, but more importantly where the symbols are not stripped.
Not sure if it helps, let me know ...

how to exclude third party lib / dll from getting analyzed in CLANG scan-build xcodebuild?

I have used some open-source code and third party libs in my project and want to exclude that code from getting analyzed while analyzing my project using scan-build file.
I know we can #ifndef clang_analyzer use this macro to suppress the code from getting analysed, but I dont want to copy paste this in all the files.
OR
Is there any way so that the report which get generated after analysis using scan-build command, not to show the warnings/error generated from some set of files?
thanks in advance.
Use --exclude [1] [2] option (available since 2018)
--exclude
Do not run static analyzer against files found in this directory
(You can specify this option multiple times). Could be useful when
project contains 3rd party libraries.
Same is applicable for Python implementation of scan-build ($ pip install scan-build) - https://github.com/rizsotto/scan-build

Resources