1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A require Config; import Config;
1N/A if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
1N/A print "1..0\n";
1N/A exit 0;
1N/A }
1N/A}
1N/A
1N/Arequire "./test.pl";
1N/Aplan(tests => 65);
1N/A
1N/Ause POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
1N/A errno);
1N/Ause strict 'subs';
1N/A
1N/A$| = 1;
1N/A
1N/A$Is_W32 = $^O eq 'MSWin32';
1N/A$Is_Dos = $^O eq 'dos';
1N/A$Is_MPE = $^O eq 'mpeix';
1N/A$Is_MacOS = $^O eq 'MacOS';
1N/A$Is_VMS = $^O eq 'VMS';
1N/A$Is_OS2 = $^O eq 'os2';
1N/A$Is_UWin = $^O eq 'uwin';
1N/A$Is_OS390 = $^O eq 'os390';
1N/A
1N/Aok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' );
1N/Aread($testfd, $buffer, 4) if $testfd > 2;
1N/Ais( $buffer, "#!./", ' with read' );
1N/A
1N/ATODO:
1N/A{
1N/A local $TODO = "read to array element not working";
1N/A
1N/A read($testfd, $buffer[1], 5) if $testfd > 2;
1N/A is( $buffer[1], "perl\n", ' read to array element' );
1N/A}
1N/A
1N/Awrite(1,"ok 4\nnot ok 4\n", 5);
1N/Anext_test();
1N/A
1N/ASKIP: {
1N/A skip("no pipe() support on DOS", 2) if $Is_Dos;
1N/A
1N/A @fds = POSIX::pipe();
1N/A ok( $fds[0] > $testfd, 'POSIX::pipe' );
1N/A
1N/A CORE::open($reader = \*READER, "<&=".$fds[0]);
1N/A CORE::open($writer = \*WRITER, ">&=".$fds[1]);
1N/A print $writer "ok 6\n";
1N/A close $writer;
1N/A print <$reader>;
1N/A close $reader;
1N/A next_test();
1N/A}
1N/A
1N/ASKIP: {
1N/A skip("no sigaction support on win32/dos", 6) if $Is_W32 || $Is_Dos;
1N/A
1N/A my $sigset = new POSIX::SigSet 1, 3;
1N/A $sigset->delset(1);
1N/A ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' );
1N/A ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' );
1N/A
1N/A SKIP: {
1N/A skip("no kill() support on Mac OS", 4) if $Is_MacOS;
1N/A
1N/A my $sigint_called = 0;
1N/A
1N/A my $mask = new POSIX::SigSet &SIGINT;
1N/A my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
1N/A sigaction(&SIGHUP, $action);
1N/A $SIG{'INT'} = 'SigINT';
1N/A
1N/A # At least OpenBSD/i386 3.3 is okay, as is NetBSD 1.5.
1N/A # But not NetBSD 1.6 & 1.6.1: the test makes perl crash.
1N/A # So the kill() must not be done with this config in order to
1N/A # finish the test.
1N/A # For others (darwin & freebsd), let the test fail without crashing.
1N/A my $todo = $^O eq 'netbsd' && $Config{osvers}=~/^1\.6/;
1N/A my $why_todo = "# TODO $^O $Config{osvers} seems to loose blocked signals";
1N/A if (!$todo) {
1N/A kill 'HUP', $$;
1N/A } else {
1N/A print "not ok 9 - sigaction SIGHUP ",$why_todo,"\n";
1N/A print "not ok 10 - sig mask delayed SIGINT ",$why_todo,"\n";
1N/A }
1N/A sleep 1;
1N/A
1N/A $todo = 1 if ($^O eq 'freebsd')
1N/A || ($^O eq 'darwin' && $Config{osvers} lt '6.6');
1N/A printf "%s 11 - masked SIGINT received %s\n",
1N/A $sigint_called ? "ok" : "not ok",
1N/A $todo ? $why_todo : '';
1N/A
1N/A print "ok 12 - signal masks successful\n";
1N/A
1N/A sub SigHUP {
1N/A print "ok 9 - sigaction SIGHUP\n";
1N/A kill 'INT', $$;
1N/A sleep 2;
1N/A print "ok 10 - sig mask delayed SIGINT\n";
1N/A }
1N/A
1N/A sub SigINT {
1N/A $sigint_called++;
1N/A }
1N/A
1N/A # The order of the above tests is very important, so
1N/A # we use literal prints and hard coded numbers.
1N/A next_test() for 1..4;
1N/A }
1N/A}
1N/A
1N/ASKIP: {
1N/A skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE;
1N/A skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX;
1N/A
1N/A ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" );
1N/A
1N/A}
1N/A
1N/Amy $pat;
1N/Aif ($Is_MacOS) {
1N/A $pat = qr/:t:$/;
1N/A}
1N/Aelsif ( $Is_VMS ) {
1N/A $pat = qr/\.T]/i;
1N/A}
1N/Aelse {
1N/A $pat = qr#[\\/]t$#i;
1N/A}
1N/Alike( getcwd(), qr/$pat/, 'getcwd' );
1N/A
1N/A# Check string conversion functions.
1N/A
1N/ASKIP: {
1N/A skip("strtod() not present", 1) unless $Config{d_strtod};
1N/A
1N/A $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
1N/A
1N/A # we're just checking that strtod works, not how accurate it is
1N/A ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
1N/A ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works');
1N/A
1N/A &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
1N/A}
1N/A
1N/ASKIP: {
1N/A skip("strtol() not present", 2) unless $Config{d_strtol};
1N/A
1N/A ($n, $x) = &POSIX::strtol('21_PENGUINS');
1N/A is($n, 21, 'strtol() number');
1N/A is($x, 9, ' unparsed chars');
1N/A}
1N/A
1N/ASKIP: {
1N/A skip("strtoul() not present", 2) unless $Config{d_strtoul};
1N/A
1N/A ($n, $x) = &POSIX::strtoul('88_TEARS');
1N/A is($n, 88, 'strtoul() number');
1N/A is($x, 6, ' unparsed chars');
1N/A}
1N/A
1N/A# Pick up whether we're really able to dynamically load everything.
1N/Aok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' );
1N/A
1N/A# This can coredump if struct tm has a timezone field and we
1N/A# didn't detect it. If this fails, try adding
1N/A# -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
1N/A# See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl
1N/Aprint POSIX::strftime("ok 21 # %H:%M, on %D\n", localtime());
1N/Anext_test();
1N/A
1N/A# If that worked, validate the mini_mktime() routine's normalisation of
1N/A# input fields to strftime().
1N/Asub try_strftime {
1N/A my $expect = shift;
1N/A my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
1N/A is($got, $expect, "validating mini_mktime() and strftime(): $expect");
1N/A}
1N/A
1N/A$lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
1N/Atry_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
1N/Atry_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
1N/Atry_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
1N/Atry_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
1N/Atry_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
1N/Atry_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
1N/Atry_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
1N/Atry_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
1N/Atry_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
1N/A&POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
1N/A
1N/A{
1N/A for my $test (0, 1) {
1N/A $! = 0;
1N/A # POSIX::errno is autoloaded.
1N/A # Autoloading requires many system calls.
1N/A # errno() looks at $! to generate its result.
1N/A # Autoloading should not munge the value.
1N/A my $foo = $!;
1N/A my $errno = POSIX::errno();
1N/A
1N/A # Force numeric context.
1N/A is( $errno + 0, $foo + 0, 'autoloading and errno() mix' );
1N/A }
1N/A}
1N/A
1N/ASKIP: {
1N/A skip("no kill() support on Mac OS", 1) if $Is_MacOS;
1N/A is (eval "kill 0", 0, "check we have CORE::kill")
1N/A or print "\$\@ is " . _qq($@) . "\n";
1N/A}
1N/A
1N/A# Check that we can import the POSIX kill routine
1N/APOSIX->import ('kill');
1N/Amy $result = eval "kill 0";
1N/Ais ($result, undef, "we should now have POSIX::kill");
1N/A# Check usage.
1N/Alike ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message");
1N/A
1N/A# Check unimplemented.
1N/A$result = eval {POSIX::offsetof};
1N/Ais ($result, undef, "offsetof should fail");
1N/Alike ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/,
1N/A "check its unimplemented message");
1N/A
1N/A# Check reimplemented.
1N/A$result = eval {POSIX::fgets};
1N/Ais ($result, undef, "fgets should fail");
1N/Alike ($@, qr/^Use method IO::Handle::gets\(\) instead/,
1N/A "check its redef message");
1N/A
1N/A# Simplistic tests for the isXXX() functions (bug #16799)
1N/Aok( POSIX::isalnum('1'), 'isalnum' );
1N/Aok(!POSIX::isalnum('*'), 'isalnum' );
1N/Aok( POSIX::isalpha('f'), 'isalpha' );
1N/Aok(!POSIX::isalpha('7'), 'isalpha' );
1N/Aok( POSIX::iscntrl("\cA"),'iscntrl' );
1N/Aok(!POSIX::iscntrl("A"), 'iscntrl' );
1N/Aok( POSIX::isdigit('1'), 'isdigit' );
1N/Aok(!POSIX::isdigit('z'), 'isdigit' );
1N/Aok( POSIX::isgraph('@'), 'isgraph' );
1N/Aok(!POSIX::isgraph(' '), 'isgraph' );
1N/Aok( POSIX::islower('l'), 'islower' );
1N/Aok(!POSIX::islower('L'), 'islower' );
1N/Aok( POSIX::isupper('U'), 'isupper' );
1N/Aok(!POSIX::isupper('u'), 'isupper' );
1N/Aok( POSIX::isprint('$'), 'isprint' );
1N/Aok(!POSIX::isprint("\n"), 'isprint' );
1N/Aok( POSIX::ispunct('%'), 'ispunct' );
1N/Aok(!POSIX::ispunct('u'), 'ispunct' );
1N/Aok( POSIX::isspace("\t"), 'isspace' );
1N/Aok(!POSIX::isspace('_'), 'isspace' );
1N/Aok( POSIX::isxdigit('f'), 'isxdigit' );
1N/Aok(!POSIX::isxdigit('g'), 'isxdigit' );
1N/A# metaphysical question : what should be returned for an empty string ?
1N/A# anyway this shouldn't segfault (bug #24554)
1N/Aok( POSIX::isalnum(''), 'isalnum empty string' );
1N/Aok( POSIX::isalnum(undef),'isalnum undef' );
1N/A# those functions should stringify their arguments
1N/Aok(!POSIX::isalpha([]), 'isalpha []' );
1N/Aok( POSIX::isprint([]), 'isprint []' );
1N/A
1N/A# Check that output is not flushed by _exit. This test should be last
1N/A# in the file, and is not counted in the total number of tests.
1N/Aif ($^O eq 'vos') {
1N/A print "# TODO - hit VOS bug posix-885 - _exit flushes output buffers.\n";
1N/A} else {
1N/A $| = 0;
1N/A # The following line assumes buffered output, which may be not true:
1N/A print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 ||
1N/A $Is_VMS ||
1N/A (defined $ENV{PERLIO} &&
1N/A $ENV{PERLIO} eq 'unix' &&
1N/A $Config::Config{useperlio}));
1N/A _exit(0);
1N/A}