b8c2594efc2b5c7ddba509c858fc54eb3b59a6aa
[platform/upstream/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 # $Id$
22 ###########################################################################
23
24 use File::Basename;
25
26 sub valgrindparse {
27     my ($srcdir,     # the dir in which the runtests script resides
28         $sslenabled,
29         $file) = @_;
30     my $leak;
31     my $invalidread;
32     my $uninitedvar;
33     my $error;
34     my $partial;
35     my $us;
36
37     my @o;
38
39     my $bt=0;
40
41     open(VAL, "<$file");
42     while(<VAL>) {
43         if($bt) {
44             # back trace parsing
45             if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
46                 my $w = $4;
47                 if($w =~ /(.*) \(([^:]*):(\d+)/) {
48                     my ($func, $source, $line)=($1, $2, $3);
49                     my $sourcename = basename($source);
50                     if(-f "$srcdir/../src/$sourcename" ||
51                        -f "$srcdir/../lib/$sourcename") {
52                         # this is our source
53  #                       print "$func() at $source:$line\n";
54                         $us++;
55                     } #else {print "Not our source: $func, $source, $line\n";}
56                 }
57             }
58             else {
59                 if($us) {
60                     # the stack trace included source details about us
61
62                     $error++;
63                     if($leak) {
64                         push @o, "\n Leaked $leak bytes\n";
65                     }
66                     if($invalidread) {
67                         push @o, "\n Read $invalidread invalid bytes\n";
68                     }
69                     if($uninitedvar) {
70                         push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
71                     }
72                 }
73                 $bt = 0; # no more backtrace
74                 $us = 0;
75             }
76         }
77         else {
78             if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
79                 $leak = $1;
80                 if($leak) {
81                     $error++;
82                 }
83                 $bt = 1;
84             }
85             elsif($_ =~ /Invalid read of size (\d+)/) {
86                 $invalidread = $1;
87                 $error++;
88                 $bt = 1;
89             }
90             elsif($_ =~ /Conditional jump or move/) {
91                 # If we require SSL, this test case most probaly makes
92                 # us use OpenSSL. OpenSSL produces numerous valgrind
93                 # errors of this kind, rendering it impossible for us to
94                 # detect (valid) reports on actual curl or libcurl code.
95
96                 if(!$sslenabled) {
97                     $uninitedvar = 1;
98                     $error++;
99                     $bt = 1;
100                 }
101                 else {
102                     $partial=1;
103                 }
104             }
105         }
106     }
107     close(VAL);
108     return @o;
109 }
110
111 1;