|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Get a unique number to prevent collision of output files |
| 4 | +outputDir=`mktemp -d ./coverage_XXXXX` |
| 5 | +if [ $? -ne 0 ]; then |
| 6 | + printf "ERROR: Could not create output directoy" |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +# Check that the previous command succeded, if not exit. |
| 11 | +commandStatus() |
| 12 | +{ |
| 13 | + if [ $? -ne 0 ]; then |
| 14 | + printf "[ERROR]\n" |
| 15 | + echo "ERROR: See $outputDir/cbmc_coverage.out for more information" |
| 16 | + exit 1 |
| 17 | + fi |
| 18 | + printf "[OK]\n" |
| 19 | +} |
| 20 | + |
| 21 | +# Check that lcov has been installed |
| 22 | +printf "INFO: Checking lcov is installed " |
| 23 | +lcov -version > $outputDir/cbmc_coverage.out 2>&1 |
| 24 | +commandStatus |
| 25 | + |
| 26 | +# Remove any previous build that may not have coverage in it. |
| 27 | +printf "INFO: Cleaning CBMC build " |
| 28 | +make clean -C ../src >> $outputDir/cbmc_coverage.out 2>&1 |
| 29 | +commandStatus |
| 30 | + |
| 31 | +printf "INFO: Building CBMC with Code Coverage enabled " |
| 32 | +# Run the usual make target with --coverage to add gcov instrumentation |
| 33 | +make CXXFLAGS="--coverage" LINKFLAGS="--coverage" -C ../src >> $outputDir/cbmc_coverage.out 2>&1 |
| 34 | +commandStatus |
| 35 | + |
| 36 | +printf "INFO: Running Regression tests " |
| 37 | +# Run regression tests which will collect the coverage metrics and put them in the src files |
| 38 | +make >> $outputDir/cbmc_coverage.out 2>&1 |
| 39 | +printf "[DONE]\n" |
| 40 | + |
| 41 | +printf "INFO: Gathering coverage metrics " |
| 42 | +# Gather all of the coverage metrics into a single file |
| 43 | +lcov --capture --directory ../src --output-file $outputDir/cbmcCoverage.info >> $outputDir/cbmc_coverage.out 2>&1 |
| 44 | +commandStatus |
| 45 | + |
| 46 | +printf "INFO: Removing unwanted metrics (for external libaries) " |
| 47 | +# Remove the metrics for files that aren't CBMC's source code |
| 48 | +lcov --remove $outputDir/cbmcCoverage.info '/usr/*' --output-file $outputDir/cbmcCoverage.info >> $outputDir/cbmc_coverage.out 2>&1 |
| 49 | +commandStatus |
| 50 | + |
| 51 | +printf "INFO: Creating coverage report " |
| 52 | +# Generate the HTML coverage report |
| 53 | +genhtml $outputDir/cbmcCoverage.info --output-directory $outputDir/cbmcCoverage >> $outputDir/cbmc_coverage.out 2>&1 |
| 54 | +commandStatus |
| 55 | +echo "INFO: Coverage report is availabe in $outputDir/cbmcCoverage" |
0 commit comments