8 require Config; import Config;
10 unless ($Config{'d_msg'} eq 'define' &&
11 $Config{'d_sem'} eq 'define') {
17 # These constants are common to all tests.
18 # Later the sem* tests will import more for themselves.
20 use IPC::SysV qw(IPC_PRIVATE IPC_NOWAIT IPC_STAT IPC_RMID
21 S_IRWXU S_IRWXG S_IRWXO);
29 $SIG{__DIE__} = 'cleanup'; # will cleanup $msg and $sem if needed
31 # FreeBSD is known to throw this if there's no SysV IPC in the kernel.
35 It may be that your kernel does not have SysV IPC configured.
38 if ($^O eq 'freebsd') {
40 You must have following options in your kernel:
52 if ($Config{'d_msgget'} eq 'define' &&
53 $Config{'d_msgctl'} eq 'define' &&
54 $Config{'d_msgsnd'} eq 'define' &&
55 $Config{'d_msgrcv'} eq 'define') {
56 $msg = msgget(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO);
57 # Very first time called after machine is booted value may be 0
58 die "msgget failed: $!\n" unless defined($msg) && $msg >= 0;
62 #Putting a message on the queue
64 my $msgtext = "hello";
66 msgsnd($msg,pack("L a*",$msgtype,$msgtext),0) or print "not ";
70 msgctl($msg,IPC_STAT,$data) or print "not ";
73 print "not " unless length($data);
77 msgrcv($msg,$msgbuf,256,0,IPC_NOWAIT) or print "not ";
80 my($rmsgtype,$rmsgtext) = unpack("L a*",$msgbuf);
82 print "not " unless($rmsgtype == $msgtype && $rmsgtext eq $msgtext);
86 print "ok $_\n"; # fake it
90 if($Config{'d_semget'} eq 'define' &&
91 $Config{'d_semctl'} eq 'define') {
93 use IPC::SysV qw(IPC_CREAT GETALL SETALL);
95 $sem = semget(IPC_PRIVATE, 10, S_IRWXU | S_IRWXG | S_IRWXO | IPC_CREAT);
96 # Very first time called after machine is booted value may be 0
97 die "semget: $!\n" unless defined($sem) && $sem >= 0;
102 semctl($sem,0,IPC_STAT,$data) or print "not ";
105 print "not " unless length($data);
110 # Find the pack/unpack template capable of handling native C shorts.
112 if ($Config{shortsize} == 2) {
114 } elsif ($Config{shortsize} == 4) {
116 } elsif ($Config{shortsize} == 8) {
117 # Try quad last because not supported everywhere.
118 foreach my $t (qw(i q)) {
119 # We could trap the unsupported quad template with eval
120 # but if we get this far we should have quad support anyway.
121 if (length(pack($t, 0)) == 8) {
128 die "$0: cannot pack native shorts\n" unless defined $template;
134 semctl($sem,0,SETALL,pack($template,(0) x $nsem)) or print "not ";
138 semctl($sem,0,GETALL,$data) or print "not ";
141 print "not " unless length($data) == length(pack($template,(0) x $nsem));
144 my @data = unpack($template,$data);
146 my $adata = "0" x $nsem;
148 print "not " unless @data == $nsem and join("",@data) eq $adata;
154 semctl($sem,0,SETALL,pack($template,@data)) or print "not ";
158 semctl($sem,0,GETALL,$data) or print "not ";
161 @data = unpack($template,$data);
163 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
165 print "not " unless join("",@data) eq $bdata;
169 print "ok $_\n"; # fake it
174 msgctl($msg,IPC_RMID,0) if defined $msg;
175 semctl($sem,0,IPC_RMID,undef) if defined $sem;