]> git.vpit.fr Git - perl/modules/Linux-SysInfo.git/blob - t/30-threads.t
Test thread safety
[perl/modules/Linux-SysInfo.git] / t / 30-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Config qw/%Config/;
7
8 BEGIN {
9  if (!$Config{useithreads}) {
10   require Test::More;
11   Test::More->import; 
12   plan(skip_all => 'This perl wasn\'t built to support threads');
13  }
14 }
15
16 use threads;
17
18 use Test::More tests => 4 * 10;
19
20 use Linux::SysInfo qw/sysinfo/;
21
22 sub try {
23  my $tid = threads->tid();
24  SKIP: {
25   my $si = sysinfo;
26   skip 'system error (sysinfo returned undef)' => 4 unless defined $si;
27   is ref($si), 'HASH', "sysinfo returns a hash reference in thread $tid";
28
29   for (1 .. 3) {
30    if (defined $si->{uptime}) {
31     like $si->{uptime}, qr/^\d+(?:\.\d+)?$/,
32                                     "key $_ looks like a number in thread $tid";
33    } else {
34     fail "key $_ isn't defined in thread $tid";
35    }
36   }
37  }
38 }
39
40 my @t = map { threads->create(\&try, $_) } 1 .. 10;
41 $_->join for @t;