Ensure we can run under prove -T
[p5sagit/Devel-PeekPoke.git] / t / 04thread-torture.t
CommitLineData
24538b08 1use Config;
2BEGIN {
3 unless ($Config{useithreads}) {
4 print "1..0 # SKIP your perl does not support ithreads\n";
5 exit 0;
6 }
7}
8
9use threads;
10use threads::shared;
11
12use strict;
13use warnings;
14no warnings 'once';
15use Time::HiRes 'sleep';
13793f05 16use Cwd 'getcwd';
24538b08 17
18$|++; # seems to be critical
19
20share $::TEST_COUNT;
21
22# older perls crash if threads are spawned way too quickly, sleep for 100 msecs
e38f7884 23my @pool = map { sleep 0.1 and threads->create(\&run_torture) } (1..($ENV{AUTOMATED_TESTING} ? 20 : 5) );
c1ec81b5 24
25# again - necessary for older perls
26sleep 1;
27
e38f7884 28for (@pool) {
29 if ($_->join != 42) {
30 die ($_->can('error') ? $_->error : "Thread did not finish successfully" );
31 }
32}
24538b08 33
34if ($ENV{AUTOMATED_TESTING}) {
35 my $vsz;
36 if (-f "/proc/$$/stat") {
37 my $proc_stat = do { local (@ARGV, $/) = "/proc/$$/stat"; <> };
38 ($vsz) = map { $_ / 1024 }
39 (split (/\s+/, $proc_stat))[-22]; # go backwards because the %s of the procname can contain anything
40 }
41
42 printf STDERR "#\n# VSIZE:%dKiB\n", $vsz
43 if $vsz;
44}
45
46print "1..$::TEST_COUNT\n";
47
48sub run_torture {
13793f05 49 do( ( "@{[ getcwd() ]}/t/03torture.t" =~ /^(.*)$/ )[0] );
24538b08 50 die $@ if $@ ne '';
e38f7884 51 42;
24538b08 52}