2 Test::Valgrind - Generate suppressions, analyse and test any command
9 # From the command-line
10 perl -MTest::Valgrind leaky.pl
12 # From the command-line, snippet style
13 perl -MTest::Valgrind -e 'leaky()'
17 eval 'use Test::Valgrind';
18 plan skip_all => 'Test::Valgrind is required to test your distribution with valgrind' if $@;
21 # In all the test files of a directory
22 prove --exec 'perl -Iblib/lib -Iblib/arch -MTest::Valgrind' t/*.t
25 This module is a front-end to the "Test::Valgrind::*" API that lets you
26 run Perl code through the "memcheck" tool of the "valgrind" memory
27 debugger, to test for memory errors and leaks. If they aren't available
28 yet, it will first generate suppressions for the current "perl"
29 interpreter and store them in the portable flavour of
30 ~/.perl/Test-Valgrind/suppressions/$VERSION. The actual run will then
31 take place, and tests will be passed or failed according to the result
34 The complete API is much more versatile than this. By declaring an
35 appropriate Test::Valgrind::Command class, you can run any executable
36 (that is, not only Perl scripts) under valgrind, generate the
37 corresponding suppressions on-the-fly and convert the analysis result to
38 TAP output so that it can be incorporated into your project's testsuite.
39 If you're not interested in producing TAP, you can output the results in
40 whatever format you like (for example HTML pages) by defining your own
41 Test::Valgrind::Action class.
43 Due to the nature of perl's memory allocator, this module can't track
44 leaks of Perl objects. This includes non-mortalized scalars and memory
45 cycles. However, it can track leaks of chunks of memory allocated in XS
46 extensions with "Newx" and friends or "malloc". As such, it's
47 complementary to the other very good leak detectors listed in the "SEE
51 "analyse [ %options ]"
52 Run a "valgrind" analysis configured by %options :
54 * "command => $command"
56 The Test::Valgrind::Command object (or class name) to use.
58 Defaults to Test::Valgrind::Command::PerlScript.
62 The Test::Valgrind::Tool object (or class name) to use.
64 Defaults to Test::Valgrind::Tool::memcheck.
68 The Test::Valgrind::Action object (or class name) to use.
70 Defaults to Test::Valgrind::Action::Test.
74 The file name of the script to analyse.
76 Ignored if you supply your own custom "command", but mandatory
79 * "callers => $number"
81 Specify the maximum stack depth studied when valgrind encounters an
82 error. Raising this number improves granularity.
84 Ignored if you supply your own custom "tool", otherwise defaults to
89 If true, print the output of the test script as diagnostics.
91 Ignored if you supply your own custom "action", otherwise defaults
94 * "extra_supps => \@files"
96 Also use suppressions from @files besides "perl"'s.
100 * "no_def_supp => $bool"
102 If true, do not use the default suppression file.
106 "import [ %options ]"
107 In the parent process, "import" calls "analyse" with the arguments it
108 received itself - except that if no "file" option was supplied, it tries
109 to pick the first caller context that looks like a script. When the
110 analysis ends, it exits with the status returned by the action (for the
111 default TAP-generator action, it's the number of failed tests).
113 In the child process, it just "return"s so that the calling code is
114 actually run under "valgrind", albeit two side-effects :
116 * Perl::Destruct::Level is loaded and the destruction level is set to
119 * Autoflush on "STDOUT" is turned on.
123 When set to true, all dynamic extensions that were loaded during the
124 analysis will be unloaded at "END" time by "dl_unload_file" in
127 Since this obfuscates error stack traces, it's disabled by default.
130 Perl 5.8 is notorious for leaking like there's no tomorrow, so the
131 suppressions are very likely not to be complete on it. You also have a
132 better chance to get more accurate results if your perl is built with
133 debugging enabled. Using the latest "valgrind" available will also help.
135 This module is not really secure. It's definitely not taint safe. That
136 shouldn't be a problem for test files.
138 What your tests output to "STDOUT" and "STDERR" is eaten unless you pass
139 the "diag" option, in which case it will be reprinted as diagnostics.
142 XML::Twig, version, File::HomeDir, Env::Sanctify, Perl::Destruct::Level.
145 All the "Test::Valgrind::*" API, including Test::Valgrind::Command,
146 Test::Valgrind::Tool, Test::Valgrind::Action and
147 Test::Valgrind::Session.
149 The valgrind(1) man page.
153 Devel::Leak, Devel::LeakTrace, Devel::LeakTrace::Fast.
156 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
158 You can contact me by mail or on "irc.perl.org" (vincent).
161 Please report any bugs or feature requests to "bug-test-valgrind at
162 rt.cpan.org", or through the web interface at
163 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>. I will
164 be notified, and then you'll automatically be notified of progress on
165 your bug as I make changes.
168 You can find documentation for this module with the perldoc command.
170 perldoc Test::Valgrind
173 Rafaƫl Garcia-Suarez, for writing and instructing me about the existence
174 of Perl::Destruct::Level (Elizabeth Mattijsen is a close second).
176 H.Merijn Brand, for daring to test this thing.
178 David Cantrell, for providing shell access to one of his smokers where
179 the tests were failing.
181 The debian-perl team, for offering all the feedback they could regarding
182 the build issues they met.
184 All you people that showed interest in this module, which motivated me
185 into completely rewriting it.
188 Copyright 2008,2009,2010,2011 Vincent Pit, all rights reserved.
190 This program is free software; you can redistribute it and/or modify it
191 under the same terms as Perl itself.