8 require Config; import Config;
12 if ($Config{'extensions'} !~ /\bIPC\/SysV\b/) {
13 $reason = 'IPC::SysV was not built';
14 } elsif ($Config{'d_sem'} ne 'define') {
15 $reason = '$Config{d_sem} undefined';
16 } elsif ($Config{'d_msg'} ne 'define') {
17 $reason = '$Config{d_msg} undefined';
20 print "1..0 # Skip: $reason\n";
25 # These constants are common to all tests.
26 # Later the sem* tests will import more for themselves.
28 use IPC::SysV qw(IPC_PRIVATE IPC_NOWAIT IPC_STAT IPC_RMID S_IRWXU);
36 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
38 # FreeBSD is known to throw this if there's no SysV IPC in the kernel.
42 It may be that your kernel does not have SysV IPC configured.
45 if ($^O eq 'freebsd') {
47 You must have following options in your kernel:
61 if ($Config{'d_msgget'} eq 'define' &&
62 $Config{'d_msgctl'} eq 'define' &&
63 $Config{'d_msgsnd'} eq 'define' &&
64 $Config{'d_msgrcv'} eq 'define') {
66 $msg = msgget(IPC_PRIVATE, $perm);
67 # Very first time called after machine is booted value may be 0
68 die "msgget failed: $!\n" unless defined($msg) && $msg >= 0;
72 #Putting a message on the queue
74 my $msgtext = "hello";
80 unless (msgsnd($msg,pack("L! a*",$msgtype,$msgtext),IPC_NOWAIT)) {
88 # The failure of the subtest #2 may indicate that the message queue
89 # resource limits either of the system or of the testing account
90 # have been reached. Error message "Operating would block" is
91 # usually indicative of this situation. The error message was now:
94 # You can check the message queues with the 'ipcs' command and
95 # you can remove unneeded queues with the 'ipcrm -q id' command.
96 # You may also consider configuring your system or account
97 # to have more message queue resources.
99 # Because of the subtest #2 failing also the substests #5 and #6 will
100 # very probably also fail.
106 msgctl($msg,IPC_STAT,$data) or print "not ";
109 print "not " unless length($data);
113 unless (msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT)) {
118 if ($test5bad && $test2bad) {
121 # This failure was to be expected because the subtest #2 failed.
126 my($rmsgtype,$rmsgtext);
127 ($rmsgtype,$rmsgtext) = unpack("L! a*",$msgbuf);
128 unless ($rmsgtype == $msgtype && $rmsgtext eq $msgtext) {
133 if ($test6bad && $test2bad) {
136 # This failure was to be expected because the subtest #2 failed.
142 print "ok $_\n"; # fake it
146 if($Config{'d_semget'} eq 'define' &&
147 $Config{'d_semctl'} eq 'define') {
149 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
150 $Config{'d_semctl_semun'} eq 'define') {
152 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
154 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
155 # Very first time called after machine is booted value may be 0
156 die "semget: $!\n" unless defined($sem) && $sem >= 0;
161 semctl($sem,0,IPC_STAT,$data) or print "not ";
164 print "not " unless length($data);
169 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
173 semctl($sem,0,GETALL,$data) or print "not ";
176 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
179 my @data = unpack("s!*",$data);
181 my $adata = "0" x $nsem;
183 print "not " unless @data == $nsem and join("",@data) eq $adata;
189 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
193 semctl($sem,0,GETALL,$data) or print "not ";
196 @data = unpack("s!*",$data);
198 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
200 print "not " unless join("",@data) eq $bdata;
204 print "ok $_ # skipped, no semctl possible\n";
209 print "ok $_\n"; # fake it
214 msgctl($msg,IPC_RMID,0) if defined $msg;
215 semctl($sem,0,IPC_RMID,undef) if defined $sem;