summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-06-16 06:59:16 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-06-16 06:59:16 +0000
commit622f2b6b7736fe8799845cb577ae677599541aee (patch)
tree8834b0e829ff1bfeeaf5b3226ba3d870c2425260
parent1ffa71f714346581eeeb0ef24febc5db3ea82ff5 (diff)
downloadlibhubbub-622f2b6b7736fe8799845cb577ae677599541aee.tar.gz
libhubbub-622f2b6b7736fe8799845cb577ae677599541aee.tar.bz2
Use IO::Select to avoid deadlock
svn path=/trunk/hubbub/; revision=4363
-rw-r--r--test/testrunner.pl105
1 files changed, 49 insertions, 56 deletions
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 = <TINDEX>) {
print "Test: $desc\n";
- my $pid;
-
if ($data) {
# Testcase has external data files
@@ -83,36 +82,8 @@ while (my $line = <TINDEX>) {
print $msg;
# Run testcase
- $pid = open3("&<NULL", \*OUT, \*ERR,
- "$directory/$test",
- "$directory/data/Aliases",
+ run_test("$directory/$test", "$directory/data/Aliases",
"$directory/data/$data/$dtest");
-
- my $last = "FAIL";
-
- # Marshal testcase output to log file
- while (my $output = <OUT>) {
- 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 = <ERR>) {
- print LOG " $errors";
- }
-
- print "\n\nFailure detected: " .
- "consult log file\n\n\n";
-
- exit(1);
- }
}
close(DINDEX);
@@ -127,41 +98,63 @@ while (my $line = <TINDEX>) {
print $msg;
# Run testcase
- $pid = open3("&<NULL", \*OUT, \*ERR,
- "$directory/$test", "$directory/data/Aliases");
+ run_test("$directory/$test", "$directory/data/Aliases");
+ }
- my $last = "FAIL";
+ print "\n";
+}
- # Marshal testcase output to log file
- while (my $output = <OUT>) {
- 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("&<NULL", \*OUT, \*ERR, @_);
+
+ $SIG{CHLD} = sub { waitpid($pid, 0); };
+
+ my $selector = IO::Select->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 = <ERR>) {
- 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 = <OUT>) {
+ print LOG " $output";
+ $last = $output;
+ }
+ } else {
+ my @tmp = <ERR>;
+ 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);