]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Tool/memcheck.pm
This is 1.19
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Tool / memcheck.pm
index fef177a5f5c296e0abfcf95585c1efd60d7dc911..27a2a62eed0abe2d820f151d5ff77fc1849959e6 100644 (file)
@@ -9,19 +9,21 @@ Test::Valgrind::Tool::memcheck - Run an analysis through the memcheck tool.
 
 =head1 VERSION
 
-Version 1.10
+Version 1.19
 
 =cut
 
-our $VERSION = '1.10';
+our $VERSION = '1.19';
 
 =head1 DESCRIPTION
 
-This tool parses the XML output of a C<memcheck> run with L<XML::Twig>.
+This class contains the information required by the session for running the C<memcheck> tool.
 
 =cut
 
-use base qw/Test::Valgrind::Tool/;
+use Scalar::Util ();
+
+use base qw<Test::Valgrind::Tool>;
 
 =head1 METHODS
 
@@ -29,13 +31,20 @@ This class inherits L<Test::Valgrind::Tool>.
 
 =head2 C<requires_version>
 
+    my $required_version = $tvt->requires_version;
+
 This tool requires C<valgrind> C<3.1.0>.
 
 =cut
 
 sub requires_version { '3.1.0' }
 
-=head2 C<< new callers => $callers, ... >>
+=head2 C<new>
+
+    my $tvtm = Test::Valgrind::Tool::memcheck->new(
+     callers => $callers,
+     %extra_args,
+    );
 
 Your usual constructor.
 
@@ -51,8 +60,11 @@ sub new {
 
  my %args = @_;
 
- my $callers = delete $args{callers} || 12;
- $callers =~ s/\D//g;
+ my $callers = delete $args{callers};
+ $callers = 24 unless $callers;
+ die 'Invalid number of callers'
+            unless Scalar::Util::looks_like_number($callers) and $callers > 0
+                                                             and $callers <= 24;
 
  my $self = bless $class->Test::Valgrind::Tool::new(%args), $class;
 
@@ -61,10 +73,12 @@ sub new {
  $self;
 }
 
-sub new_trainer { shift->new(callers => 50) }
+sub new_trainer { shift->new(callers => 24) }
 
 =head2 C<callers>
 
+    my $callers = $tvtm->callers;
+
 Read-only accessor for the C<callers> option.
 
 =cut
@@ -73,9 +87,11 @@ sub callers { $_[0]->{callers} }
 
 sub suppressions_tag { 'memcheck-' . $_[1]->version }
 
-=head2 C<parser_class $session>
+=head2 C<parser_class>
+
+    my $parser_class = $tvtm->parser_class($session);
 
-This tool uses a C<Test::Valgrind::Parser::XML::Twig> parser in analysis mode, and a C<Test::Valgrind::Parser::Suppressions::Text> parser in suppressions mode.
+This tool uses a L<Test::Valgrind::Parser::XML::Twig> parser in analysis mode, and a L<Test::Valgrind::Parser::Suppressions::Text> parser in suppressions mode.
 
 =cut
 
@@ -86,23 +102,31 @@ sub parser_class {
            ? 'Test::Valgrind::Parser::Suppressions::Text'
            : 'Test::Valgrind::Parser::XML::Twig';
 
- local $@;
- eval "require $class";
+ {
+  local $@;
+  eval "require $class; 1" or die $@;
+ }
 
  return $class;
 }
 
-=head2 C<report_class $session>
+=head2 C<report_class>
+
+    my $report_class = $tvtm->report_class($session);
 
-This tool emits C<Test::Valgrind::Tool::memcheck::Report> object reports in analysis mode.
+This tool emits C<Test::Valgrind::Tool::memcheck::Report> object reports in analysis mode, and C<Test::Valgrind::Report::Suppressions> object reports in suppressions mode.
 
 =cut
 
 sub report_class {
  my ($self, $session) = @_;
 
- $session->do_suppressions ? 'Test::Valgrind::Report::Suppressions'
-                           : 'Test::Valgrind::Tool::memcheck::Report'
+ if ($session->do_suppressions) {
+  require Test::Valgrind::Parser::Suppressions::Text;
+  return 'Test::Valgrind::Report::Suppressions';
+ } else {
+  return 'Test::Valgrind::Tool::memcheck::Report';
+ }
 }
 
 sub args {
@@ -118,10 +142,8 @@ sub args {
   '--error-limit=yes',
  );
 
- unless ($sess->do_suppressions) {
-  push @args, '--track-origins=yes' if $sess->version ge '3.4.0';
-  push @args, '--xml=yes';
- }
+ push @args, '--track-origins=yes' if  $sess->version >= '3.4.0'
+                                   and not $sess->do_suppressions;
 
  push @args, $self->SUPER::args(@_);
 
@@ -132,8 +154,6 @@ sub args {
 
 L<Test::Valgrind>, L<Test::Valgrind::Tool>.
 
-L<XML::Twig>.
-
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
@@ -153,7 +173,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2009 Vincent Pit, all rights reserved.
+Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
 
@@ -163,11 +183,11 @@ This program is free software; you can redistribute it and/or modify it under th
 
 package Test::Valgrind::Tool::memcheck::Report;
 
-use base qw/Test::Valgrind::Report/;
+use base qw<Test::Valgrind::Report>;
 
-our $VERSION = '1.10';
+our $VERSION = '1.19';
 
-my @kinds = qw/
+my @kinds = qw<
  InvalidFree
  MismatchedFree
  InvalidRead
@@ -183,7 +203,7 @@ my @kinds = qw/
  Leak_IndirectlyLost
  Leak_PossiblyLost
  Leak_StillReachable
-/;
+>;
 push @kinds, __PACKAGE__->SUPER::kinds();
 
 my %kinds_hashed = map { $_ => 1 } @kinds;
@@ -220,9 +240,9 @@ sub dump {
    my ($ip, $obj, $fn, $dir, $file, $line) = map { (defined) ? $_ : '?' } @$_;
    my $frame;
    if ($fn eq '?' and $obj eq '?') {
-    $ip =~ s/^0x//g;
-    $ip = hex $ip;
-    $frame = sprintf "0x%0${pad}X", $ip;
+    $ip =~ s/^0x//gi;
+    my $l = length $ip;
+    $frame = '0x' . ($l < $pad ? ('0' x ($pad - $l)) : '') . uc($ip);
    } else {
     $frame = sprintf '%s (%s) [%s:%s]', $fn, $obj, $file, $line;
    }