6 require Config; import Config;
7 if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
17 use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
23 $Is_W32 = $^O eq 'MSWin32';
24 $Is_Dos = $^O eq 'dos';
25 $Is_MPE = $^O eq 'mpeix';
26 $Is_MacOS = $^O eq 'MacOS';
27 $Is_VMS = $^O eq 'VMS';
28 $Is_OS2 = $^O eq 'os2';
29 $Is_UWin = $^O eq 'uwin';
30 $Is_OS390 = $^O eq 'os390';
32 ok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' );
33 read($testfd, $buffer, 9) if $testfd > 2;
34 is( $buffer, "#!./perl\n", ' with read' );
36 write(1,"ok 3\nnot ok 3\n", 5);
40 skip("no pipe() support on DOS", 2) if $Is_Dos;
43 ok( $fds[0] > $testfd, 'POSIX::pipe' );
45 CORE::open($reader = \*READER, "<&=".$fds[0]);
46 CORE::open($writer = \*WRITER, ">&=".$fds[1]);
47 print $writer "ok 5\n";
55 skip("no sigaction support on win32/dos", 6) if $Is_W32 || $Is_Dos;
57 my $sigset = new POSIX::SigSet 1, 3;
59 ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' );
60 ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' );
63 skip("no kill() support on Mac OS", 4) if $Is_MacOS;
65 my $sigint_called = 0;
67 my $mask = new POSIX::SigSet &SIGINT;
68 my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
69 sigaction(&SIGHUP, $action);
70 $SIG{'INT'} = 'SigINT';
74 printf "%s 10 - masked SIGINT received %s\n",
75 $sigint_called ? "ok" : "not ok",
76 $^O eq 'darwin' ? "# TODO Darwin seems to loose blocked signals"
79 print "ok 11 - signal masks successful\n";
82 print "ok 8 - sigaction SIGHUP\n";
85 print "ok 9 - sig mask delayed SIGINT\n";
92 # The order of the above tests is very important, so
93 # we use literal prints and hard coded numbers.
99 skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE;
100 skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX;
102 ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" );
116 like( getcwd(), qr/$pat/, 'getcwd' );
118 # Check string conversion functions.
121 skip("strtod() not present", 1) unless $Config{d_strtod};
123 $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
125 # we're just checking that strtod works, not how accurate it is
126 ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
127 ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works');
129 &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
133 skip("strtol() not present", 2) unless $Config{d_strtol};
135 ($n, $x) = &POSIX::strtol('21_PENGUINS');
136 is($n, 21, 'strtol() number');
137 is($x, 9, ' unparsed chars');
141 skip("strtoul() not present", 2) unless $Config{d_strtoul};
143 ($n, $x) = &POSIX::strtoul('88_TEARS');
144 is($n, 88, 'strtoul() number');
145 is($x, 6, ' unparsed chars');
148 # Pick up whether we're really able to dynamically load everything.
149 ok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' );
151 # This can coredump if struct tm has a timezone field and we
152 # didn't detect it. If this fails, try adding
153 # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
154 # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl
155 print POSIX::strftime("ok 20 # %H:%M, on %D\n", localtime());
158 # If that worked, validate the mini_mktime() routine's normalisation of
159 # input fields to strftime().
162 my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
163 is($got, $expect, "validating mini_mktime() and strftime(): $expect");
166 $lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
167 try_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
168 try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
169 try_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
170 try_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
171 try_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
172 try_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
173 try_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
174 try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
175 try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
176 &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
179 for my $test (0, 1) {
181 # POSIX::errno is autoloaded.
182 # Autoloading requires many system calls.
183 # errno() looks at $! to generate its result.
184 # Autoloading should not munge the value.
186 my $errno = POSIX::errno();
188 # Force numeric context.
189 is( $errno + 0, $foo + 0, 'autoloading and errno() mix' );
194 skip("no kill() support on Mac OS", 1) if $Is_MacOS;
195 is (eval "kill 0", 0, "check we have CORE::kill")
196 or print "\$\@ is " . _qq($@) . "\n";
199 # Check that we can import the POSIX kill routine
200 POSIX->import ('kill');
201 my $result = eval "kill 0";
202 is ($result, undef, "we should now have POSIX::kill");
204 like ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message");
206 # Check unimplemented.
207 $result = eval {POSIX::offsetof};
208 is ($result, undef, "offsetof should fail");
209 like ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/,
210 "check its unimplemented message");
212 # Check reimplemented.
213 $result = eval {POSIX::fgets};
214 is ($result, undef, "fgets should fail");
215 like ($@, qr/^Use method IO::Handle::gets\(\) instead/,
216 "check its redef message");
218 # Check that output is not flushed by _exit. This test should be last
219 # in the file, and is not counted in the total number of tests.
221 print "# TODO - hit VOS bug posix-885 - _exit flushes output buffers.\n";
224 # The following line assumes buffered output, which may be not true:
225 print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 ||
227 (defined $ENV{PERLIO} &&
228 $ENV{PERLIO} eq 'unix' &&
229 $Config::Config{useperlio}));