From 622f2b6b7736fe8799845cb577ae677599541aee Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 16 Jun 2008 06:59:16 +0000 Subject: Use IO::Select to avoid deadlock svn path=/trunk/hubbub/; revision=4363 --- test/testrunner.pl | 105 +++++++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 56 deletions(-) (limited to 'test/testrunner.pl') diff --git a/test/testrunner.pl b/test/testrunner.pl index 4b59969..7faca23 100644 --- a/test/testrunner.pl +++ b/test/testrunner.pl @@ -14,6 +14,7 @@ use warnings; use strict; use File::Spec; +use IO::Select; use IPC::Open3; if (@ARGV < 1) { @@ -52,8 +53,6 @@ while (my $line = ) { print "Test: $desc\n"; - my $pid; - if ($data) { # Testcase has external data files @@ -83,36 +82,8 @@ while (my $line = ) { print $msg; # Run testcase - $pid = open3("&) { - print LOG " $output"; - $last = $output; - } - - # Wait for child to finish - waitpid($pid, 0); - - print substr($last, 0, 4) . "\n"; - - # Bail, noisily, on failure - if (substr($last, 0, 4) eq "FAIL") { - # Write any stderr output to the log - while (my $errors = ) { - print LOG " $errors"; - } - - print "\n\nFailure detected: " . - "consult log file\n\n\n"; - - exit(1); - } } close(DINDEX); @@ -127,41 +98,63 @@ while (my $line = ) { print $msg; # Run testcase - $pid = open3("&) { - print LOG " $output"; - $last = $output; - } +# Clean up +close(TINDEX); - # Wait for child to finish - waitpid($pid, 0); +close(NULL); +close(LOG); + +sub run_test +{ + my @errors; + + my $pid = open3("&new(); + $selector->add(*OUT, *ERR); - print substr($last, 0, 4) . "\n"; + my $last = "FAIL"; - # Bail, noisily, on failure - if (substr($last, 0, 4) eq "FAIL") { - # Write any stderr output to the log - while (my $errors = ) { - print LOG " $errors"; + # Marshal testcase output to log file + while (my @ready = $selector->can_read) { + foreach my $fh (@ready) { + if (fileno($fh) == fileno(OUT)) { + while (my $output = ) { + print LOG " $output"; + $last = $output; + } + } else { + my @tmp = ; + push(@errors, @tmp); } - print "\n\nFailure detected: " . - "consult log file\n\n\n"; + $selector->remove($fh) if eof($fh); + } + } + + print substr($last, 0, 4) . "\n"; - exit(1); + # Bail, noisily, on failure + if (substr($last, 0, 4) eq "FAIL") { + # Write any stderr output to the log + foreach my $error (@errors) { + print LOG " $error"; } + + print "\n\nFailure detected: consult log file\n\n\n"; + + exit(1); } - print "\n"; + close(OUT); + close(ERR); } -# Clean up -close(TINDEX); - -close(NULL); -close(LOG); -- cgit v1.2.3