6 unshift @INC, '../lib';
8 require Config; import Config;
12 if ($Config{'d_sem'} ne 'define') {
13 $reason = '$Config{d_sem} undefined';
14 } elsif ($Config{'d_msg'} ne 'define') {
15 $reason = '$Config{d_msg} undefined';
18 print "1..0 # Skip: $reason\n";
23 # These constants are common to all tests.
24 # Later the sem* tests will import more for themselves.
26 use IPC::SysV qw(IPC_PRIVATE IPC_NOWAIT IPC_STAT IPC_RMID
27 S_IRWXU S_IRWXG S_IRWXO S_IWGRP S_IROTH S_IWOTH);
35 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
37 # FreeBSD is known to throw this if there's no SysV IPC in the kernel.
41 It may be that your kernel does not have SysV IPC configured.
44 if ($^O eq 'freebsd') {
46 You must have following options in your kernel:
60 $perm = S_IRWXU | S_IRWXG | S_IRWXO | S_IWGRP | S_IROTH | S_IWOTH
63 $perm = S_IRWXU | S_IRWXG | S_IRWXO unless defined $perm;
65 if ($Config{'d_msgget'} eq 'define' &&
66 $Config{'d_msgctl'} eq 'define' &&
67 $Config{'d_msgsnd'} eq 'define' &&
68 $Config{'d_msgrcv'} eq 'define') {
70 $msg = msgget(IPC_PRIVATE, $perm);
71 # Very first time called after machine is booted value may be 0
72 die "msgget failed: $!\n" unless defined($msg) && $msg >= 0;
76 #Putting a message on the queue
78 my $msgtext = "hello";
84 if ($Config{'use64bitall'} eq 'define') {
85 unless (msgsnd($msg,pack("L L a*",0,$msgtype,$msgtext),IPC_NOWAIT)) {
90 unless (msgsnd($msg,pack("L a*",$msgtype,$msgtext),IPC_NOWAIT)) {
99 # The failure of the subtest #2 may indicate that the message queue
100 # resource limits either of the system or of the testing account
101 # have been reached. Error message "Operating would block" is
102 # usually indicative of this situation. The error message was now:
105 # You can check the message queues with the 'ipcs' command and
106 # you can remove unneeded queues with the 'ipcrm -q id' command.
107 # You may also consider configuring your system or account
108 # to have more message queue resources.
110 # Because of the subtest #2 failing also the substests #5 and #6 will
111 # very probably also fail.
117 msgctl($msg,IPC_STAT,$data) or print "not ";
120 print "not " unless length($data);
124 unless (msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT)) {
129 if ($test5bad && $test2bad) {
132 # This failure was to be expected because the subtest #2 failed.
137 my($rmsgtype,$rmsgtext);
138 if ($Config{'use64bitall'} eq 'define') {
139 (undef,$rmsgtype,$rmsgtext) = unpack("L L a*",$msgbuf)
141 ($rmsgtype,$rmsgtext) = unpack("L a*",$msgbuf)
143 unless($rmsgtype == $msgtype && $rmsgtext eq $msgtext) {
148 if ($test6bad && $test2bad) {
151 # This failure was to be expected because the subtest #2 failed.
157 print "ok $_\n"; # fake it
161 if($Config{'d_semget'} eq 'define' &&
162 $Config{'d_semctl'} eq 'define') {
164 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
165 $Config{'d_semctl_semun'} eq 'define') {
167 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
169 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
170 # Very first time called after machine is booted value may be 0
171 die "semget: $!\n" unless defined($sem) && $sem >= 0;
176 semctl($sem,0,IPC_STAT,$data) or print "not ";
179 print "not " unless length($data);
184 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
188 semctl($sem,0,GETALL,$data) or print "not ";
191 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
194 my @data = unpack("s!*",$data);
196 my $adata = "0" x $nsem;
198 print "not " unless @data == $nsem and join("",@data) eq $adata;
204 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
208 semctl($sem,0,GETALL,$data) or print "not ";
211 @data = unpack("s!*",$data);
213 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
215 print "not " unless join("",@data) eq $bdata;
219 print "ok $_ # skipped, no semctl possible\n";
224 print "ok $_\n"; # fake it
229 msgctl($msg,IPC_RMID,0) if defined $msg;
230 semctl($sem,0,IPC_RMID,undef) if defined $sem;