how to exclude multiple files using cppcheck with command line - cppcheck

I'm using cppcheck to analyse C source code
Using this command : cppcheck --enable=warning inputpath1 inputpath2 inputpath3 -iexcludepath1 excludepath2 --xml -U_DEBUG 2> .\CppCheckReport.xml
I'm able to generate an XMl report which contains the analyse results of the three input files with the exclusion of the exclude file1 only.
I need to exclude the two files using the -i option one time that's mean that I don't want to use this command : cppcheck --enable=warning inputpath1 inputpath2 inputpath3 -iexcludepath1 -iexcludepath2 --xml -U_DEBUG 2> .\CppCheckReport.xml
Is there any other method to exclude multiple files using cppcheck command ?

Related

How to use cppcheck command the input path from txt file

I'm using Cppchek to analyse my source codes
By this command : cppcheck inputPath1 inputPath2 --enable=warning --xml 2> cppcheck-result.xml the report was well generated, However, I require a method to store the inputPath in a text file so that it can be read by the command line that will be executed.

Merge lcov results in one report, and keep the test ids testing each line

I have lcov report of my c++ code on each of my integration tests. I would like to merge it in one global report, I know it is possible but it only adds up hit lines count. I wish to have the information about which test hit each line.
I dunno if there is a way instead of writing a script myself.
Thanks
You can use geninfo in combination with lcov to achieve something similar.
If you have both .gcno and .gcda files available then first we will need to generate .info files.
To generate .info files use :
geninfo "path for .gcda files" -b "path for the source files" -o ./coverage1.info
So this will generate .info for your first test. Similarly, generate .info for all of your tests.
Now you can use lcov to combine these info files and get a combined report. To do that use:
lcov --add-tracefile coverage1.info -a coverage2.info ...coverageN -o merged.info
Now you have combined .info file and you can use genhtml to generate a HTML report for better view.
genhtml merged.info -o CodeCoverage

How to use the exclude_files regex in cpplint?

I am using cpplint to check my sourcode agains the google style guide.
Cpplint's help says:
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
files. CPPLINT.cfg file can contain a number of key=value pairs.
Currently the following options are supported:
"exclude_files" allows to specify a regular expression to be matched against
a file name. If the expression matches, the file is skipped and not run
through liner.
Example file:
filter=-build/include_order,+build/include_alpha
exclude_files=.*\.cc
The above example disables build/include_order warning and enables
build/include_alpha as well as excludes all .cc from being
processed by linter, in the current directory (where the .cfg
file is located) and all sub-directories.
How I use cpplint:
I use cpplint by this command to check all files in my source folder:
cpplint src/*.c
Well there is one special file foo.cc which must not be checked. So I tried to create a CPPLIN.cfg to use the exclude_files property. My file looks like this:
set noparent
filter=-build/include_dir
exclude_files=foo.cc
Nevertheless foo.cc is still checked.
What I have already tried to do:
I tried exclude_files=/.*\.cc/. This should exclude all files ending with *.cc. Nevertheless all files are still checked.
I tried to remove my filter from the file. This caused more errors than before. So I am now sure that my CPPLINT.cfg file is found by cpplint.
Question:
How to use the exclude_files regex in cpplint correctly?
Turns out apparently that the doc is wrong: exclude_files only excludes files in the same directory as CPPLINT.cfg, not in subdirectories. See https://github.com/google/styleguide/issues/220
So the solution would be to create src/CPPLINT.cfg and put exclude_files=.*\.cc in it.

How to ignore header files in gcov output?

I am using gcov and gcovr to generate my code test coverage (the tests are done with google test++).
So, I compile with the -ftest-coverage -fprofile-arcs options, and then I run gcovr (which itself runs gcov).
However, on my output, I have the cpp files, with a cover of 100%, but also the .h files, even if they do not have executable code, and hence they have a 0% coverage output.
This 0% does not mean anything, and hence, I would like to remove the .h files from the coverage output. I can't find anything about that...
I already try to add : -e "*.h" to the govr options, to exclude files with .h extension, but it doesn't work (it actually excludes everything...).
Does anybody have an idea ??
Thank you !!
I was also struggling with this, now found the right solution. Here an example and way of working:
When you run gcov, use option -o coverage.xml, then open the file. Find the filename you want to exclude and copy the filename.
Open in your browser following link and copy the entire filename to the part which says: TEST STRING
https://regex101.com/
Now, where it says: REGULAR EXPRESSION, create a regular expression which makes the entire filename BLUE. Make sure this expression does not apply to other files which are needed to show in your coverage report.
Here some basic rules: Usually, for "some characters" you can use ".*" what has nothing to do with files of type *.cpp, where you want to see the cpp files! So if you want to exclude anything like "<some characters>include<more characters>", then you can use ".*include.*". This will also exclude some filename like include.cpp
Because the . has a meaning in regular expressions, use \. So if you want to exclude "<something>.h" files, use ".*\.h"
Example what works for me: (exclude include files and the test framework and linux include directory and exclude jenkins files)
Also I want to exclude any cpp file which has the word test, what I can do with ".*test[_-[A-Z|a-z]*\.cpp"
Real life example:
gcovr --xml -e ".*unit_test\.cpp" -e ".*\.h" -e ".*usr/include/.*" -e ".*jenkins.*" -e ".*test[_-|A-Z|a-z]*\.cpp" -o coverage.xml
have fun!
Just use -e to exclude you files..
Your command will look like
gcovr -r . -e "include.*" --html --html-details -o $result_dir/result.html
It will exclude all include files of your project.

Can we list all the *.[c,h,S] files that are used by "make" command to build the linux kernel?

There are a lot of files in the kernel source that are not used most of the times. I wanted to list out only the files that are compiled when I issue a make command.
I thought that only those files that will be compiled are accessed during a make and hence, I tried the following command :
find . -type f -name *.[chS] -anewer Makefile
But I found that many files that are not a part of the required architecture are also being accessed. Please suggest a method in which I could list those filenames along with their path form the kernel source top directory.
Try make cscope and then check out the file list in the cscope.files plaintext file. You need the cscope tool installed on your system.