1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl IPC-Semaphore-Concurrency.t'
4 #########################
6 # change 'tests => 1' to 'tests => last_test_to_print';
9 use POSIX qw(O_WRONLY O_CREAT O_NONBLOCK O_NOCTTY WNOHANG);
13 #########################
15 # Insert your test code below, the Test::More module is use()ed here so read
16 # its man page ( perldoc Test::More ) for help writing this test script.
18 # Skip all if the testing architecture doesn't support semaphores
19 # bits taken from IPC::SysV tests...
21 if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
22 plan(skip_all => 'IPC::SysV was not built');
24 if ($Config{'d_sem'} ne 'define' || $Config{'d_semget'} ne 'define' ||
25 $Config{'d_semctl'} ne 'define') {
26 plan(skip_all => 'Lacking d_sem, d_semget or d_semctl');
29 # Cygwin needs a cygserver running to handle IPC syscalls
30 if ($Config{'osname'} eq 'cygwin') {
31 system('ipcs -s >/dev/null 2>&1');
33 plan(skip_all => 'command "ipcs -s" failed; are you running cygserver?');
37 # My handy Acme Child Reaper(tm)
38 $SIG{'CHLD'} = sub { while (waitpid(-1, WNOHANG) > 0) {} };
41 my $base = ".IPC-Semaphore-Concurrency.test";
43 # Try different paths for writing the semaphore files
44 foreach my $prefix ('/tmp/', '/var/tmp/', '') {
45 my $tmpfile = $prefix.$base;
46 if (sysopen(my $f, "$tmpfile-0.$$", O_WRONLY|O_CREAT|O_NONBLOCK|O_NOCTTY)) {
48 # $base now becomes what we'll use for cleaning up...
54 if (!defined($file)) {
55 plan skip_all => "Can't create a file for named semaphores: $!";
60 # Can't do that at compile time with a flexible plan, but we don't use prototypes anyway
61 use_ok('IPC::Semaphore::Concurrency');
63 # Simple semaphore usage
64 my $c = IPC::Semaphore::Concurrency->new("$file-1.$$");
65 ok(defined($c), "Simple usage");
68 ok($c->remove(), "Remove semaphore");
71 # Full semaphore usage
72 $c = IPC::Semaphore::Concurrency->new(
79 ok(defined($c), "Full usage");
82 ok($c->remove(), "Remove semaphore");
86 system('rm -rf '.$base.'.IPC-Semaphore-Concurrency.test-*');