Git init
[external/curl.git] / tests / valgrind.pm
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 ###########################################################################
22
23 use File::Basename;
24
25 sub valgrindparse {
26     my ($srcdir,     # the dir in which the runtests script resides
27         $sslenabled,
28         $file) = @_;
29     my $leak;
30     my $invalidread;
31     my $uninitedvar;
32     my $error;
33     my $partial;
34     my $us;
35
36     my @o;
37
38     my $bt=0;
39
40     open(VAL, "<$file");
41     while(<VAL>) {
42         if($bt) {
43             # back trace parsing
44             if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
45                 my $w = $4;
46                 if($w =~ /(.*) \(([^:]*):(\d+)/) {
47                     my ($func, $source, $line)=($1, $2, $3);
48                     my $sourcename = basename($source);
49                     if(-f "$srcdir/../src/$sourcename" ||
50                        -f "$srcdir/../lib/$sourcename") {
51                         # this is our source
52  #                       print "$func() at $source:$line\n";
53                         $us++;
54                     } #else {print "Not our source: $func, $source, $line\n";}
55                 }
56             }
57             else {
58                 if($us) {
59                     # the stack trace included source details about us
60
61                     $error++;
62                     if($leak) {
63                         push @o, "\n Leaked $leak bytes\n";
64                     }
65                     if($invalidread) {
66                         push @o, "\n Read $invalidread invalid bytes\n";
67                     }
68                     if($uninitedvar) {
69                         push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
70                     }
71                 }
72                 $bt = 0; # no more backtrace
73                 $us = 0;
74             }
75         }
76         else {
77             if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
78                 $leak = $1;
79                 if($leak) {
80                     $error++;
81                 }
82                 $bt = 1;
83             }
84             elsif($_ =~ /Invalid read of size (\d+)/) {
85                 $invalidread = $1;
86                 $error++;
87                 $bt = 1;
88             }
89             elsif($_ =~ /Conditional jump or move/) {
90                 # If we require SSL, this test case most probaly makes
91                 # us use OpenSSL. OpenSSL produces numerous valgrind
92                 # errors of this kind, rendering it impossible for us to
93                 # detect (valid) reports on actual curl or libcurl code.
94
95                 if(!$sslenabled) {
96                     $uninitedvar = 1;
97                     $error++;
98                     $bt = 1;
99                 }
100                 else {
101                     $partial=1;
102                 }
103             }
104         }
105     }
106     close(VAL);
107     return @o;
108 }
109
110 1;