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 S_IRWXU);
34 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
36 # FreeBSD is known to throw this if there's no SysV IPC in the kernel.
40 It may be that your kernel does not have SysV IPC configured.
43 if ($^O eq 'freebsd') {
45 You must have following options in your kernel:
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";
78 unless (msgsnd($msg,pack("L! a*",$msgtype,$msgtext),IPC_NOWAIT)) {
86 # The failure of the subtest #2 may indicate that the message queue
87 # resource limits either of the system or of the testing account
88 # have been reached. Error message "Operating would block" is
89 # usually indicative of this situation. The error message was now:
92 # You can check the message queues with the 'ipcs' command and
93 # you can remove unneeded queues with the 'ipcrm -q id' command.
94 # You may also consider configuring your system or account
95 # to have more message queue resources.
97 # Because of the subtest #2 failing also the substests #5 and #6 will
98 # very probably also fail.
104 msgctl($msg,IPC_STAT,$data) or print "not ";
107 print "not " unless length($data);
111 unless (msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT)) {
116 if ($test5bad && $test2bad) {
119 # This failure was to be expected because the subtest #2 failed.
124 my($rmsgtype,$rmsgtext);
125 ($rmsgtype,$rmsgtext) = unpack("L! a*",$msgbuf);
126 unless ($rmsgtype == $msgtype && $rmsgtext eq $msgtext) {
131 if ($test6bad && $test2bad) {
134 # This failure was to be expected because the subtest #2 failed.
140 print "ok $_\n"; # fake it
144 if($Config{'d_semget'} eq 'define' &&
145 $Config{'d_semctl'} eq 'define') {
147 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
148 $Config{'d_semctl_semun'} eq 'define') {
150 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
152 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
153 # Very first time called after machine is booted value may be 0
154 die "semget: $!\n" unless defined($sem) && $sem >= 0;
159 semctl($sem,0,IPC_STAT,$data) or print "not ";
162 print "not " unless length($data);
167 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
171 semctl($sem,0,GETALL,$data) or print "not ";
174 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
177 my @data = unpack("s!*",$data);
179 my $adata = "0" x $nsem;
181 print "not " unless @data == $nsem and join("",@data) eq $adata;
187 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
191 semctl($sem,0,GETALL,$data) or print "not ";
194 @data = unpack("s!*",$data);
196 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
198 print "not " unless join("",@data) eq $bdata;
202 print "ok $_ # skipped, no semctl possible\n";
207 print "ok $_\n"; # fake it
212 msgctl($msg,IPC_RMID,0) if defined $msg;
213 semctl($sem,0,IPC_RMID,undef) if defined $sem;