From: Vincent Pit Date: Sun, 29 Jun 2008 15:58:34 +0000 (+0200) Subject: Importing Test-Valgrind-0.02.tar.gz X-Git-Tag: v0.02^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Valgrind.git;a=commitdiff_plain;h=8e236cf7f5ac06829edb65527fcdf12716ecd159 Importing Test-Valgrind-0.02.tar.gz --- diff --git a/Changes b/Changes index 6533c9d..57c82a4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,16 @@ Revision history for Test-Valgrind +0.02 2008-04-21 15:25 UTC + + Add : Test::Valgrind now depends on Perl::Destruct::Level. This is + needed for non-debugging perls because we can't set their + level of memory cleanup correctness on exit with the + PERL_DESTRUCT_LEVEL environment variable. + + Add : Hardcode valgrind path into the new constant + Test::Valgrind::Suppressions::VG_PATH. + + Chg : Test::Valgrind::Suppressions::supppath() is now supp_path(). + + Chg : lib/Test/Valgrind/Suppressions.pm.tpl was renamed to + lib/Test/Valgrind/Suppressions.tpl for file portability reasons. + 0.01 2008-04-19 15:50 UTC First version, released on an unsuspecting world. diff --git a/MANIFEST b/MANIFEST index 21501aa..774c1e2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -7,6 +7,7 @@ gen.pl lib/Test/Valgrind.pm lib/Test/Valgrind/perlTestValgrind.supp lib/Test/Valgrind/Suppressions.pm +lib/Test/Valgrind/Suppressions.tpl samples/map.pl t/00-load.t t/01-import.t diff --git a/META.yml b/META.yml index f6ac313..884e5f0 100644 --- a/META.yml +++ b/META.yml @@ -1,7 +1,7 @@ --- #YAML:1.0 name: Test-Valgrind -version: 0.01 -abstract: Test your code through valgrind. +version: 0.02 +abstract: Test Perl code through valgrind. license: perl author: - Vincent Pit @@ -10,6 +10,7 @@ distribution_type: module requires: Carp: 0 Exporter: 0 + Perl::Destruct::Level: 0 POSIX: 0 Test::More: 0 meta-spec: diff --git a/Makefile.PL b/Makefile.PL index 62522ed..1d37fb9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -3,9 +3,10 @@ use warnings; use ExtUtils::MakeMaker; my $has_vg = 0; +my $vg; print 'Checking for valgrind >= 3.1.0 in PATH... '; for (split /:/, $ENV{PATH}) { - my $vg = $_ . '/valgrind'; + $vg = $_ . '/valgrind'; if (-x $vg) { my $ver = qx/$vg --version/; if ($ver =~ s/^valgrind-//) { @@ -38,7 +39,17 @@ sub build_req { return $build_req; } -my $supp = 'Test/Valgrind/perlTestValgrind.supp'; +my $supp = 'lib/Test/Valgrind/Suppressions'; +open my $tpl, '<', $supp . '.tpl' or die "open($supp.tpl): $!"; +open my $out, '>', $supp . '.pm' or die "open($supp.pm): $!"; +while (<$tpl>) { + s/(VG_PATH\s*=>\s*)undef/$1'$vg'/g; + print $out $_; +} +close $out; +close $tpl; + +$supp = 'Test/Valgrind/perlTestValgrind.supp'; WriteMakefile( NAME => 'Test::Valgrind', @@ -55,10 +66,11 @@ WriteMakefile( 'lib/' . $supp => '$(INST_ARCHLIB)/' . $supp, }, PREREQ_PM => { - 'Carp' => 0, - 'Exporter' => 0, - 'POSIX' => 0, - 'Test::More' => 0, + 'Carp' => 0, + 'Exporter' => 0, + 'POSIX' => 0, + 'Perl::Destruct::Level' => 0, + 'Test::More' => 0, }, dist => { PREOP => 'pod2text lib/Test/Valgrind.pm > $(DISTVNAME)/README; ' diff --git a/README b/README index acbd863..8ece675 100644 --- a/README +++ b/README @@ -1,13 +1,13 @@ NAME - Test::Valgrind - Test your code through valgrind. + Test::Valgrind - Test Perl code through valgrind. VERSION - Version 0.01 + Version 0.02 SYNOPSIS use Test::More; eval 'use Test::Valgrind'; - plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind'; + plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind' if $@; # Code to inspect for memory leaks/errors. @@ -20,6 +20,10 @@ DESCRIPTION parent then parses the report output by valgrind and pass or fail tests accordingly. + You can also use it from the command-line to test a given script : + + perl -MTest::Valgrind leaky.pl + CONFIGURATION You can pass parameters to "import" as a list of key / value pairs, where valid keys are : @@ -46,15 +50,25 @@ CONFIGURATION CAVEATS You can't use this module to test code given by the "-e" command-line - switch. This module is not really secure. It's definitely not taint - safe. That shouldn't be a problem for test files. If your tests output - to STDERR, everything will be eaten in the process. + switch. + + Results will most likely be better if your perl is built with debugging + enabled. Using the latest valgrind available will also help. + + This module is not really secure. It's definitely not taint safe. That + shouldn't be a problem for test files. + + If your tests output to STDERR, everything will be eaten in the process. + In particular, running this module against test files will obliterate + their original test results. DEPENDENCIES Valgrind 3.1.0 (). Carp, POSIX (core modules since perl 5) and Test::More (since 5.6.2). + Perl::Destruct::Level. + AUTHOR Vincent Pit, "", . @@ -73,6 +87,13 @@ SUPPORT perldoc Test::Valgrind +ACKNOWLEDGEMENTS + Rafaël Garcia-Suarez, for writing and instructing me about the + existence of Perl::Destruct::Level (Elizabeth Mattijsen is a close + second). + + H.Merijn Brand, for daring to test this thing. + COPYRIGHT & LICENSE Copyright 2008 Vincent Pit, all rights reserved. diff --git a/lib/Test/Valgrind.pm b/lib/Test/Valgrind.pm index 647cde9..b4ce022 100644 --- a/lib/Test/Valgrind.pm +++ b/lib/Test/Valgrind.pm @@ -7,25 +7,27 @@ use Carp qw/croak/; use POSIX qw/SIGTERM/; use Test::More; +use Perl::Destruct::Level level => 3; + use Test::Valgrind::Suppressions; =head1 NAME -Test::Valgrind - Test your code through valgrind. +Test::Valgrind - Test Perl code through valgrind. =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS use Test::More; eval 'use Test::Valgrind'; - plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind'; + plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind' if $@; # Code to inspect for memory leaks/errors. @@ -33,6 +35,10 @@ our $VERSION = '0.01'; This module lets you run some code through the B memory debugger, to test it for memory errors and leaks. Just add C at the beginning of the code you want to test. Behind the hood, C forks so that the child can basically C (except that of course C<$0> isn't right there). The parent then parses the report output by valgrind and pass or fail tests accordingly. +You can also use it from the command-line to test a given script : + + perl -MTest::Valgrind leaky.pl + =head1 CONFIGURATION You can pass parameters to C as a list of key / value pairs, where valid keys are : @@ -112,7 +118,7 @@ sub import { '--error-limit=yes' ); unless ($args{no_supp}) { - for (Test::Valgrind::Suppressions::supppath(), $args{supp}) { + for (Test::Valgrind::Suppressions::supp_path(), $args{supp}) { push @args, '--suppressions=' . $_ if $_; } } @@ -125,7 +131,8 @@ sub import { print STDERR "valgrind @args\n" if $args{diag}; local $ENV{PERL_DESTRUCT_LEVEL} = 3; local $ENV{PERL_DL_NONLAZY} = 1; - exec 'valgrind', @args; + my $vg = Test::Valgrind::Suppressions::VG_PATH; + exec $vg, @args if $vg and -x $vg; } close $wtr or croak "close(\$wtr): $!"; local $SIG{INT} = sub { kill -(SIGTERM) => $pid }; @@ -168,8 +175,12 @@ sub import { =head1 CAVEATS You can't use this module to test code given by the C<-e> command-line switch. + +Results will most likely be better if your perl is built with debugging enabled. Using the latest valgrind available will also help. + This module is not really secure. It's definitely not taint safe. That shouldn't be a problem for test files. -If your tests output to STDERR, everything will be eaten in the process. + +If your tests output to STDERR, everything will be eaten in the process. In particular, running this module against test files will obliterate their original test results. =head1 DEPENDENCIES @@ -177,6 +188,8 @@ Valgrind 3.1.0 (L). L, L (core modules since perl 5) and L (since 5.6.2). +L. + =head1 AUTHOR Vincent Pit, C<< >>, L. @@ -193,12 +206,17 @@ You can find documentation for this module with the perldoc command. perldoc Test::Valgrind +=head1 ACKNOWLEDGEMENTS + +Rafaël Garcia-Suarez, for writing and instructing me about the existence of L (Elizabeth Mattijsen is a close second). + +H.Merijn Brand, for daring to test this thing. + =head1 COPYRIGHT & LICENSE Copyright 2008 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. +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut diff --git a/lib/Test/Valgrind/Suppressions.pm b/lib/Test/Valgrind/Suppressions.pm index 12c6607..e69de29 100644 --- a/lib/Test/Valgrind/Suppressions.pm +++ b/lib/Test/Valgrind/Suppressions.pm @@ -1,82 +0,0 @@ -package Test::Valgrind::Suppressions; - -use strict; -use warnings; - -=head1 NAME - -Test::Valgrind::Suppressions - Placeholder for architecture-dependant perl suppressions. - -=head1 VERSION - -Version 0.01 - -=cut - -our $VERSION = '0.01'; - -=head1 DESCRIPTION - -L needs suppressions so that perl's errors aren't reported. However, these suppressions depend widely on the architecture, perl's version and the features it has been build with (e.g. threads). The goal of this module is hence to be installed together with the suppression file generated when the Test-Valgrind distribution was built, and to handle back to L the path to the suppression file. - -=head1 FUNCTIONS - -=head2 C - -Returns the path to the suppression file that applies to the current running perl, or C when no such file is available. - -=cut - -sub supppath { - my $pkg = __PACKAGE__; - $pkg =~ s!::!/!g; - $pkg .= '.pm'; - return if not $INC{$pkg}; - my $supp = $INC{$pkg}; - $supp =~ s![^/]*$!perlTestValgrind.supp!; - return (-f $supp) ? $supp : undef; -} - -=head1 EXPORT - -This module exports the L function only on demand, either by giving its name, or by the C<:funcs> or C<:all> tags. - -=cut - -use base qw/Exporter/; - -our @EXPORT = (); -our %EXPORT_TAGS = ( 'funcs' => [ qw/supppath/ ] ); -our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; -$EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; - -=head1 SEE ALSO - -L. - -=head1 AUTHOR - -Vincent Pit, C<< >>, L. - -You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince). - -=head1 BUGS - -Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. - -=head1 SUPPORT - -You can find documentation for this module with the perldoc command. - - perldoc Test::Valgrind::Suppressions - -=head1 COPYRIGHT & LICENSE - -Copyright 2008 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. - -=cut - -1; # End of Test::Valgrind::Suppressions diff --git a/lib/Test/Valgrind/Suppressions.tpl b/lib/Test/Valgrind/Suppressions.tpl new file mode 100644 index 0000000..f3f7636 --- /dev/null +++ b/lib/Test/Valgrind/Suppressions.tpl @@ -0,0 +1,94 @@ +package Test::Valgrind::Suppressions; + +use strict; +use warnings; + +=head1 NAME + +Test::Valgrind::Suppressions - Placeholder for architecture-dependant perl suppressions. + +=head1 VERSION + +Version 0.02 + +=cut + +our $VERSION = '0.02'; + +=head1 DESCRIPTION + +L needs suppressions so that perl's errors aren't reported. However, these suppressions depend widely on the architecture, perl's version and the features it has been build with (e.g. threads). The goal of this module is hence to be installed together with the suppression file generated when the Test-Valgrind distribution was built, and to handle back to L the path to the suppression file. + +=head1 FUNCTIONS + +=head2 C + +Returns the path to the suppression file that applies to the current running perl, or C when no such file is available. + +=cut + +sub supp_path { + my $pkg = __PACKAGE__; + $pkg =~ s!::!/!g; + $pkg .= '.pm'; + return if not $INC{$pkg}; + my $supp = $INC{$pkg}; + $supp =~ s![^/]*$!perlTestValgrind.supp!; + return (-f $supp) ? $supp : undef; +} + +=head1 CONSTANTS + +=head2 C + +The path to the valgrind binary from which the suppressions were generated. + +=cut + +use constant VG_PATH => undef; + +=head1 EXPORT + +This module exports the L function and the L constants only on demand, either by giving their name explicitely or by the C<:funcs>, C<:consts> or C<:all> tags. + +=cut + +use base qw/Exporter/; + +our @EXPORT = (); +our %EXPORT_TAGS = ( + 'funcs' => [ qw/supp_path/ ], + 'consts' => [ qw/VG_PATH/ ] +); +our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; +$EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; + +=head1 SEE ALSO + +L. + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Test::Valgrind::Suppressions + +=head1 COPYRIGHT & LICENSE + +Copyright 2008 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. + +=cut + +1; # End of Test::Valgrind::Suppressions diff --git a/t/01-import.t b/t/01-import.t index 8a40f8a..cb0938f 100644 --- a/t/01-import.t +++ b/t/01-import.t @@ -3,11 +3,11 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 2; require Test::Valgrind::Suppressions; -for (qw/supppath/) { +for (qw/supp_path VG_PATH/) { eval { Test::Valgrind::Suppressions->import($_) }; ok(!$@, 'import ' . $_); } diff --git a/t/10-suppressions.t b/t/10-suppressions.t index 9dc37d9..935dfbe 100644 --- a/t/10-suppressions.t +++ b/t/10-suppressions.t @@ -2,10 +2,12 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 2; -use Test::Valgrind::Suppressions qw/supppath/; +use Test::Valgrind::Suppressions qw/supp_path VG_PATH/; -my $path = supppath(); +my $path = supp_path(); like($path, qr!Test/Valgrind/perlTestValgrind\.supp$!, 'supppath() returns the path to the suppression file'); + +isnt(VG_PATH, undef, 'VG_PATH is defined');