Wednesday, 21 December 2011

Checking Coverity builds

I'll write another Coverity related post right after the previous one to not forget..

In Coverity you need to be very careful that what you analyze is really what you wanted to.  First off of course you need to have the correct compiler configured, missing function models defined and correct compilation flags being used for the Coverity build. These are usually a one-off job, but depending on your workflow there might be problems making sure that the new snapshot really is built exactly like the previous one. You have to remember to clean the build etc very carefully.

There are a few things to check out:

  1. Did Coverity compile everything? It says at the end of the process what percentage of units were compiled. This should be 100.
  2. Do you see an unexpectedly high number of fixed and/or new defects? This can reveal issues listed above.
  3. Are there any errors in the build log (build-log.txt in the intermediary directory)? Search for "error #" in the log. This should also show in the percentage.
  4. Are there any warnings in the build log? Search for "warning #" in the log. These can prevent Coverity from analyzing functions.
  5. Are there any asserts? This is a rare Coverity bug and also should show in the percentage as well. Search for "Assertion failed".  There are instructions on how to get past this issue in the build log. It involves setting COVERITY_SUPPRESS_ASSERT.

Coverity and Bitbake

Coverity is a useful tool but boy can it take time to get it to work, especially if your compiler is not supported.

The latest issue, however, was more interesting. Apparently Bitbake shouldn't be a problem, but it was with us. The bitbake script cleans all environment variables except those whitelisted before it runs and as it happens, Coverity requires certain variables to be kept.

This problem can be solved by editing the /lib/bb/utils.py. There is a function called preserved_envvars_list() which returns an array of whitelisted environment variables. In order to make Coverity work, you need to add the following variables to that list:

EDIT: I was told of a few more variables in the Coverity Support Forum.

        'LD_PRELOAD',
        'COVERITY_BIN',
        'COVERITY_SITE_CC',
        'COVERITY_TEMP',
        'COVERITY_IS_COMPILER',
        'COVERITY_TOP_PROCESS',
        'COVERITY_IS_COMPILER_DESCENDANT',
        'COVERITY_OUTPUT',
        'COVERITY_BUILD_INVOCATION_ID',
        'COVERITY_COMPILER_PATH_MISMATCH_FILE',
        'COVERITY_LD_PRELOAD',
        'COVERITY_LD_PRELOAD_32',
        'COVERITY_LD_PRELOAD_64'
        'COVERITY_PATHLESS_CONFIGS_FILE',
        'COVERITY_PREV_XML_CATALOG_FILES',
        'COVERITY_START_CWD',
        'COVERITY_TOP_CONFIG',
        'LD_PRELOAD_32',
        'LD_PRELOAD_64',
        'PLATFORM',
        'COVERITY_DEBUG',
        'COVERITY_EMIT',
        'COVERITY_LD_LIBRARY_PATH',
        'COVERITY_TOP_PROCESS',
        'COVERITY_USE_DOLLAR_PLATFORM'