summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2005-02-10 08:50:33 +0000
committerDaniel Stenberg <daniel@haxx.se>2005-02-10 08:50:33 +0000
commit160d6b26b0ca3966d55dce45c0ca2090500bc175 (patch)
tree40d2c53399929d62207912da20ec4a30f93a0943
parent17d61e4f29e3e1f39a845834e268e67a5afa46e1 (diff)
downloadgnurl-160d6b26b0ca3966d55dce45c0ca2090500bc175.tar.gz
gnurl-160d6b26b0ca3966d55dce45c0ca2090500bc175.tar.bz2
gnurl-160d6b26b0ca3966d55dce45c0ca2090500bc175.zip
Moved out the valgrind report parser to valgrind.pm, to make it easier to
test it outside the test suite. Now we also disable valgrind usage if libcurl was built shared, as then valgrind is only testing the wrapper-script running shell which is pointless.
-rwxr-xr-xtests/runtests.pl68
-rw-r--r--tests/valgrind.pm109
2 files changed, 128 insertions, 49 deletions
diff --git a/tests/runtests.pl b/tests/runtests.pl
index 7af18d6a5..35b4ddd7f 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -6,7 +6,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -29,6 +29,7 @@ use strict;
@INC=(@INC, $ENV{'srcdir'}, ".");
require "getpart.pm"; # array functions
+require "valgrind.pm"; # valgrind report parser
my $srcdir = $ENV{'srcdir'} || '.';
my $HOSTIP="127.0.0.1";
@@ -94,6 +95,15 @@ if($valgrind) {
if (($? >> 8)==0) {
$valgrind_tool="--tool=memcheck ";
}
+ open(C, "<$CURL");
+ my $l = <C>;
+ if($l =~ /^\#\!/) {
+ # The first line starts with "#!" which implies a shell-script.
+ # This means libcurl is built shared and curl is a wrapper-script
+ # Disable valgrind in this setup
+ $valgrind=0;
+ }
+ close(C);
}
my $gdb = checkcmd("gdb");
@@ -1434,60 +1444,20 @@ sub singletest {
if($f =~ /^valgrind$testnum\.pid/) {
$l = $f;
last;
- }
- }
- my $leak;
- my $invalidread;
- my $uninitedvar;
- my $error;
- my $partial;
-
- open(VAL, "<log/$l");
- while(<VAL>) {
- if($_ =~ /definitely lost: (\d*) bytes/) {
- $leak = $1;
- if($leak) {
- $error++;
- }
- last;
- }
- elsif($_ =~ /Invalid read of size (\d+)/) {
- $invalidread = $1;
- $error++;
- last;
- }
- elsif($_ =~ /Conditional jump or move/) {
- # If we require SSL, this test case most probaly makes
- # us use OpenSSL. OpenSSL produces numerous valgrind
- # errors of this kind, rendering it impossible for us to
- # detect (valid) reports on actual curl or libcurl code.
-
- if(!$feature{'SSL'}) {
- $uninitedvar = 1;
- $error++;
- last;
- }
- else {
- $partial=1;
- }
}
}
- close(VAL);
- if($error) {
+ my $src=$ENV{'srcdir'};
+ if(!$src) {
+ $src=".";
+ }
+ my @e = valgrindparse($src, $feature{'SSL'}, "log/$l");
+ if($e[0]) {
print " valgrind ERROR ";
- if($leak) {
- print "\n Leaked $leak bytes\n";
- }
- if($invalidread) {
- print "\n Read $invalidread invalid bytes\n";
- }
- if($uninitedvar) {
- print "\n Conditional jump or move depends on uninitialised value(s)\n";
- }
+ print @e;
return 1;
}
elsif(!$short) {
- printf " valgrind %s", $partial?"PARTIAL":"OK";
+ printf " valgrind OK";
}
}
else {
diff --git a/tests/valgrind.pm b/tests/valgrind.pm
new file mode 100644
index 000000000..e2ead03c8
--- /dev/null
+++ b/tests/valgrind.pm
@@ -0,0 +1,109 @@
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://curl.haxx.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+# $Id$
+###########################################################################
+
+sub valgrindparse {
+ my ($srcdir, # the dir in which the runtests script resides
+ $sslenabled,
+ $file) = @_;
+ my $leak;
+ my $invalidread;
+ my $uninitedvar;
+ my $error;
+ my $partial;
+ my $us;
+
+ my @o;
+
+ my $bt=0;
+
+ open(VAL, "<$file");
+ while(<VAL>) {
+ if($bt) {
+ # back trace parsing
+ if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
+ my $w = $4;
+ if($w =~ /(.*) \(([^:]*):(\d+)/) {
+ my ($func, $source, $line)=($1, $2, $3);
+
+ if(-f "$srcdir/../src/$source" ||
+ -f "$srcdir/../lib/$source") {
+ # this is our source
+ # print "$func() at $source:$line\n";
+ $us++;
+ }
+ }
+ }
+ else {
+ if($us) {
+ # the stack trace included source details about us
+
+ $error++;
+ if($leak) {
+ push @o, "\n Leaked $leak bytes\n";
+ }
+ if($invalidread) {
+ push @o, "\n Read $invalidread invalid bytes\n";
+ }
+ if($uninitedvar) {
+ push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
+ }
+ }
+ $bt = 0; # no more backtrace
+ $us = 0;
+ }
+ }
+ else {
+ if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
+ $leak = $1;
+ if($leak) {
+ $error++;
+ }
+ $bt = 1;
+ }
+ elsif($_ =~ /Invalid read of size (\d+)/) {
+ $invalidread = $1;
+ $error++;
+ $bt = 1;
+ }
+ elsif($_ =~ /Conditional jump or move/) {
+ # If we require SSL, this test case most probaly makes
+ # us use OpenSSL. OpenSSL produces numerous valgrind
+ # errors of this kind, rendering it impossible for us to
+ # detect (valid) reports on actual curl or libcurl code.
+
+ if(!$sslenabled) {
+ $uninitedvar = 1;
+ $error++;
+ $bt = 1;
+ }
+ else {
+ $partial=1;
+ }
+ }
+ }
+ }
+ close(VAL);
+ return @o;
+}
+
+1;