Infrastructure/Process.pm

filter: Statementstmt 29.5% 29 / 98 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 1 totaltotal 27.1% 35 / 129 CC 10 SCAR 17.5
CC
10
Cov
27%
__ANON__
12.0
__ANON__
12.0
__ANON__
6.0
CRAP 5.8
« Infrastructure/HTTP.pm ↑ Summary Infrastructure/Swap.pm »
1 package Test::BDD::Infrastructure::Process;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.005'; # VERSION
7 # ABSTRACT: cucumber step definitions for checking processes
8
9 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Test::BDD::Cucumber::StepFile qw( Given When Then );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub S { Test::BDD::Cucumber::StepFile::S }
Subroutine S: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 1 ▶use Test::BDD::Infrastructure::Utils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 convert_unit convert_cmp_operator $CMP_OPERATOR_RE );
16  
17 1 ▶use Proc::ProcessTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 0 ▶Given qr/there (?:is|are) $CMP_OPERATOR_RE (\d+) process(?:es)? like (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 my $op = convert_cmp_operator( $1 );
22 0 my $count = $2;
23 0 my $procname = $3;
24 0 my $t = Proc::ProcessTable->new;
25 my @procs = grep {
26 0 $_->cmndline =~ /$procname/
27 0 } @{$t->table};
28  
29 0 cmp_ok( scalar(@procs), $op, $count, "$op $count processes with process name like $procname");
30  
31 0 S->{'proc'} = \@procs;
32 1 };
33  
34 0 ▶Given qr/a parent process like (\S+) is running/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
35 0 my $procname = $1;
36 0 my $t = Proc::ProcessTable->new;
37  
38 my @procs = grep {
39 0 ▶ $_->cmndline =~ /$procname/
Condition0%0/3
$_->cmndline =~ /$procname/ && $_->ppid == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_->cmndline =~ /$procname/ && $_->ppid == 1
$_->cmndline =~ /$procname/ $_->ppid == 1
Truth table0%0/3
A && B
A= $_->cmndline =~ /$procname/B= $_->ppid == 1
ABresult
0X0
100
111
40 && $_->ppid == 1
41 0 } @{$t->table};
42 0 cmp_ok( scalar(@procs), '==', 1, "parent process of $procname must be running");
43  
44 0 S->{'parent'} = $procs[0];
45 0 S->{'procs'} = \@procs;
46 1 };
47  
48 0 ▶When qr/there (?:is|are) $CMP_OPERATOR_RE (\d+) child process(?:es)?/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 my $op = convert_cmp_operator( $1 );
50 0 my $count = $2;
51 0 my $parent = S->{'parent'};
52 0 my $t = Proc::ProcessTable->new;
53 my @childs = grep {
54 0 $_->ppid == $parent->pid,
55 0 } @{$t->table};
56  
57 0 cmp_ok( scalar(@childs), $op, $count, "$op $count child processes of parent pid ".$parent->pid);
58  
59 0 S->{'childs'} = \@childs;
60 0 S->{'procs'} = \@childs;
61 1 };
62  
63 0 ▶When qr/there (?:is|are) $CMP_OPERATOR_RE (\d+) child process(?:es)? like (.*)/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
64 0 my $op = convert_cmp_operator( $1 );
65 0 my $count = $2;
66 0 my $procname = $3;
67 0 my $parent = S->{'parent'};
68 0 my $t = Proc::ProcessTable->new;
69 my @childs = grep {
70 0 ▶ $_->cmndline =~ /$procname/
Condition0%0/3
$_->cmndline =~ /$procname/ && $_->ppid == $parent->pid
!ll&&!rl&&r
000
MC/DC0%0/2
$_->cmndline =~ /$procname/ && $_->ppid == $parent->pid
$_->cmndline =~ /$procname/ $_->ppid == $parent->pid
Truth table0%0/3
A && B
A= $_->cmndline =~ /$procname/B= $_->ppid == $parent->pid
ABresult
0X0
100
111
71 && $_->ppid == $parent->pid,
72 0 } @{$t->table};
73  
74 0 cmp_ok( scalar(@childs), $op, $count, "$op $count child processes of parent pid ".$parent->pid.' with process name like '.$procname);
75  
76 0 S->{'childs'} = \@childs;
77 0 S->{'proc'} = \@childs;
78 1 };
79  
80  
81 0 ▶Then qr/the uid of the (?:child )?process(?:es)? must be (\S+)/, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
82 0 my $uid = $1;
83 0 ▶ if( $uid !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uid =~ /^\d+$/) 0 0 0
84 0 $uid = getpwnam($uid);
85 }
86 0 foreach my $proc ( @{S->{'procs'}} ) {
87 0 cmp_ok( $proc->uid, '==', $uid, "uid of process must be $uid");
88 }
89 1 };
90  
91 0 ▶Then qr/the gid of the (?:child )?process(?:es)? must be (\S+)/, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
92 0 my $gid = $1;
93 0 ▶ if( $gid !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gid =~ /^\d+$/) 0 0 0
94 0 $gid = getgrnam($gid);
95 }
96 0 foreach my $proc ( @{S->{'procs'}} ) {
97 0 cmp_ok( $proc->gid, '==', $gid, "gid of process must be $gid");
98 }
99 1 };
100  
101 0 ▶Then qr/the priority of the (?:child )?process(?:es)? must be ([+-]?\d+)/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
102 0 my $prio = $1;
103 0 foreach my $proc ( @{S->{'procs'}} ) {
104 0 cmp_ok( $proc->priority, '==', $prio, "priority of process must be $prio");
105 }
106 1 };
107  
108 0 ▶Then qr/the virtual size of the (?:child )?process(?:es)? must be $CMP_OPERATOR_RE (\d+) (\S+)/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
109 0 my $op = convert_cmp_operator( $1 );
110 0 my $size = $2;
111 0 my $unit = $3;
112 0 $size = convert_unit( $size, $unit );
113 0 foreach my $proc ( @{S->{'procs'}} ) {
114 0 cmp_ok( $proc->size, $op, $size, "virtual size of process must $op $size");
115 }
116 1 };
117  
118 0 ▶Then qr/the RSS size of the (?:child )?process(?:es)? must be $CMP_OPERATOR_RE (\d+) (\S+)/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
119 0 my $op = convert_cmp_operator( $1 );
120 0 my $size = $2;
121 0 my $unit = $3;
122 0 $size = convert_unit( $size, $unit );
123 0 foreach my $proc ( @{S->{'procs'}} ) {
124 0 cmp_ok( $proc->rss, $op, $size, "rss size of process must be $op $size");
125 }
126 1 };
127  
128 1 1;
129  
130 __END__
« Infrastructure/HTTP.pm ↑ Summary Infrastructure/Swap.pm »