]> git.vpit.fr Git - perl/modules/Linux-SysInfo.git/commitdiff
Test thread safety
authorVincent Pit <vince@profvince.com>
Thu, 12 Mar 2009 00:33:57 +0000 (01:33 +0100)
committerVincent Pit <vince@profvince.com>
Thu, 12 Mar 2009 00:33:57 +0000 (01:33 +0100)
MANIFEST
t/30-threads.t [new file with mode: 0644]

index 017eff0c68deeb55df08117ecf7ff036496790fa..b56ecd947af857052ad23ceab06fe89a3e0e42c3 100644 (file)
--- 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 (file)
index 0000000..2bec94f
--- /dev/null
@@ -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;