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 unless (msgsnd($msg,pack("L! a*",$msgtype,$msgtext),IPC_NOWAIT)) {
92 # The failure of the subtest #2 may indicate that the message queue
93 # resource limits either of the system or of the testing account
94 # have been reached. Error message "Operating would block" is
95 # usually indicative of this situation. The error message was now:
98 # You can check the message queues with the 'ipcs' command and
99 # you can remove unneeded queues with the 'ipcrm -q id' command.
100 # You may also consider configuring your system or account
101 # to have more message queue resources.
103 # Because of the subtest #2 failing also the substests #5 and #6 will
104 # very probably also fail.
110 msgctl($msg,IPC_STAT,$data) or print "not ";
113 print "not " unless length($data);
117 unless (msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT)) {
122 if ($test5bad && $test2bad) {
125 # This failure was to be expected because the subtest #2 failed.
130 my($rmsgtype,$rmsgtext);
131 ($rmsgtype,$rmsgtext) = unpack("L! a*",$msgbuf)
132 unless($rmsgtype == $msgtype && $rmsgtext eq $msgtext) {
137 if ($test6bad && $test2bad) {
140 # This failure was to be expected because the subtest #2 failed.
146 print "ok $_\n"; # fake it
150 if($Config{'d_semget'} eq 'define' &&
151 $Config{'d_semctl'} eq 'define') {
153 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
154 $Config{'d_semctl_semun'} eq 'define') {
156 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
158 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
159 # Very first time called after machine is booted value may be 0
160 die "semget: $!\n" unless defined($sem) && $sem >= 0;
165 semctl($sem,0,IPC_STAT,$data) or print "not ";
168 print "not " unless length($data);
173 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
177 semctl($sem,0,GETALL,$data) or print "not ";
180 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
183 my @data = unpack("s!*",$data);
185 my $adata = "0" x $nsem;
187 print "not " unless @data == $nsem and join("",@data) eq $adata;
193 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
197 semctl($sem,0,GETALL,$data) or print "not ";
200 @data = unpack("s!*",$data);
202 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
204 print "not " unless join("",@data) eq $bdata;
208 print "ok $_ # skipped, no semctl possible\n";
213 print "ok $_\n"; # fake it
218 msgctl($msg,IPC_RMID,0) if defined $msg;
219 semctl($sem,0,IPC_RMID,undef) if defined $sem;