[icinga-checkins] icinga.org: icinga-core/test/core: add experimental test_leak. pl inspired by mod_gearman

git at icinga.org git at icinga.org
Tue Apr 3 09:16:14 CEST 2012


Module: icinga-core
Branch: test/core
Commit: 43af17a94b5d5607090ff891a9465b4fa21dbe31
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=43af17a94b5d5607090ff891a9465b4fa21dbe31

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Mar 12 17:01:56 2012 +0100

add experimental test_leak.pl inspired by mod_gearman

$ cd t-tap
$ ./test_leak.pl
or
$ ./test_leak.pl test_checks

to run the valgrind onto the tests. the logs, if any are placed in
var/log/* with their date.

refs #2427

---

 t-tap/Makefile.in        |    7 +----
 t-tap/test_leak.pl       |   61 ++++++++++++++++++++++++++++++++++++++++++++++
 t-tap/var/log/.gitignore |    4 +++
 3 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/t-tap/Makefile.in b/t-tap/Makefile.in
index e43a79c..195ea63 100644
--- a/t-tap/Makefile.in
+++ b/t-tap/Makefile.in
@@ -12,12 +12,7 @@ CC=@CC@
 CFLAGS=@TESTS_CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tools/libtap
 TAPOBJ=../tools/libtap/tap.o
 
-TESTS = test_logging test_events test_timeperiods test_icinga_config
-TESTS += test_xsddefault
-TESTS += test_checks
-TESTS += test_strtoul
-TESTS += test_commands
-TESTS += test_downtime
+TESTS = test_logging test_events test_timeperiods test_icinga_config test_xsddefault test_checks test_strtoul test_commands test_downtime
 
 # these objects must be the same as defined in cgi/Makefile.in as CGILIBS!
 XSD_OBJS = $(SRC_CGI)/statusdata-cgi.o $(SRC_CGI)/xstatusdata-cgi.o
diff --git a/t-tap/test_leak.pl b/t-tap/test_leak.pl
new file mode 100755
index 0000000..1a2de79
--- /dev/null
+++ b/t-tap/test_leak.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+# slighty modified from the initial idea of mod_gearman
+# https://github.com/sni/mod_gearman/blob/master/t/test_all.pl
+
+
+use warnings;
+use strict;
+use Test::More;
+
+my $pwd = `pwd`;
+chomp $pwd;
+
+# clean up old gearmands
+#`ps -efl | grep gearmand | grep 54730 | awk '{ print \$4 }' | xargs kill`;
+
+`type valgrind >/dev/null 2>&1`;
+if($? != 0) {
+    plan skip_all => 'valgrind required';
+}
+
+my $makeprep = `cd ..; make clean 2>&1 && make icinga && make cgis 2>&1; cd $pwd`;
+is($?, 0, "make icinga && cgis is $?") or BAIL_OUT("no need to test without successful make icinga && make cgis!\n".$makeprep);
+
+my $makeout = `make clean  2>&1 && make 2>&1`;
+is($?, 0, "build rc is $?") or BAIL_OUT("no need to test without successful make!\n".$makeout);
+
+my $skip_perl_mem_leaks = "";
+#if(`grep -c '^#define EMBEDDEDPERL' config.h` > 0) {
+#    $skip_perl_mem_leaks = "--suppressions=./t/valgrind_suppress.cfg";
+#}
+
+my $today 	 = `date '+%Y-%m-%d'`;
+chomp $today;
+my $vallog       = 'var/log/valgrind-'.$today.'.log';
+my $testlog      = 'var/log/icinga_test-'.$today.'.log';
+my $suppressions = 'var/log/suppressions-'.$today.'.log';
+`>$suppressions`;
+my @tests = $ARGV[0] || split/\s+/, `grep ^TESTS Makefile.in | awk -F = '{print \$2}'`;
+for my $test (@tests) {
+    next if $test =~ m/^\s*$/;
+    `make $test 2>/dev/null`;
+    is($?, 0, "$test build rc is $?");
+
+    #my $cmd = "yes | valgrind --tool=memcheck --leak-check=yes --leak-check=full --show-reachable=yes --track-origins=yes $skip_perl_mem_leaks --gen-suppressions=yes --log-file=$vallog ./$test >$testlog 2>&1";
+    my $cmd = "yes | valgrind --tool=memcheck --leak-check=yes --leak-check=full --show-reachable=yes --track-origins=yes $skip_perl_mem_leaks --log-file=$vallog ./$test >$testlog -v 2>&1";
+    #diag($cmd);
+    `$cmd`;
+    is($?, 0, "$test valgrind exit code is $?") or diag(`cat $testlog`);
+
+    `cat $vallog >> $suppressions`;
+
+    is(qx(grep "ERROR SUMMARY: " $vallog | grep -v "ERROR SUMMARY: 0 errors"), "", "valgrind Error Summary")
+      or BAIL_OUT("check memory $test in $vallog");
+}
+
+unlink($vallog);
+unlink($testlog);
+
+#diag(`ls -la $suppressions`);
+
+done_testing();
diff --git a/t-tap/var/log/.gitignore b/t-tap/var/log/.gitignore
new file mode 100644
index 0000000..f734974
--- /dev/null
+++ b/t-tap/var/log/.gitignore
@@ -0,0 +1,4 @@
+valgrind-*.log
+icinga_test-*.log
+suppressions-*.log
+





More information about the icinga-checkins mailing list