X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F30-threads.t;fp=t%2F30-threads.t;h=2bec94f8139789f0cb9f5e09490642a7f156ea8f;hb=86fd49234c91a91300d95ba292129a1825d396ab;hp=0000000000000000000000000000000000000000;hpb=7cc9831c8d8d6f3dee5a53b394d08775282df1d4;p=perl%2Fmodules%2FLinux-SysInfo.git diff --git a/t/30-threads.t b/t/30-threads.t new file mode 100644 index 0000000..2bec94f --- /dev/null +++ b/t/30-threads.t @@ -0,0 +1,41 @@ +#!perl -T + +use strict; +use warnings; + +use Config qw/%Config/; + +BEGIN { + if (!$Config{useithreads}) { + require Test::More; + Test::More->import; + plan(skip_all => 'This perl wasn\'t built to support threads'); + } +} + +use threads; + +use Test::More tests => 4 * 10; + +use Linux::SysInfo qw/sysinfo/; + +sub try { + my $tid = threads->tid(); + SKIP: { + my $si = sysinfo; + skip 'system error (sysinfo returned undef)' => 4 unless defined $si; + is ref($si), 'HASH', "sysinfo returns a hash reference in thread $tid"; + + for (1 .. 3) { + if (defined $si->{uptime}) { + like $si->{uptime}, qr/^\d+(?:\.\d+)?$/, + "key $_ looks like a number in thread $tid"; + } else { + fail "key $_ isn't defined in thread $tid"; + } + } + } +} + +my @t = map { threads->create(\&try, $_) } 1 .. 10; +$_->join for @t;