1 ################################################################################
5 # $Date: 2010/03/07 16:01:42 +0100 $
7 ################################################################################
9 # Version 2.x, Copyright (C) 2007-2010, Marcus Holland-Moritz <mhx@cpan.org>.
10 # Version 1.x, Copyright (C) 1999, Graham Barr <gbarr@pobox.com>.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
15 ################################################################################
18 if ($ENV{'PERL_CORE'}) {
20 @INC = '../lib' if -d '../lib' && -d '../ext';
23 require Test::More; import Test::More;
24 require Config; import Config;
26 if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
27 plan(skip_all => 'IPC::SysV was not built');
31 if ($Config{'d_shm'} ne 'define') {
32 plan(skip_all => '$Config{d_shm} undefined');
35 use IPC::SysV qw( IPC_PRIVATE S_IRWXU );
40 if (exists $SIG{SYS}) {
41 local $SIG{SYS} = sub { plan(skip_all => "SIGSYS caught") };
45 }->(sub { IPC::SharedMem->new(IPC_PRIVATE, 8, S_IRWXU) });
47 unless (defined $shm) {
48 my $info = "IPC::SharedMem->new failed: $!";
49 if ($! == &IPC::SysV::ENOSPC || $! == &IPC::SysV::ENOSYS ||
50 $! == &IPC::SysV::ENOMEM || $! == &IPC::SysV::EACCES) {
51 plan(skip_all => $info);
60 pass('acquired shared mem');
65 is($st->nattch, 0, 'st->nattch');
66 is($st->cpid, $$, 'cpid');
67 ok($st->segsz >= 8, 'segsz');
69 ok($shm->write(pack("N", 4711), 0, 4), 'write(offs=0)');
70 ok($shm->write(pack("N", 210577), 4, 4), 'write(offs=4)');
72 is($shm->read(0, 4), pack("N", 4711), 'read(offs=0)');
73 is($shm->read(4, 4), pack("N", 210577), 'read(offs=4)');
75 ok($shm->attach, 'attach');
80 is($st->nattch, 1, 'st->nattch');
81 is($st->cpid, $$, 'lpid');
83 is($shm->read(0, 4), pack("N", 4711), 'read(offs=0)');
84 is($shm->read(4, 4), pack("N", 210577), 'read(offs=4)');
86 ok($shm->write("Shared", 1, 6), 'write(offs=1)');
88 ok(!$shm->is_removed, '!is_removed');
89 ok($shm->remove, 'remove');
90 ok($shm->is_removed, 'is_removed');
92 is($shm->read(1, 6), 'Shared', 'read(offs=1)');
93 ok($shm->write("Memory", 0, 6), 'write(offs=0)');
94 is(unpack("P6", $shm->addr), 'Memory', 'read using unpack');
96 ok($shm->detach, 'detach');