File: 60-forkdepth.t

package info (click to toggle)
libdevel-nytprof-perl 5.06%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,396 kB
  • ctags: 1,413
  • sloc: perl: 4,905; ansic: 101; sh: 54; makefile: 17
file content (39 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (5)
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
use Test::More;

use strict;

use lib qw(t/lib);
use NYTProfTest;

plan skip_all => "doesn't work with fork() emulation" if (($^O eq "MSWin32") || ($^O eq 'VMS'));

plan tests => 5;

my $out = 'nytprof-forkdepth.out';

is run_forkdepth(  0 ),   1;
is run_forkdepth(  1 ),   2;
is run_forkdepth(  2 ),   3;
is run_forkdepth( -1 ),   3;
is run_forkdepth( undef), 3;

exit 0;

sub run_forkdepth {
    my ($forkdepth) = @_;
    printf "run_forkdepth %s\n", defined($forkdepth) ? $forkdepth : "undef";

    unlink $_ for glob("$out.*");

    $ENV{NYTPROF} = "file=$out:addpid=1:trace=0";
    $ENV{NYTPROF} .= ":forkdepth=$forkdepth" if defined $forkdepth;

    my $forkdepth_cmd = q{-d:NYTProf -e "sub f { fork or return; wait; exit \$? } f; f; exit 0"};
    run_perl_command($forkdepth_cmd);

    my @files = glob("$out.*");
    unlink $_ for @files;

    return scalar @files;
}