buildframework/helium/doc/src/manual/coverity.rst
changeset 628 7c4a911dc066
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 .. index::
       
     2   module: Coverity Prevent Tool
       
     3   
       
     4 ========================
       
     5 Coverity Prevent Tool
       
     6 ========================
       
     7 
       
     8 .. contents::
       
     9 
       
    10 This document describes requirements and how to run Coverity Prevent tool with sbs builds using Helium. 
       
    11 
       
    12 Introduction
       
    13 -------------------------
       
    14 
       
    15 - Coverity Prevent analyzes source code to find defects early in the development cycle, reducing the risks associated with coding. Included with Prevent are workflow tools that track and manage defects from initial discovery through final resolution.
       
    16 - With high precision, Coverity Prevent analyzes source code and detects critical software defects in the following categories:
       
    17 
       
    18  **Quality**
       
    19   Coverity Prevent detects bugs at compile-time that can cause run-time crashes. For example: memory leaks, use-after-free errors, and illegal pointer accesses.
       
    20 
       
    21  **Security** 
       
    22   Early during development, Coverity Prevent can detect the security vulnerabilities that hackers can exploit and help you eliminate serious problems, such as denial of service, data or memory corruption, and privilege escalation. Vulnerabilities detected can include buffer overruns, integer overflows, format string errors, and SQL injection attacks.
       
    23         
       
    24  **Concurrency**
       
    25   Coverity Prevent can detect errors in multi-threaded programs that, given the complexity of concurrent programming, can be extremely difficult to track down or reproduce. Detected defects include potential deadlocks or misuse of locks.
       
    26 
       
    27 Description
       
    28 -------------------------
       
    29 
       
    30 - Coverity Prevent tool is integrated with Helium to measure C++ code coverage.
       
    31 - Helium does measure C++ code coverage and gives output results in the format of HTML and errors could be submitted to remote database server.
       
    32 - Helium runs coverity prevet tool commands, in sequential using targets. Those targets are defined below..
       
    33 - Helium runs Coverity Prevent tool targets if ``coverity.enabled`` is set to ``true``
       
    34 - Coverity command can be run using the ``<hlm:coverity>`` task.
       
    35 - Coverity task will validate is the command passed to task is starts with ``cov-`` and then it will run the command.
       
    36 - Coverity command options can passed through the datatypes ``<hlm:coverityoptions>`` or ``<hlm:arg>``.
       
    37 - Below example shows how parameters can be passed to coverity command:
       
    38    
       
    39 .. code-block:: xml
       
    40         
       
    41         <hlm:coverity command="cov-link" dir="${build.drive}/">
       
    42             <hlm:arg name="--dir" value="${coverity.inter.dir}"/>
       
    43             <hlm:arg name="--collect" value=""/>
       
    44             <hlm:arg name="-of" value="${coverity.link.dir}/all.link"/>
       
    45         </hlm:coverity>
       
    46         
       
    47 .. code-block:: xml
       
    48         
       
    49         <hlm:coverityoptions id="coverity.analyze.options">
       
    50             <hlm:arg name="--dir" value="${coverity.analyze.dir}"/>
       
    51             <hlm:arg name="--all" value=""/>
       
    52             <hlm:arg name="--symbian" value=""/>
       
    53             <hlm:arg name="--append" value=""/>
       
    54             <hlm:arg name="--enable-callgraph-metrics" value=""/>
       
    55         </hlm:coverityoptions>
       
    56         
       
    57         <hlm:coverity command="cov-analyze" dir="${build.drive}/">
       
    58             <hlm:coverityoptions refid="coverity.analyze.options"/>
       
    59         </hlm:coverity>
       
    60 
       
    61 Helium Targets
       
    62 --------------------------
       
    63 
       
    64 Coverity configure
       
    65 ::::::::::::::::::::::::
       
    66 
       
    67  The ``cov-configure`` command configures a compiler or family of compilers. By default, if no other configuration file or directory is specified, 
       
    68  the configuration is created at <install_dir>/config/coverity_config.xml. Each invocation of cov-configure adds a compiler configuration 
       
    69  in its own subdirectory of the directory containing the coverity_config.xml file, and coverity_config.xml contains an include directive for 
       
    70  that compiler-specific configuration.
       
    71 
       
    72 - These configuration files are generated by ``run-coverity-configure`` target.
       
    73 - If the configuration options need to be changed, then define a ``coverity.config.options`` reference in the respective configuration file.
       
    74 
       
    75 Ex:
       
    76 
       
    77 .. code-block:: xml
       
    78         
       
    79         <hlm:coverityoptions id="coverity.config.options">
       
    80             <hlm:arg name="--config" value="${coverity.config.dir}/coverity_config.xml"/>
       
    81             <hlm:arg name="--template" value=""/>
       
    82             <hlm:arg name="--comptype" value="armcc"/>
       
    83             <hlm:arg name="--compiler" value="armcc.exe"/>
       
    84         </hlm:coverityoptions>
       
    85   
       
    86 Coverity build
       
    87 ::::::::::::::::::::::::
       
    88 
       
    89  The cov-build command intercepts all calls to the compiler invoked by the build system.
       
    90 
       
    91  Usually the cov-build command name and option can prefix the original build command. However, if the build command depends on features 
       
    92  of the command shell that usually invokes it, such as certain shell variables or non-alphanumeric arguments, you can invoke it using a 
       
    93  wrapper script. This preserves the original behavior because the build command is again invoked directly by the kind of shell on which 
       
    94  it depends. 
       
    95 
       
    96 - Coverity Prevent tool build command integrated with SBS task. 
       
    97 - Coverity task extends the "sbstask", so what ever the arguments we pass for sbstask will remain same for coverity tool also.
       
    98 - For example 
       
    99 
       
   100 .. code-block:: xml
       
   101         
       
   102         <hlm:coveritybuild  sbsinput="@{sbs.input}" 
       
   103                             sysdeffile="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}.xml"
       
   104                             layerpatternsetref="${sbs.patternset}" 
       
   105                             workingdir="${build.drive}/" 
       
   106                             execute="true"
       
   107                             failonerror="false"
       
   108                             outputlog="${sbs.log.file}" 
       
   109                             cleanlog = "${sbs.clean.log}"
       
   110                             erroroutput="${sbs.log.file}.sbs_error.log"
       
   111                             statslog="${sbs.log.file}.info.xml">
       
   112                 <hlm:coverityoptions refid="coverity.build.options"/>
       
   113         </hlm:coveritybuild>
       
   114      
       
   115 - In above example Coverity Prevent tool is integrated with sbs using task "coveritybuild".
       
   116 - This task is slightly difference from sbstask as it accepts the coverity tool parameters required while running coverity tool.
       
   117 - In the above example we have mentioned "coverity.build.options" which are required for cov-build command.
       
   118 - coverityoptions datatype will follow below syntax.
       
   119 
       
   120 .. code-block:: xml
       
   121         
       
   122         <hlm:coverityoptions id="coverity.build.options">
       
   123             <arg name="--config" value="${coverity.config.dir}/coverity_config.xml"/>
       
   124             <arg name="--dir" value="${coverity.inter.dir}"/>
       
   125             <arg name="--auto-diff" value=""/>
       
   126             <arg name="--preprocess-first" value=""/>
       
   127             <arg name="--record-only" value=""/>
       
   128         </hlm:coverityoptions>
       
   129 
       
   130 - Internally "coveritybuild" task will run the "cov-build" with parameters passed with "<hlm:coverityoptions>" datatype and sbs commands.
       
   131 - Above arguments are passed by default in helium. If it is required to remove/change the default parameters (by helium)into cov-build, 
       
   132   we need to override the datatype "coverityoptions".
       
   133 
       
   134 - Command resulted for above example is shown below with "@{sbs.input} = dfs_build_input_armv5".
       
   135 
       
   136     | cov-build.exe --auto-diff  --record-only  --config Y:/output/coverity/config/coverity_config.xml 
       
   137     | --preprocess-first  --dir Y:/output/coverity/intermediate sbs -s Y:/output/build/canonical_system_definition_dfs_build.xml 
       
   138     | -c armv5 -k --logfile Y:/output/logs/compile/ido_helloworld_tb92_blr_ci_9.2.30_armv5_dfs_build.log 
       
   139     | --makefile=Y:/output/logs/compile/ido_helloworld_tb92_blr_ci_9.2.30_armv5_dfs_build
       
   140 
       
   141 Coverity emit
       
   142 ::::::::::::::::::::::::
       
   143  
       
   144  The ``cov-emit`` command parses a source file and outputs it into a directory (emit repository) that can later be analyzed with ``cov-analyze``. 
       
   145  The ``cov-emit`` command is typically called by ``cov-translate``, which is in turn typically called by ``cov-build`` (``cov-emit`` is a low-level command 
       
   146  and is not normally called directly). 
       
   147  
       
   148  Re-running the cov-build with replay option will reduce the build time by ~ 20% 
       
   149  
       
   150  - Coverity emit command run by target ``run-coverity-emit``.
       
   151  
       
   152 Coverity analyze
       
   153 ::::::::::::::::::::::::
       
   154 
       
   155  Sometimes the same file is compiled several times with different command-line options. Due to the inherent difficulty of tracking linkage 
       
   156  information, the ``cov-analyze`` command cannot automatically determine which files are linked together. To avoid errors in function call 
       
   157  resolution (especially in C code, which doesn't have any name mangling), use the ``cov-link`` command to get this information. 
       
   158  
       
   159  and also
       
   160  
       
   161  working with link files is faster than collecting data from the intermediate directory multiple times
       
   162  
       
   163  So run the ``cov-link`` commands and analyze the database using ``cov-analyze`` command.
       
   164  
       
   165 - Coverity code analysis is done by target ``run-coverity-analyze``.
       
   166 - Analysis is done in 2 stages. First runs ``cov-link`` and then ``cov-analyze`` command.
       
   167 
       
   168 **cov-link command**
       
   169 
       
   170   1. Run cov-link with the --collect and -of options to collect linkage information on all files compiled in an emit directory.
       
   171   
       
   172   2. Create one or more additional link files by filtering information using either an argument or a portion of the pathname that 
       
   173      was used during command-line compilation. Compiled files are identified based on:
       
   174    * A portion of the pathname to the file when it was compiled. Use the -s option to specify a Perl regular expression to use when looking 
       
   175      at the pathname.
       
   176    
       
   177    * The options given on the command line when it was compiled. Use the -a, -r, -na, and -nr options to group by command-line options.
       
   178     
       
   179   3. Use the link files created in the previous steps, and the emit repository in the original intermediate directory, to create a new intermediate directory with an emit repository with resolved function calls. Then use cov-analyze on the new intermediate directory.
       
   180 
       
   181 **cov-analyze**
       
   182  command analyzes the code previously parsed and emitted into an intermediate directory. The result is a set of XML files 
       
   183  in the <intermediate_directory>/c/output directory that contain a description of the defects. The cov-analyze command also stores analysis 
       
   184  information in the intermediate directory, which speeds up future runs.
       
   185 
       
   186  A log file with information about the checkers used in the analysis, including notices of crashes, is created at 
       
   187  <intermediate_directory>/c/output/analysis-log.txt.gz. 
       
   188 
       
   189  Note that behind the scenes, cov-analyze actually calls cov-internal-analyze-c to run the analysis. If you look at running processes, 
       
   190  both cov-analyze and cov-internal-analyze-c are listed. During an analysis, cov-analyze monitors cov-internal-analyze-c, and can 
       
   191  seamlessly restart the analysis in case of failure.
       
   192  
       
   193  - ``coverity.analyze.options`` could be set if it required to disable/enable the checkers.
       
   194 
       
   195   .. code-block:: xml
       
   196  
       
   197     <hlm:coverityoptions id="coverity.analyze.options">
       
   198         <hlm:arg name="--dir" value="${coverity.analyze.dir}"/>
       
   199         <hlm:arg name="--all" value=""/>
       
   200         <hlm:arg name="--symbian" value=""/>
       
   201         <hlm:arg name="--append" value=""/>
       
   202         <hlm:arg name="--enable-callgraph-metrics" value=""/>
       
   203     </hlm:coverityoptions>
       
   204 
       
   205 
       
   206 Coverity defect manager
       
   207 :::::::::::::::::::::::
       
   208 
       
   209  The ``cov-commit-defects`` command takes defects stored as *.errors.xml files in the <intermediate directory>/<domain>/output directory and 
       
   210  commits them to the Defect Manager database as a new product run. Once committed, you can view the defects in the Defect Manager alongside 
       
   211  the source code that generated them. The defect XML files are created by the ``cov-analyze``command, which scan and evaluate the 
       
   212  preprocessed source files in the <intermediate directory>/<domain>/emit directory.
       
   213         
       
   214 - Coverity defects can be submitted to a remote coverity defect database using the ``run-commit-defects`` target.
       
   215 - To enable the target user should set ``coverity.commit.defects.enabled`` to ``true`` and ``coverity.enabled`` to ``true``.
       
   216 - Username and Password for the Coverity Defect Manager  should be set in the `.netrc file`_::
       
   217 
       
   218     machine coverity login <user name> password <password>
       
   219 
       
   220 .. csv-table:: Coverity feature flags
       
   221    :header: "Flags to set", "Action performed", "Allowed value"
       
   222    
       
   223    ":hlm-t:`coverity.commit.defects.enabled`", "If user wants to commit the defects using existing intermediate folder and run target 
       
   224    ``run-commit-defects``", "true/false"
       
   225    ":hlm-t:`coverity.commit.defects.enabled` and `coverity.enabled`", "If user want to generate the intermididate folder and then commit 
       
   226    defects, first intermediate folders will get generated and defects will commited into database. By default this build sequence will 
       
   227    happen.", "true/false"
       
   228 
       
   229 - Below properties must be set for defects to be committed to the database:
       
   230 
       
   231 .. csv-table:: Coverity defect manager properties
       
   232    :header: "Property name", "Description"
       
   233    
       
   234    ":hlm-t:`coverity.defect.manager.server`", "Coverity defect manager server/IP address. Ex: server.domain.extension or 100.220.530.101"
       
   235    ":hlm-t:`coverity.defect.manager.port`", "Coverity defect manager HTTP port number"
       
   236    ":hlm-t:`coverity.defect.manager.product`", "Coverity defect manager product/platform to submit the coverity errors."
       
   237