1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl
3 # IPC-Semaphore-Concurrency.t'
5 #########################
7 # change 'tests => 1' to 'tests => last_test_to_print';
10 use POSIX qw(O_WRONLY O_CREAT O_NONBLOCK O_NOCTTY WNOHANG);
14 #########################
16 # Insert your test code below, the Test::More module is use()ed here so
17 # read its man page ( perldoc Test::More ) for help writing this test
20 # Skip all if the testing architecture doesn't support semaphores
21 # bits taken from IPC::SysV tests...
23 if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
24 plan(skip_all => 'IPC::SysV was not built');
26 if ($Config{'d_sem'} ne 'define' || $Config{'d_semget'} ne 'define' ||
27 $Config{'d_semctl'} ne 'define') {
28 plan(skip_all => 'Lacking d_sem, d_semget or d_semctl');
31 # Cygwin needs a cygserver running to handle IPC syscalls
32 if ($Config{'osname'} eq 'cygwin') {
33 system('ipcs -s >/dev/null 2>&1');
36 => 'command "ipcs -s" failed; are you running cygserver?');
40 # My handy Acme Child Reaper(tm)
41 $SIG{'CHLD'} = sub { while (waitpid(-1, WNOHANG) > 0) {} };
44 my $base = ".IPC-Semaphore-Concurrency.test";
46 # Try different paths for writing the semaphore files
47 foreach my $prefix ('/tmp/', '/var/tmp/', '') {
48 my $tmpfile = $prefix.$base;
49 if (sysopen(my $f, "$tmpfile-0.$$", O_WRONLY|O_CREAT|O_NONBLOCK|
52 # $base now becomes what we'll use for cleaning up...
58 if (!defined($file)) {
59 plan skip_all => "Can't create a file for named semaphores: $!";
64 # Can't do that at compile time with a flexible plan, but we don't use
66 use_ok('IPC::Semaphore::Concurrency');
68 # Simple semaphore usage
69 my $c = IPC::Semaphore::Concurrency->new("$file-1.$$");
70 ok(defined($c), "Simple usage");
73 ok($c->remove(), "Remove semaphore");
76 # Full semaphore usage
77 $c = IPC::Semaphore::Concurrency->new(
84 ok(defined($c), "Full usage");
87 ok($c->remove(), "Remove semaphore");
91 system('rm -rf '.$base.'.IPC-Semaphore-Concurrency.test-*');