Make sure to abort the test if a thread dies
[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';
16
17$|++; # seems to be critical
18
19share $::TEST_COUNT;
20
21# older perls crash if threads are spawned way too quickly, sleep for 100 msecs
e38f7884 22my @pool = map { sleep 0.1 and threads->create(\&run_torture) } (1..($ENV{AUTOMATED_TESTING} ? 20 : 5) );
23for (@pool) {
24 if ($_->join != 42) {
25 die ($_->can('error') ? $_->error : "Thread did not finish successfully" );
26 }
27}
24538b08 28
29if ($ENV{AUTOMATED_TESTING}) {
30 my $vsz;
31 if (-f "/proc/$$/stat") {
32 my $proc_stat = do { local (@ARGV, $/) = "/proc/$$/stat"; <> };
33 ($vsz) = map { $_ / 1024 }
34 (split (/\s+/, $proc_stat))[-22]; # go backwards because the %s of the procname can contain anything
35 }
36
37 printf STDERR "#\n# VSIZE:%dKiB\n", $vsz
38 if $vsz;
39}
40
41print "1..$::TEST_COUNT\n";
42
43sub run_torture {
e38f7884 44 do 't/03torture.t';
24538b08 45 die $@ if $@ ne '';
e38f7884 46 42;
24538b08 47}