In perl.git, the branch nicholas/bisect has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/d05446d0b8f3ccc46ea6965233e755a716504e3d?hp=1c1d1477c40ba18f5b7be249cc0a880b95b84653>

- Log -----------------------------------------------------------------
commit d05446d0b8f3ccc46ea6965233e755a716504e3d
Author: Nicholas Clark <[email protected]>
Date:   Fri Apr 13 16:49:24 2012 +0200

    Add a --valgrind option to bisect.pl, to run the test program with valgrind.
    
    Specifically this option prepends valgrind --error-exitcode=124
    to the command line, so that git bisect run will treat this revision as a
    failure if valgrind finds any problems.

M       Porting/bisect-runner.pl

commit 914fb934cb18fa922834c5a4d915bb64b755ab7d
Author: Nicholas Clark <[email protected]>
Date:   Fri Apr 13 16:00:49 2012 +0200

    bisect-runner.pl will now invoke with ./perl -Ilib if it sees a #!./perl 
line
    
    If the first argument of the test case given to bisect-runner.pl is a 
readable
    file with a #! line of ./perl or ./miniperl (only), bisect-runner.pl with
    prepend ./perl -Ilib or ./miniperl -Ilib to the command sent to system.
    This increases flexibility somewhat, and will avoid problems with
    inconsistencies between directly running system(...), and running
    system('valgrind', ...). The former accepts a #!./perl line, the latter 
sends
    it to /bin/sh.

M       Porting/bisect-runner.pl
-----------------------------------------------------------------------

Summary of changes:
 Porting/bisect-runner.pl |   64 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/Porting/bisect-runner.pl b/Porting/bisect-runner.pl
index 65fe6d2..db7310d 100755
--- a/Porting/bisect-runner.pl
+++ b/Porting/bisect-runner.pl
@@ -14,6 +14,10 @@ my %options =
      clean => 1, # mostly for debugging this
     );
 
+# We accept #!./miniperl and #!./perl
+# We don't accept #!miniperl and #!perl as their intent is ambiguous
+my $run_with_our_perl = qr{\A#!(\./(?:mini)?perl)\b};
+
 my $linux64 = `uname -sm` eq "Linux x86_64\n" ? '64' : '';
 
 my @paths;
@@ -53,7 +57,7 @@ unless(GetOptions(\%options,
                       $options{'expect-pass'} = 0;
                   },
                   'force-manifest', 'force-regen', 'test-build', 'validate',
-                  'all-fixups', 'early-fixup=s@', 'late-fixup=s@',
+                  'all-fixups', 'early-fixup=s@', 'late-fixup=s@', 'valgrind',
                   'check-args', 'check-shebang!', 'usage|help|?', 'A=s@',
                   'D=s@' => sub {
                       my (undef, $val) = @_;
@@ -107,6 +111,8 @@ bisect.pl - use git bisect to pinpoint changes
          --expect-fail -e 'my $a := 2;'
     # What was the last revision to build with these options?
     .../Porting/bisect.pl --test-build -Dd_dosuid
+    # When did this test program start generating errors from valgrind?
+    .../Porting/bisect.pl --valgrind ../test_prog.pl
 
 =head1 DESCRIPTION
 
@@ -147,7 +153,10 @@ find the commit which caused the failure.
 
 Because the test case is the complete argument to C<system>, it is easy to
 run something other than the F<perl> built, if necessary. If you need to run
-the perl built, you'll probably need to invoke it as C<./perl -Ilib ...>
+the perl built, you'll probably need to invoke it as C<./perl -Ilib ...>.
+As a special case, if the first argument of the test case is a readable file
+(whether executable or not), matching C<qr{\A#!./(?:mini)?perl\b}> then it
+will have C<./perl> <-Ilib> (or C<./miniperl>) prepended to it.
 
 You need a clean checkout to run a bisect, and you can't use the checkout
 which contains F<Porting/bisect.pl> (because C<git bisect>) will check out
@@ -388,6 +397,24 @@ C<--no-match ...> is implemented as C<--expect-fail 
--match ...>
 
 =item *
 
+--valgrind
+
+Run the test program under C<valgrind>. If you need to test for memory
+errors when parsing invalid programs, the default parser fail exit code of
+255 will always override C<valgrind>, so try putting the test case invalid
+code inside a I<string> C<eval>, so that the perl interpreter will exit with 0.
+(Be sure to check the output of $@, to avoid missing mistakes such as
+unintended C<eval> failures due to incorrect C<@INC>)
+
+Specifically, this option prepends C<valgrind> C<--error-exitcode=124> to
+the command line that runs the testcase, to cause valgrind to exit non-zero
+if it detects errors, with the assumption that the test program itself
+always exits with zero. If you require more flexibility than this, either
+specify your C<valgrind> invocation explicitly as part of the test case, or
+use a wrapper script to control the command line or massage the exit codes.
+
+=item *
+
 --test-build
 
 Test that the build completes, without running any test case.
@@ -549,10 +576,10 @@ Validate the options and arguments, and exit silently if 
they are valid.
 
 Validate that the test case isn't an executable file with a
 C<#!/usr/bin/perl> line (or similar). As F<bisect-runner.pl> does B<not>
-prepend C<./perl> to the test case, a I<#!> line specifying an external
-F<perl> binary will cause the test case to always run with I<that> F<perl>,
-not the F<perl> built by the bisect runner. Likely this is not what you
-wanted. If your test case is actually a wrapper script to run other
+automatically prepend C<./perl> to the test case, a I<#!> line specifying an
+external F<perl> binary will cause the test case to always run with I<that>
+F<perl>, not the F<perl> built by the bisect runner. Likely this is not what
+you wanted. If your test case is actually a wrapper script to run other
 commands, you should run it with an explicit interpreter, to be clear. For
 example, instead of C<../perl/Porting/bisect.pl ~/test/testcase.pl> you'd
 run C<../perl/Porting/bisect.pl /usr/bin/perl ~/test/testcase.pl>
@@ -868,14 +895,15 @@ sub checkout_file {
 sub check_shebang {
     my $file = shift;
     return unless -e $file;
+    my $fh = open_or_die($file);
+    my $line = <$fh>;
+    return if $line =~ $run_with_our_perl;
     if (!-x $file) {
         die_255("$file is not executable.
 system($file, ...) is always going to fail.
 
 Bailing out");
     }
-    my $fh = open_or_die($file);
-    my $line = <$fh>;
     return unless $line =~ m{\A#!(/\S+/perl\S*)\s};
     die_255("$file will always be run by $1
 It won't be tested by the ./perl we build.
@@ -1187,6 +1215,26 @@ if (defined $options{'one-liner'}) {
     unshift @ARGV, "./$exe", '-Ilib';
 }
 
+if (-f $ARGV[0]) {
+    my $fh = open_or_die($ARGV[0]);
+    my $line = <$fh>;
+    unshift @ARGV, $1, '-Ilib'
+        if $line =~ $run_with_our_perl;
+}
+
+if ($options{valgrind}) {
+    # Turns out to be too confusing to use an optional argument with the path
+    # of the valgrind binary, as if --valgrind takes an optional argument,
+    # then specifying it as the last option eats the first part of the 
testcase.
+    # ie this: .../bisect.pl --valgrind testcase
+    # is treated as --valgrind=testcase and as there is no test case given,
+    # it's an invalid commandline, bailing out with the usage message.
+
+    # Currently, the test script can't signal a skip with 125, so anything
+    # non-zero would do. But to keep that option open in future, use 124
+    unshift @ARGV, 'valgrind', '--error-exitcode=124';
+}
+
 # This is what we came here to run:
 
 if (exists $Config{ldlibpthname}) {

--
Perl5 Master Repository

Reply via email to