summaryrefslogtreecommitdiff
path: root/t/harness
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-08-06 17:51:10 +0000
committerNicholas Clark <nick@ccl4.org>2008-08-06 17:51:10 +0000
commit9ae5a6c323cea172e440bd71782fdef16f8f20b1 (patch)
tree2b79030407cb05855cc446ad9d8ab3d73352cce7 /t/harness
parent7a7e49369367a634141dd279a31cb8e210734b24 (diff)
downloadperl-9ae5a6c323cea172e440bd71782fdef16f8f20b1.tar.gz
If TEST_JOBS is set to something non-zero, use TAP::Harness to run the
tests in parallel. The tests aren't fully parallelisable yet to the level we'd like, but one needs to start somewhere. p4raw-id: //depot/perl@34174
Diffstat (limited to 't/harness')
-rw-r--r--t/harness107
1 files changed, 90 insertions, 17 deletions
diff --git a/t/harness b/t/harness
index 1c6bcf1276..d137701d90 100644
--- a/t/harness
+++ b/t/harness
@@ -46,7 +46,7 @@ foreach (keys %datahandle) {
unlink "$_.t";
}
-my (@tests, $re);
+my (@tests, $rules, $re);
# [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
@ARGV = grep $_ && length( $_ ) => @ARGV;
@@ -55,6 +55,51 @@ sub _populate_hash {
return map {$_, 1} split /\s+/, $_[0];
}
+sub _glob_and_parallelise {
+ my @dirs;
+ # Run the tests in each of these directories in sequence, but the
+ # directories themselves can be parallelised.
+ foreach (@_) {
+ push @dirs, { seq => [ glob "$_/*.t" ] };
+ }
+ { par => \@dirs };
+}
+
+# Generate T::H schedule rules that run the contents of each directory
+# sequentially.
+sub _seq_dir_rules {
+ my @tests = @_;
+ my %dir;
+ for (@tests) {
+ s{[^/]+$}{\*};
+ $dir{$_}++;
+ }
+
+ return { par => [ map { { seq => $_ } } sort keys %dir ] };
+}
+
+sub _extract_tests;
+sub _extract_tests {
+ # This can probably be done more tersely with a map, but I doubt that it
+ # would be as clear
+ my @results;
+ foreach (@_) {
+ my $ref = ref $_;
+ if ($ref) {
+ if ($ref eq 'ARRAY') {
+ push @results, _extract_tests @$_;
+ } elsif ($ref eq 'HASH') {
+ push @results, _extract_tests values %$_;
+ } else {
+ die "Unknown reference type $ref";
+ }
+ } else {
+ push @results, $_;
+ }
+ }
+ @results;
+}
+
if ($ARGV[0] && $ARGV[0]=~/^-re/) {
if ($ARGV[0]!~/=/) {
shift;
@@ -73,18 +118,31 @@ if (@ARGV) {
@tests = @ARGV;
}
} else {
+ # Ideally we'd get somewhere close to Tux's Oslo rules
+ # my $rules = {
+ # par => [
+ # { seq => '../ext/DB_File/t/*' },
+ # { seq => '../ext/IO_Compress_Zlib/t/*' },
+ # { seq => '../lib/CPANPLUS/*' },
+ # { seq => '../lib/ExtUtils/t/*' },
+ # '*'
+ # ]
+ # };
+
+ # but for now, run all directories in sequence. In particular, it would be
+ # nice to get the tests in t/op/*.t able to run in parallel.
+
unless (@tests) {
- push @tests, <base/*.t>;
- push @tests, <comp/*.t>;
- push @tests, <cmd/*.t>;
- push @tests, <run/*.t>;
- push @tests, <io/*.t>;
- push @tests, <op/*.t>;
- push @tests, <uni/*.t>;
- push @tests, <mro/*.t>;
- push @tests, <lib/*.t>;
- push @tests, <japh/*.t> if $torture;
- push @tests, <win32/*.t> if $^O eq 'MSWin32';
+ my @seq;
+ push @seq, <base/*.t>;
+
+ push @seq, _glob_and_parallelise qw(comp cmd run io);
+ my @next = qw(op uni mro lib);
+ push @next, 'japh' if $torture;
+ push @next, 'win32' if $^O eq 'MSWin32';
+ push @seq, _glob_and_parallelise @next;
+
+ my @last;
use Config;
my %skip;
{
@@ -114,13 +172,20 @@ if (@ARGV) {
close MANI;
# Sort the list of test files read from MANIFEST into a sensible
# order instead of using the order in which they are listed there
- push @tests, sort { lc $a cmp lc $b } @manitests;
+ push @last, sort { lc $a cmp lc $b } @manitests;
} else {
warn "$0: cannot open $mani: $!\n";
}
- push @tests, <Module_Pluggable/*.t>;
- push @tests, <pod/*.t>;
- push @tests, <x2p/*.t>;
+ push @last, <Module_Pluggable/*.t>;
+ push @last, <pod/*.t>;
+ push @last, <x2p/*.t>;
+
+ @tests = (_extract_tests (@seq), @last);
+
+ push @seq, _seq_dir_rules @last;
+
+ $rules = { seq => \@seq };
+
}
}
if ($^O eq 'MSWin32') {
@@ -128,5 +193,13 @@ if ($^O eq 'MSWin32') {
}
@tests=grep /$re/, @tests
if $re;
-Test::Harness::runtests @tests;
+
+my $jobs = $ENV{TEST_JOBS};
+if ($jobs) {
+ eval 'use TAP::Harness 3.13; 1' or die $@;
+ my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules});
+ $h->runtests(@tests);
+} else {
+ Test::Harness::runtests @tests;
+}
exit(0);