From 9834554c174948ed6368bb1186d039de0211c0cb Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Tue, 1 Mar 2011 14:33:19 +0100 Subject: [PATCH] Leak check with valgrind and coverage check with lcov too in run_test.sh --- .gitignore | 2 +- test/cov_check.pl | 23 +++++++++++++++++++++++ test/leak_check.pl | 26 ++++++++++++++++++++++++++ test/run_test.sh | 15 ++++++++++++--- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100755 test/cov_check.pl create mode 100755 test/leak_check.pl diff --git a/.gitignore b/.gitignore index 52bdd5c..e09d3ea 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ *.kdev_include_paths test/generated_main.cpp test/test - +leak.log diff --git a/test/cov_check.pl b/test/cov_check.pl new file mode 100755 index 0000000..0995d32 --- /dev/null +++ b/test/cov_check.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +# Usage: +# cov_check.pl + + +my $min_cov = shift; + +while (<>) { + if ( my ($cov) = /(\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) + } + } +} diff --git a/test/leak_check.pl b/test/leak_check.pl new file mode 100755 index 0000000..75eabb4 --- /dev/null +++ b/test/leak_check.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# usage: +# leak_check.pl + + +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); + diff --git a/test/run_test.sh b/test/run_test.sh index 9ed5b82..d87f7b0 100755 --- a/test/run_test.sh +++ b/test/run_test.sh @@ -1,6 +1,7 @@ #!/bin/bash -# Usage: ./run_test.sh +# Usage: +# ./run_test.sh pre="\E[00;32m" post="\E[00;00m" @@ -10,7 +11,9 @@ lcov --directory . -z rm -f ./lcov.info 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}" @@ -24,4 +27,10 @@ lcov -r lcov.info "/usr/include/cxxtest*" -o lcov.info echo -e "${pre}Generating HTML${post}" rm -rf ./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