summaryrefslogtreecommitdiff
path: root/t/op/ipcsem.t
blob: f3f6e3ce4c02bf27a61ab55c7630236f06b493bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!./perl

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
}

my @define;

BEGIN {
    @define = qw(
	GETALL
	SETALL
	IPC_PRIVATE
	IPC_CREAT
	IPC_RMID
	IPC_STAT
	S_IRWXU
	S_IRWXG
	S_IRWXO
    );
}

use Config;
use vars map { '$' . $_ } @define;

BEGIN {
    unless($Config{'d_semget'} eq 'define' &&
	   $Config{'d_semctl'} eq 'define') {
	print "1..0\n";
	exit;
    }
    my @incpath = (split(/\s+/, $Config{usrinc}), split(/\s+/ ,$Config{locincpth}));
    my %done = ();
    my %define = ();

    sub process_file {
	my($file) = @_;

	return unless defined $file;

	my $path = undef;
	my $dir;
	foreach $dir (@incpath) {
	    my $tmp = $dir . "/" . $file;
	    next unless -r $tmp;
	    $path = $tmp;
	    last;
	}

	return if exists $done{$path};
	$done{$path} = 1;

	unless(defined $path) {
	    warn "Cannot find '$file'";
	    return;
	}

	open(F,$path) or return;
	while(<F>) {
	    s#/\*.*(\*/|$)##;

	    process_file($mm,$1)
		    if /^#\s*include\s*[<"]([^>"]+)[>"]/;

	    s/(?:\([^)]*\)\s*)//;

	    $define{$1} = $2
		if /^#\s*define\s+(\w+)\s+((0x)?\d+|\w+)/;
       }
       close(F);
    }

    process_file("sys/sem.h");
    process_file("sys/ipc.h");
    process_file("sys/stat.h");

    foreach $d (@define) {
	while(defined($define{$d}) && $define{$d} !~ /^(0x)?\d+$/) {
	    $define{$d} = exists $define{$define{$d}}
		    ? $define{$define{$d}} : undef;
	}
	unless(defined $define{$d}) {
	    print "0..0\n";
	    exit;
	};
	${ $d } = eval $define{$d};
    }
}

use strict;

print "1..10\n";

my $sem = semget($IPC_PRIVATE, 10, $S_IRWXU | $S_IRWXG | $S_IRWXO | $IPC_CREAT)
	|| die "semget: $!\n";

print "ok 1\n";

my $data;
semctl($sem,0,$IPC_STAT,$data) or print "not ";
print "ok 2\n";

print "not " unless length($data);
print "ok 3\n";

semctl($sem,0,$SETALL,pack("s*",(0) x 10)) or print "not ";
print "ok 4\n";

$data = "";
semctl($sem,0,$GETALL,$data) or print "not ";
print "ok 5\n";

print "not " unless length($data);
print "ok 6\n";

my @data = unpack("s*",$data);

print "not " unless join("",@data) eq "0000000000";
print "ok 7\n";

$data[2] = 1;
semctl($sem,0,$SETALL,pack("s*",@data)) or print "not ";
print "ok 8\n";

$data = "";
semctl($sem,0,$GETALL,$data) or print "not ";
print "ok 9\n";

@data = unpack("s*",$data);

print "not " unless join("",@data) eq "0010000000";
print "ok 10\n";

semctl($sem,0,$IPC_RMID,undef);