6 unshift @INC, '../lib';
8 require Config; import Config;
10 unless ($Config{'d_msg'} eq 'define' &&
11 $Config{'d_sem'} eq 'define') {
17 # These constants are common to all tests.
18 # Later the sem* tests will import more for themselves.
20 use IPC::SysV qw(IPC_PRIVATE IPC_NOWAIT IPC_STAT IPC_RMID
21 S_IRWXU S_IRWXG S_IRWXO S_IWGRP S_IROTH S_IWOTH);
29 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
31 # FreeBSD is known to throw this if there's no SysV IPC in the kernel.
35 It may be that your kernel does not have SysV IPC configured.
38 if ($^O eq 'freebsd') {
40 You must have following options in your kernel:
54 $perm = S_IRWXU | S_IRWXG | S_IRWXO | S_IWGRP | S_IROTH | S_IWOTH
57 $perm = S_IRWXU | S_IRWXG | S_IRWXO unless defined $perm;
59 if ($Config{'d_msgget'} eq 'define' &&
60 $Config{'d_msgctl'} eq 'define' &&
61 $Config{'d_msgsnd'} eq 'define' &&
62 $Config{'d_msgrcv'} eq 'define') {
64 $msg = msgget(IPC_PRIVATE, $perm);
65 # Very first time called after machine is booted value may be 0
66 die "msgget failed: $!\n" unless defined($msg) && $msg >= 0;
70 #Putting a message on the queue
72 my $msgtext = "hello";
74 msgsnd($msg,pack("L a*",$msgtype,$msgtext),0) or print "not ";
78 msgctl($msg,IPC_STAT,$data) or print "not ";
81 print "not " unless length($data);
85 msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT) or print "not ";
88 my($rmsgtype,$rmsgtext) = unpack("L a*",$msgbuf);
90 print "not " unless($rmsgtype == $msgtype && $rmsgtext eq $msgtext);
94 print "ok $_\n"; # fake it
98 if($Config{'d_semget'} eq 'define' &&
99 $Config{'d_semctl'} eq 'define') {
101 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
102 $Config{'d_semctl_semun'} eq 'define') {
104 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
106 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
107 # Very first time called after machine is booted value may be 0
108 die "semget: $!\n" unless defined($sem) && $sem >= 0;
113 semctl($sem,0,IPC_STAT,$data) or print "not ";
116 print "not " unless length($data);
121 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
125 semctl($sem,0,GETALL,$data) or print "not ";
128 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
131 my @data = unpack("s!*",$data);
133 my $adata = "0" x $nsem;
135 print "not " unless @data == $nsem and join("",@data) eq $adata;
141 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
145 semctl($sem,0,GETALL,$data) or print "not ";
148 @data = unpack("s!*",$data);
150 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
152 print "not " unless join("",@data) eq $bdata;
156 print "ok $_ # skipped, no semctl possible\n";
161 print "ok $_\n"; # fake it
166 msgctl($msg,IPC_RMID,0) if defined $msg;
167 semctl($sem,0,IPC_RMID,undef) if defined $sem;