In order to increase quality of our software, I will introduce cppcheck, a static c++ check tool to our build ecosystem. First I start with installing cppcheck to Debian build node.
Then let’s have a test run. Just go to project root and launch with default parameters,
Cppcheck lists the problems that it finds. Let’s look at the first one that is in source file ./src/capturer.cpp. Here we see that either the null check at line 7269 is redundant, or the assignments at the previous two lines are crash prone. That needs to be handled.
If we run the cppcheck with “–enable=all” option, we may have style, performance and similar suggestions also. Here is a result of such a run,
Default parameters of cppcheck is chosen to minimize false positives. However, it will nearly always be better to be in the safe side, by lowering the warning threshold. Remember that, it is easier, and also cost effective, to investigate warning and write an exception in configuration than, dealing with the more tedious external rework. Therefore in Jenkins, I will chose the full coverage with using “–enable=all –inconclusive” options.
In order to use cppcheck in Jenkins, go to manage plugins section
and install cppcheck plugin.
then, we should add a step in ssh executor, so that we will have a cppcheck run after build is complete. Notice that the result is requested to be in xml format written in a file named cppcheck.xml located in temp directory.
Next we should add a post build action; a cppcheck report generation. All we have to do is give location of previously prepared xml file.
Results may be seen in Debian build job dashboard.
and detailed results may also be obtained from there.
If the project under investigation is not a brand new one, there will already be somewhat accumulated problem list. Aim should be, with each commit, not to introduce any new items, and if possible, correct the previous ones progressively.