Monday, December 3, 2012

Code Quality test with Continuous integration



Last time I wrote about what is code quality and how to measure. Today it’s going to be an implementation of code testing with opensource and continuous integration with Jenkins.
The concept is test code from the following tools and executes to xml and show the result from Jenkins plugin.
Code we have are:

C-code (from Eclipse)

Code Metrics

Jenkins Plug-in: Jenkins CCCC Plug-in https://wiki.jenkins-ci.org/display/JENKINS/CCCC+Plugin
A free software tool for measurement of source code related metrics. The CCCC tool was developed as a testing ground for a number of ideas related to software metrics.
Report: This table shows measures over the project as a whole.

  • NOM = Number of modules
    Number of non-trivial modules identified by the analyser. Non-trivial modules include all classes, and any other module for which member functions are identified.
  • LOC = Lines of Code
    Number of non-blank, non-comment lines of source code counted by the analyser.
  • COM = Lines of Comments
    Number of lines of comment identified by the analyser
  • MVG = McCabe's Cyclomatic Complexity
    A measure of the decision complexity of the functions which make up the program. The strict definition of this measure is that it is the number of linearly independent routes through a directed acyclic graph which maps the flow of control of a subprogram. The analyser counts this by recording the number of distinct decision outcomes contained within each function, which yields a good approximation to the formally defined version of the measure.
  • L_C = Lines of code per line of comment
    Indicates density of comments with respect to textual size of program
  • M_C = Cyclomatic Complexity per line of comment
    Indicates density of comments with respect to logical complexity of program
  • IF4 = Information Flow measure
    Measure of information flow between modules suggested by Henry and Kafura. The analyser makes an approximate count of this by counting inter-module couplings identified in the module interfaces.

Code analysis

Jenkins Plug-in: Jenkins Cppcheck Plug-in https://wiki.jenkins-ci.org/display/JENKINS/Cppcheck+Plugin
CPPcheck is a static analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools it does not detect syntax errors in the code. Cppcheck primarily detects the types of bugs that the compilers normally do not detect. The goal is to detect only real errors in the code (i.e. have zero false positives).

Report:

  • Out of bounds checking
  • Check the code for each class
  • Checking exception safety
  • Memory leaks checking
  • Warn if obsolete functions are used
  • Check for invalid usage of STL
  • Check for uninitialized variables and unused functions
  • http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page

C# code (from Visual Studio)

Code Metric

CCM is a tool that analyzes c/c++, c#, javascript and Typescript code and reports back on Cyclomatic Complexity, a metric introduced by Thomas McCabe back in the mid 70's.
This metric states the number of independent linear paths through a unit of code and is useful to determine how complex the unit of code is (for this particular tool, a unit is a function or a method).

Report:

  • Cyclomatic Complexity metrics

Code analysis

Jenkins Plug-in: Jenkins Violations plugin https://wiki.jenkins-ci.org/display/JENKINS/Violations
FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements. Many of the issues concern violations of the programming and design rules set forth in the Design Guidelines, which are the Microsoft guidelines for writing robust and easily maintainable code by using the .NET Framework.

Report:

FxCop is a tool that performs static code analysis of .NET code. It provides hundreds of rules that perform various types of analysis.



  • Design
  • Globalization
  • Interoperability
  • Maintainability
  • Mobility
  • Naming
  • Performance
  • Portability
  • Reliability
  • Security
  • Usage