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";
80 msgsnd($msg,pack("L a*",$msgtype,$msgtext),0) or print "not ";
84 msgctl($msg,IPC_STAT,$data) or print "not ";
87 print "not " unless length($data);
91 msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT) or print "not ";
94 my($rmsgtype,$rmsgtext) = unpack("L a*",$msgbuf);
96 print "not " unless($rmsgtype == $msgtype && $rmsgtext eq $msgtext);
100 print "ok $_\n"; # fake it
104 if($Config{'d_semget'} eq 'define' &&
105 $Config{'d_semctl'} eq 'define') {
107 if ($Config{'d_semctl_semid_ds'} eq 'define' ||
108 $Config{'d_semctl_semun'} eq 'define') {
110 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
112 $sem = semget(IPC_PRIVATE, 10, $perm | IPC_CREAT);
113 # Very first time called after machine is booted value may be 0
114 die "semget: $!\n" unless defined($sem) && $sem >= 0;
119 semctl($sem,0,IPC_STAT,$data) or print "not ";
122 print "not " unless length($data);
127 semctl($sem,0,SETALL,pack("s!*",(0) x $nsem)) or print "not ";
131 semctl($sem,0,GETALL,$data) or print "not ";
134 print "not " unless length($data) == length(pack("s!*",(0) x $nsem));
137 my @data = unpack("s!*",$data);
139 my $adata = "0" x $nsem;
141 print "not " unless @data == $nsem and join("",@data) eq $adata;
147 semctl($sem,0,SETALL,pack("s!*",@data)) or print "not ";
151 semctl($sem,0,GETALL,$data) or print "not ";
154 @data = unpack("s!*",$data);
156 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
158 print "not " unless join("",@data) eq $bdata;
162 print "ok $_ # skipped, no semctl possible\n";
167 print "ok $_\n"; # fake it
172 msgctl($msg,IPC_RMID,0) if defined $msg;
173 semctl($sem,0,IPC_RMID,undef) if defined $sem;