Skip to content

Commit fa711b5

Browse files
author
jgwilson42
committed
Remove the temporary gcov files by default.
Remove instances of camel case.
1 parent c2d7554 commit fa711b5

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

regression/get_coverage.sh

+52-17
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,90 @@
11
#!/bin/bash
22

3+
# By default remove temporary files after the run
4+
keep_files=false
5+
36
# Get a unique number to prevent collision of output files
4-
outputDir=`mktemp -d ./coverage_XXXXX`
7+
output_dir=`mktemp -d ./coverage_XXXXX`
58
if [ $? -ne 0 ]; then
69
printf "ERROR: Could not create output directoy"
710
exit 1
811
fi
912

1013
# Check that the previous command succeded, if not exit.
11-
commandStatus()
14+
command_status()
1215
{
1316
if [ $? -ne 0 ]; then
1417
printf "[ERROR]\n"
15-
echo "ERROR: See $outputDir/cbmc_coverage.out for more information"
18+
echo "ERROR: See $output_dir/cbmc_coverage.out for more information"
1619
exit 1
1720
fi
1821
printf "[OK]\n"
1922
}
2023

24+
# Print usage
25+
print_usage()
26+
{
27+
echo "Usage: $0 [-k]"
28+
echo " -k Keep all raw coverage files"
29+
}
30+
31+
#Check the options that the user provided
32+
while getopts ":k" opt
33+
do
34+
case $opt in
35+
k)
36+
keep_files=true
37+
;;
38+
\?)
39+
echo "ERROR: Invalid option: -$opt"
40+
print_usage
41+
exit 1
42+
;;
43+
esac
44+
done
45+
2146
# Check that lcov has been installed
2247
printf "INFO: Checking lcov is installed "
23-
lcov -version > $outputDir/cbmc_coverage.out 2>&1
24-
commandStatus
48+
lcov -version > $output_dir/cbmc_coverage.out 2>&1
49+
command_status
2550

2651
# Remove any previous build that may not have coverage in it.
2752
printf "INFO: Cleaning CBMC build "
28-
make clean -C ../src >> $outputDir/cbmc_coverage.out 2>&1
29-
commandStatus
53+
make clean -C ../src >> $output_dir/cbmc_coverage.out 2>&1
54+
command_status
3055

3156
printf "INFO: Building CBMC with Code Coverage enabled "
3257
# 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
58+
make CXXFLAGS="--coverage" LINKFLAGS="--coverage" -C ../src >> $output_dir/cbmc_coverage.out 2>&1
59+
command_status
3560

3661
printf "INFO: Running Regression tests "
3762
# Run regression tests which will collect the coverage metrics and put them in the src files
38-
make >> $outputDir/cbmc_coverage.out 2>&1
63+
make >> $output_dir/cbmc_coverage.out 2>&1
3964
printf "[DONE]\n"
4065

4166
printf "INFO: Gathering coverage metrics "
4267
# 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
68+
lcov --capture --directory ../src --output-file $output_dir/cbmc_coverage.info >> $output_dir/cbmc_coverage.out 2>&1
69+
command_status
4570

4671
printf "INFO: Removing unwanted metrics (for external libaries) "
4772
# 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
73+
lcov --remove $output_dir/cbmc_coverage.info '/usr/*' --output-file $output_dir/cbmc_coverage.info >> $output_dir/cbmc_coverage.out 2>&1
74+
command_status
5075

5176
printf "INFO: Creating coverage report "
5277
# 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"
78+
genhtml $output_dir/cbmc_coverage.info --output-directory $output_dir/cbmc_coverage >> $output_dir/cbmc_coverage.out 2>&1
79+
command_status
80+
echo "INFO: Coverage report is availabe in $output_dir/cbmc_coverage"
81+
82+
if [ $keep_files == false ]; then
83+
# Remove the temporary coverage files
84+
printf "INFO: Removing temporary coverage files (1 of 2) "
85+
find ../ -name "*.gcda" -delete >> $output_dir/cbmc_coverage.out 2>&1
86+
command_status
87+
printf "INFO: Removing temporary coverage files (2 of 2) "
88+
find ../ -name "*.gcno" -delete >> $output_dir/cbmc_coverage.out 2>&1
89+
command_status
90+
fi

0 commit comments

Comments
 (0)