Leak check with valgrind and coverage check with lcov too in run_test.sh

master
Denes Matetelki 14 years ago
parent 1ec5fb1466
commit 9834554c17

2
.gitignore vendored

@ -10,4 +10,4 @@
*.kdev_include_paths *.kdev_include_paths
test/generated_main.cpp test/generated_main.cpp
test/test test/test
leak.log

@ -0,0 +1,23 @@
#!/usr/bin/perl
use warnings;
use strict;
# Usage:
# cov_check.pl <expected coverage percentage> <index.html to analyze>
my $min_cov = shift;
while (<>) {
if ( my ($cov) = /<td class="headerCovTableEntry\S+">(\d*\.\d*) %<\/td>/ ) {
if ($cov < $min_cov) {
print "The coverage: $cov% is NOT enough, it should be at least $min_cov%\n";
exit(1);
}
else {
print "The coverage: $cov% exceeds the expected $min_cov%, OK :)\n";
exit(0)
}
}
}

@ -0,0 +1,26 @@
#!/usr/bin/env perl
use strict;
use warnings;
# usage:
# leak_check.pl <log>
my $leaks = 0;
my $errors = 0;
while (<>) {
if (/definitely lost: ([0-9,]+) bytes in ([0-9]+) blocks/) { $leaks = $2; }
if (/ERROR SUMMARY: (\d+) errors from (\d+) contexts/) { $errors = $2;}
}
if ($leaks) { print(sprintf("You have some leaks at %d places :/\n", $leaks)); }
if ($errors) { print(sprintf("You have some memory corruptions at %d places :/\n", $errors)); }
if (0 == $leaks && 0 == $errors) {
print "Valgrind result are ok :)\n";
exit(0);
}
exit(1);

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# Usage: ./run_test.sh <TEST_BINARY> # Usage:
# ./run_test.sh <TEST_BINARY>
pre="\E[00;32m" pre="\E[00;32m"
post="\E[00;00m" post="\E[00;00m"
@ -10,7 +11,9 @@ lcov --directory . -z
rm -f ./lcov.info rm -f ./lcov.info
echo -e "${pre}Run tests${post}" echo -e "${pre}Run tests${post}"
valgrind --leak-check=full --show-reachable=yes --show-below-main=no --track-origins=yes --num-callers=30 --malloc-fill=0xaa --free-fill=0xdd --suppressions=valgrind.supp $1 valgrind --log-file=leak.log --leak-check=full --show-reachable=yes --show-below-main=no \
--track-origins=yes --num-callers=30 --malloc-fill=0xaa --free-fill=0xdd \
--suppressions=valgrind.supp $1
echo -e "${pre}Capture coverage info${post}" echo -e "${pre}Capture coverage info${post}"
@ -24,4 +27,10 @@ lcov -r lcov.info "/usr/include/cxxtest*" -o lcov.info
echo -e "${pre}Generating HTML${post}" echo -e "${pre}Generating HTML${post}"
rm -rf ./cov rm -rf ./cov
mkdir cov mkdir cov
genhtml -o ./cov lcov.info genhtml --frames --legend -o ./cov lcov.info
echo -e "${pre}Checking the coverage results${post}"
./cov_check.pl 90 cov/index.html
echo -e "${pre}Checking leak results${post}"
./leak_check.pl leak.log

Loading…
Cancel
Save