]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Fix Savannah bug #20452.
authorPaul Smith <psmith@gnu.org>
Sat, 14 Jul 2007 02:57:46 +0000 (02:57 +0000)
committerPaul Smith <psmith@gnu.org>
Sat, 14 Jul 2007 02:57:46 +0000 (02:57 +0000)
Add a new feature to the test suite suggested by Icarus Sparry:
set a timer before invoking a test, so that if it loops infinitely we
will wake up and have a chance to kill the process and continue.

ChangeLog
file.c
tests/ChangeLog
tests/run_make_tests.pl
tests/scripts/features/parallelism
tests/scripts/options/dash-l
tests/test_driver.pl

index b9709fcc734eabab3e1fd8c672983dd93bcd08dc..9c9ed3ae45cff8a5d0cd12c40352bc9ab21d9967 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-07-13  Paul Smith  <psmith@gnu.org>
+
+       * file.c (expand_deps): Use variable_buffer as the start of the
+       buffer, not the original pointer (in case it was reallocated).
+       Fix suggested by Rafi Einstein <rafi.einstein@formalism-labs.com>.
+       Fixes Savannah bug #20452.
+
 2007-07-04  Paul Smith  <psmith@gnu.org>
 
        * (ALL FILES): Update to GPLv3.
diff --git a/file.c b/file.c
index 96aad1d2b31c4059be92e1d0aa31e7930ce11fba..303f192437c2b14bebe433d13c8993486138ab0a 100644 (file)
--- a/file.c
+++ b/file.c
@@ -483,6 +483,7 @@ expand_deps (struct file *f)
         {
           p = variable_expand ("");
           variable_buffer_output (p, d->name, strlen (d->name) + 1);
+          p = variable_buffer;
         }
       else
         {
@@ -495,7 +496,8 @@ expand_deps (struct file *f)
 
               o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
 
-              d->name = strcache_add_len (buffer, o - buffer);
+              d->name = strcache_add_len (variable_buffer,
+                                          o - variable_buffer);
               d->staticpattern = 0; /* Clear staticpattern so that we don't
                                        re-expand %s below. */
             }
index 93a9e3bf654220d04629d4d5623b36d258df89bd..6e53dc77aea28d3799b26f7dd2485876984573dd 100644 (file)
@@ -1,3 +1,23 @@
+2007-07-13  Paul Smith  <psmith@gnu.org>
+
+       Install a timeout so tests can never loop infinitely.
+       Original idea and patch for a single-test version provided by
+       Icarus Sparry <savannah@icarus.freeuk.com>
+
+       * test_driver.pl (_run_command): New function: this is called by
+       other functions to actually run a command.  Before we run it,
+       install a SIGALRM handler and set up a timer to go off in the
+       future (default is 5s; this can be overridden by individual tests).
+       (run_command): Call it.
+       (run_command_with_output): Call it.
+
+       * run_make_tests.pl (run_make_with_options): Override the default
+       timeout if the caller requests it.
+       (run_make_test): Pass any timeout override to run_make_with_options.
+
+       * scripts/features/parallelism: Increase the timeout for long tests.
+       * scripts/options/dash-l: Ditto.
+
 2006-10-01  Paul Smith  <psmith@paulandlesley.org>
 
        * run_make_tests.pl (set_more_defaults): Remove setting of LANG in
index 48be41befd48ada3744460c92a9d6c1b5a9f473a..0adb17200a3b1345e00cd07bf111a2ff3aed1983 100755 (executable)
@@ -82,7 +82,7 @@ $old_makefile = undef;
 
 sub run_make_test
 {
-  local ($makestring, $options, $answer, $err_code) = @_;
+  local ($makestring, $options, $answer, $err_code, $timeout) = @_;
 
   # If the user specified a makefile string, create a new makefile to contain
   # it.  If the first value is not defined, use the last one (if there is
@@ -121,7 +121,8 @@ sub run_make_test
   $answer =~ s/#MAKE#/$make_name/g;
   $answer =~ s/#PWD#/$pwd/g;
 
-  &run_make_with_options($makefile, $options, &get_logfile(0), $err_code);
+  run_make_with_options($makefile, $options, &get_logfile(0),
+                        $err_code, $timeout);
   &compare_output($answer, &get_logfile(1));
 
   $old_makefile = $makefile;
@@ -130,7 +131,7 @@ sub run_make_test
 
 # The old-fashioned way...
 sub run_make_with_options {
-  local ($filename,$options,$logname,$expected_code) = @_;
+  local ($filename,$options,$logname,$expected_code,$timeout) = @_;
   local($code);
   local($command) = $make_path;
 
@@ -151,7 +152,15 @@ sub run_make_with_options {
     print VALGRIND "\n\nExecuting: $command\n";
   }
 
-  $code = &run_command_with_output($logname,$command);
+
+  {
+      my $old_timeout = $test_timeout;
+      $test_timeout = $timeout if $timeout;
+
+      $code = &run_command_with_output($logname,$command);
+
+      $test_timeout = $old_timeout;
+  }
 
   # Check to see if we have Purify errors.  If so, keep the logfile.
   # For this to work you need to build with the Purify flag -exit-status=yes
index abe49a5dab0d2ed5b13fc591311a7f04214a3876..432c088988c0012eb27456109d2c8e60fdeb7590 100644 (file)
@@ -69,6 +69,7 @@ unlink('1.inc', '2.inc');
 # function in an exported recursive variable.  I added some code to check
 # for this situation and print a message if it occurred.  This test used
 # to trigger this code when I added it but no longer does after the fix.
+# We have to increase the timeout from the default (5s) on this test.
 
 run_make_test("
 export HI = \$(shell \$(\$\@.CMD))
@@ -79,7 +80,7 @@ second.CMD = $sleep_command 4; echo hi
 all: first second
 
 first second: ; \@echo \$\@; $sleep_command 1; echo \$\@",
-              '-j2', "first\nfirst\nsecond\nsecond");
+              '-j2', "first\nfirst\nsecond\nsecond", 0, 7);
 
 # Michael Matz <matz@suse.de> reported a bug where if make is running in
 # parallel without -k and two jobs die in a row, but not too close to each
index 58216f9fb19eb185623ad635f48bb1034138b723..0b0f196f9c926a4e204dc9588b12f2aebe05299b 100644 (file)
@@ -45,7 +45,8 @@ close(MAKEFILE);
 $mkoptions = "-l 0.0001";
 $mkoptions .= " -j 4" if ($parallel_jobs);
 
-&run_make_with_options($makefile, $mkoptions, &get_logfile);
+# We have to wait longer than the default (5s).
+&run_make_with_options($makefile, $mkoptions, &get_logfile, 0, 8);
 
 $slurp = &read_file_into_string (&get_logfile(1));
 if ($slurp !~ /cannot enforce load limit/) {
index 68007ec296805e0a1dfd12f1b9b59b0ecd3b15d3..bea98162322b3d50f39de6dea94376f190a1c050 100644 (file)
@@ -50,6 +50,10 @@ $tests_passed = 0;
 $test_passed = 1;
 
 
+# Timeout in seconds.  If the test takes longer than this we'll fail it.
+$test_timeout = 5;
+
+
 # %makeENV is the cleaned-out environment.
 %makeENV = ();
 
@@ -766,21 +770,43 @@ sub detach_default_output
          || &error ("ddo: $! closing SAVEDOSerr\n", 1);
 }
 
-# run one command (passed as a list of arg 0 - n), returning 0 on success
-# and nonzero on failure.
-
-sub run_command
+# This runs a command without any debugging info.
+sub _run_command
 {
-  local ($code);
+  my $code;
 
   # We reset this before every invocation.  On Windows I think there is only
   # one environment, not one per process, so I think that variables set in
   # test scripts might leak into subsequent tests if this isn't reset--???
   resetENV();
 
+  eval {
+      local $SIG{ALRM} = sub { die "timeout\n"; };
+      alarm $test_timeout;
+      $code = system @_;
+      alarm 0;
+  };
+  if ($@) {
+      # The eval failed.  If it wasn't SIGALRM then die.
+      $@ eq "timeout\n" or die;
+
+      # Timed out.  Resend the alarm to our process group to kill the children.
+      $SIG{ALRM} = 'IGNORE';
+      kill -14, $$;
+      $code = 14;
+  }
+
+  return $code;
+}
+
+# run one command (passed as a list of arg 0 - n), returning 0 on success
+# and nonzero on failure.
+
+sub run_command
+{
   print "\nrun_command: @_\n" if $debug;
-  $code = system @_;
-  print "run_command: \"@_\" returned $code.\n" if $debug;
+  my $code = _run_command(@_);
+  print "run_command returned $code.\n" if $debug;
 
   return $code;
 }
@@ -792,19 +818,13 @@ sub run_command
 
 sub run_command_with_output
 {
-  local ($filename) = shift;
-  local ($code);
-
-  # We reset this before every invocation.  On Windows I think there is only
-  # one environment, not one per process, so I think that variables set in
-  # test scripts might leak into subsequent tests if this isn't reset--???
-  resetENV();
+  my $filename = shift;
 
+  print "\nrun_command_with_output($filename): @_\n" if $debug;
   &attach_default_output ($filename);
-  $code = system @_;
+  my $code = _run_command(@_);
   &detach_default_output;
-
-  print "run_command_with_output: '@_' returned $code.\n" if $debug;
+  print "run_command_with_output returned $code.\n" if $debug;
 
   return $code;
 }