xref: /openbsd-src/gnu/usr.bin/perl/t/op/waitpid.t (revision 5759b3d249badf144a6240f7eec4dcf9df003e6b)
16fb12b70Safresh1#!./perl
26fb12b70Safresh1
36fb12b70Safresh1# tests for (possibly emulated) waitpid
46fb12b70Safresh1
56fb12b70Safresh1BEGIN {
66fb12b70Safresh1    chdir 't' if -d 't';
76fb12b70Safresh1    require './test.pl';
8*5759b3d2Safresh1    set_up_inc('../lib');
96fb12b70Safresh1    require Config;
106fb12b70Safresh1    skip_all('no Errno')
116fb12b70Safresh1	unless eval 'use Errno qw(EINVAL); 1';
126fb12b70Safresh1    skip_all('no POSIX')
136fb12b70Safresh1        unless eval 'use POSIX qw(WNOHANG); 1';
146fb12b70Safresh1}
156fb12b70Safresh1
166fb12b70Safresh1$|=1;
176fb12b70Safresh1
186fb12b70Safresh1watchdog(10);
196fb12b70Safresh1{
206fb12b70Safresh1    # [perl #85228] Broken waitpid
216fb12b70Safresh1    # $! = EINVAL; waitpid 0, 0; # would loop forever, even with WNOHANG
226fb12b70Safresh1    $! = EINVAL;
236fb12b70Safresh1    my $pid = waitpid(0, WNOHANG);
246fb12b70Safresh1
256fb12b70Safresh1    # depending on the platform, there's several possible values for
266fb12b70Safresh1    # $pid and $!, so I'm only testing that we don't loop forever.
276fb12b70Safresh1    #
286fb12b70Safresh1    # Some of the complications are:
296fb12b70Safresh1    #
306fb12b70Safresh1    #  - watchdog() may be implemented with alarm() or fork, so there
316fb12b70Safresh1    #    may or may not be children (this code doesn't use threads, so
326fb12b70Safresh1    #    threads shouldn't be used)
336fb12b70Safresh1    #
346fb12b70Safresh1    #  - the platform may or may not implement waitpid()/wait4()
356fb12b70Safresh1
366fb12b70Safresh1    pass("didn't block on waitpid(0, ...)");
376fb12b70Safresh1}
386fb12b70Safresh1
396fb12b70Safresh1done_testing();
40