File: kill_kill.t

package info (click to toggle)
libipc-run-perl 20250809.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684 kB
  • sloc: perl: 6,282; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 1,608 bytes parent folder | download
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
#!/usr/bin/perl

=pod

=head1 NAME

kill_kill.t - Test suite for IPC::Run->kill_kill

=cut

BEGIN {
    $|  = 1;
    $^W = 1;
    if ( $ENV{PERL_CORE} ) {
        chdir '../lib/IPC/Run' if -d '../lib/IPC/Run';
        unshift @INC, 'lib', '../..';
        $^X = '../../../t/' . $^X;
    }
}

use strict;
use warnings;
use Test::More;
use IPC::Run ();

# Don't run this test script on Windows at all
if ( IPC::Run::Win32_MODE() ) {
    plan( skip_all => 'Temporarily ignoring test failure on Win32' );
    exit(0);
}
else {
    plan( tests => 2 );
}

# Test 1
SCOPE: {
    my $out;
    my $h = IPC::Run::start(
        [
            $^X,
            '-e',
            '$|=1;print "running\n";sleep while 1',
        ],
        \undef,
        \$out
    );

    # On most platforms, we don't need to wait to read the "running" message.
    # On NetBSD 10.0, not waiting led to us often issuing kill(kid, SIGTERM)
    # before the end of the child's exec().  Per https://gnats.netbsd.org/58268,
    # NetBSD then discarded the signal.
    pump $h until $out =~ /running/;
    my $needed = $h->kill_kill;
    ok( !$needed, 'Did not need kill_kill' );
}

# Test 2
SKIP: {
    if ( IPC::Run::Win32_MODE() ) {
        skip( "$^O does not support ignoring the TERM signal", 1 );
    }

    my $out;
    my $h = IPC::Run::start(
        [
            $^X,
            '-e',
            '$SIG{TERM}=sub{};$|=1;print "running\n";sleep while 1',
        ],
        \undef,
        \$out
    );
    pump $h until $out =~ /running/;
    my $needed = $h->kill_kill( grace => 1 );
    ok( $needed, 'Did need kill_kill' );
}