From: Vincent Pit Date: Thu, 12 Mar 2009 00:33:57 +0000 (+0100) Subject: Test thread safety X-Git-Tag: v0.12~11 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=86fd49234c91a91300d95ba292129a1825d396ab;p=perl%2Fmodules%2FLinux-SysInfo.git Test thread safety --- diff --git a/MANIFEST b/MANIFEST index 017eff0..b56ecd9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,6 +10,7 @@ t/00-load.t t/01-import.t t/10-standard.t t/20-extended.t +t/30-threads.t t/91-pod.t t/92-pod-coverage.t t/95-portability-files.t 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;