summaryrefslogtreecommitdiff
path: root/t/io
diff options
context:
space:
mode:
authorBrian Childs <brian@rentec.com>2013-12-03 06:33:41 +0100
committerTony Cook <tony@develop-help.com>2013-12-09 14:31:00 +1100
commit64d7628235943ff18939a1ff98ace513aeb5260c (patch)
tree4a66ef3c015dffce9b6181e2a6401fdd044bf184 /t/io
parent1c6ce212d37a2a17424675e94afb035a9a446f9f (diff)
downloadperl-64d7628235943ff18939a1ff98ace513aeb5260c.tar.gz
Fixes the case where on 64bit big-endian boxes, calls to semctl(id,semnum,SETVAL,$wantedval) will ignore the passed in $wantedval, and always use 0
Diffstat (limited to 't/io')
-rw-r--r--t/io/sem.t72
1 files changed, 72 insertions, 0 deletions
diff --git a/t/io/sem.t b/t/io/sem.t
new file mode 100644
index 0000000000..272c39630b
--- /dev/null
+++ b/t/io/sem.t
@@ -0,0 +1,72 @@
+#!perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib' if -d '../lib' && -d '../ext';
+
+ require "./test.pl";
+ require Config; import Config;
+
+ if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
+ skip_all('-- IPC::SysV was not built');
+ }
+ skip_all_if_miniperl();
+ if ($Config{'d_sem'} ne 'define') {
+ skip_all('-- $Config{d_sem} undefined');
+ }
+}
+
+use strict;
+our $TODO;
+
+use sigtrap qw/die normal-signals error-signals/;
+use IPC::SysV qw/ IPC_PRIVATE S_IRUSR S_IWUSR IPC_RMID SETVAL GETVAL SETALL GETALL IPC_CREAT /;
+
+my $id;
+my $nsem = 10;
+END { semctl $id, IPC_RMID, 0, 0 if defined $id }
+
+{
+ local $SIG{SYS} = sub { skip_all("SIGSYS caught") } if exists $SIG{SYS};
+ $id = semget IPC_PRIVATE, $nsem, S_IRUSR | S_IWUSR | IPC_CREAT;
+}
+
+if (not defined $id) {
+ my $info = "semget failed: $!";
+ if ($! == &IPC::SysV::ENOSPC || $! == &IPC::SysV::ENOSYS ||
+ $! == &IPC::SysV::ENOMEM || $! == &IPC::SysV::EACCES) {
+ plan(skip_all => $info);
+ }
+ else {
+ die $info;
+ }
+}
+else {
+ plan(tests => 7);
+ pass('acquired semaphore');
+}
+
+{ # [perl #120635] 64 bit big-endian semctl SETVAL bug
+ ok(semctl($id, "ignore", SETALL, pack("s!*",(0)x$nsem)),
+ "Initialize all $nsem semaphores to zero");
+
+ my $sem2set = 3;
+ my $semval = 17;
+ ok(semctl($id, $sem2set, SETVAL, $semval),
+ "Set semaphore $sem2set to $semval");
+
+ my $semvals;
+ ok(semctl($id, "ignore", GETALL, $semvals),
+ 'Get current semaphore values');
+
+ my @semvals = unpack("s!*", $semvals);
+ is(scalar(@semvals), $nsem,
+ "Make sure we get back statuses for all $nsem semaphores");
+
+ is($semvals[$sem2set], $semval,
+ "Checking value of semaphore $sem2set");
+
+ is(semctl($id, $sem2set, GETVAL, "ignored"), $semval,
+ "Check value via GETVAL");
+}
+