File: forks00-sigtrap.t

package info (click to toggle)
libforks-perl 0.36-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 752 kB
  • sloc: perl: 4,705; ansic: 3,086; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 1,904 bytes parent folder | download | duplicates (4)
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
#!/usr/local/bin/perl -w
BEGIN {
    if ($ENV{PERL_CORE}) {
        chdir 't' if -d 't';
        @INC = '../lib';
    } elsif (!grep /blib/, @INC) {
        chdir 't' if -d 't';
        unshift @INC, ('../blib/lib', '../blib/arch');
    }
}

BEGIN {delete $ENV{THREADS_DEBUG}} # no debugging during testing!

use forks::signals;
use Test::More tests => 9;

my $g = '';
my $g_cnt = 0;
my $g_cnt_chk = 0;
my $g_myhup_cnt = 0;
my $g_myhup_cnt_chk = 0;

my $ndef_hup = sub { $g = 'nhup'; $g_cnt++ };
my $def_hup = sub { $g = 'hup'; $g_cnt++ };

import forks::signals
    ifndef  => { HUP => $ndef_hup },
    ifdef   => { HUP => $def_hup };


$SIG{HUP} = undef;
$g_cnt_chk++; kill('SIGHUP', $$);
is( $g,'nhup','Check that not defined HUP signal handler was triggered' );

$SIG{HUP} = 'DEFAULT';
$g_cnt_chk++; kill('SIGHUP', $$);
is( $g,'nhup','Check that not defined HUP signal handler was triggered' );


$SIG{HUP} = 1;
$g_cnt_chk++; kill('SIGHUP', $$);
is( $g,'hup','Check that defined HUP signal handler was triggered' );

$SIG{HUP} = sub { 1 };
$g_cnt_chk++; kill('SIGHUP', $$);
is( $g,'hup','Check that defined HUP signal handler was triggered' );


my $def_myhup = sub { $g = 'myhup'; $g_myhup_cnt++ };

$SIG{HUP} = $def_myhup;
$g_cnt_chk++; $g_myhup_cnt_chk++; kill('SIGHUP', $$);
is( $g,'myhup','Check that defined HUP signal handler was triggered' );

$SIG{HUP} = $def_myhup;
$g_cnt_chk++; $g_myhup_cnt_chk++; kill('SIGHUP', $$);
is( $g,'myhup','Check that defined HUP signal handler was triggered' );

$SIG{HUP} = undef;
$SIG{HUP} = $def_myhup;
$SIG{HUP} = $def_myhup;
$g_cnt_chk++; $g_myhup_cnt_chk++; kill('SIGHUP', $$);
is( $g,'myhup','Check that defined HUP signal handler was triggered' );

$SIG{HUP} = 'IGNORE';
kill('SIGHUP', $$);


is( $g_cnt,$g_cnt_chk,'Check that all expected signals were handled' );
is( $g_myhup_cnt,$g_myhup_cnt_chk,'Verify no internal signal recursion occured' );

1;