lib/Tapper/PRC/Testcontrol.pm

filter: Statementstmt 67.1% 288 / 429 Branchbran 44.9% 97 / 216 Conditioncond 43.4% 20 / 46 MC/DCmcdc 14.2% 4 / 28 Subroutinesub 87.5% 28 / 32 Podpod 94.1% 16 / 17 totaltotal 58.9% 453 / 768 SCAR 72.5
CC
134
Cov
59%
wait_for_sync
90.0
testprogram_execute
83.1
control_testprogram
47.3
CRAP 1407.1
↑ Summary lib/Tapper/PRC.pm »
1 package Tapper::PRC::Testcontrol;
2 24 our $AUTHORITY = 'cpan:TAPPER';
3 24 $Tapper::PRC::Testcontrol::VERSION = '5.0.4';
4 24 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use YAML 'LoadFile';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use English '-no_match_vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use File::Basename qw/basename dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 24 ▶use Tapper::Remote::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 # ABSTRACT: Control running test programs
20  
21 24 extends 'Tapper::PRC';
22  
23 24 our $MAXREAD = 1024; # read that much in one read
24  
25  
26  
27 sub capture_handler_tap
28 {
29 2 ▶ my ($self, $filename) = @_;
Subroutine capture_handler_tap: called CC=2 SCAR=7.0
Pod documented
30 2 my $content;
31 2 ▶ open my $fh, '<', $filename or die "Can not open $filename to send captured report";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Can not open $filename to send captured report" 0 2 2
32 2 { local $/; $content = <$fh> }
33 2 close $fh;
34 2 return $content;
35 }
36  
37  
38 sub send_output
39 {
40 2 ▶ my ($self, $captured_output, $testprogram) = @_;
Subroutine send_output: called CC=5 SCAR=16.7
Pod documented
41  
42 # add missing minimum Tapper meta information
43 2 my $headerlines = "";
44 2 ▶ $headerlines .= "# Tapper-suite-name: ".basename($testprogram->{program})."\n" unless $captured_output =~ /\# Tapper-suite-name:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $captured_output =~ /\# Tapper-suite-name:/ 2 0 2
45 2 ▶ $headerlines .= "# Tapper-machine-name: ".$self->cfg->{hostname}."\n" unless $captured_output =~ /\# Tapper-machine-name:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $captured_output =~ /\# Tapper-machine-name:/ 2 0 2
46 2 ▶ $headerlines .= "# Tapper-reportgroup-testrun: ".$self->cfg->{test_run}."\n" unless $captured_output =~ /\# Tapper-reportgroup-testrun:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $captured_output =~ /\# Tapper-reportgroup-testrun:/ 2 0 2
47  
48 2 $captured_output =~ s/^(1\.\.\d+\n)/$1$headerlines/m;
49  
50 2 my ($error, $message) = $self->tap_report_away($captured_output);
51  
52 2 ▶ return $message if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 2 2
53 2 return 0;
54  
55 }
56  
57  
58 sub send_attachements {
59  
60 2 ▶ my ( $self ) = @_;
Subroutine send_attachements: called CC=3 SCAR=13.3
Pod undocumented
61  
62 my ( $b_error, $s_message ) = $self->tap_report_away(
63 "TAP version 13\n"
64 . "1..1\n"
65 . "# Tapper-suite-name: PRC" . ( $self->cfg->{guest_number} || 0 ) . "-Attachments\n"
66 . "# Tapper-machine-name: " . $self->cfg->{hostname} . "\n"
67 2 ▶ . "# Tapper-reportgroup-testrun: " . $self->cfg->{test_run} . "\n"
Condition50%1/2
$self->cfg->{'guest_number'} || 0
l!l
02
MC/DC0%0/1
$self->cfg->{'guest_number'} || 0
$self->cfg->{'guest_number'}
Truth table50%1/2
A
A= $self->cfg->{'guest_number'}
Aresult
11
00
68 . "ok - Test attachments\n"
69 );
70  
71 2 ▶ return ( 1, $s_message ) if $b_error;
Branch: 1 branch
BranchTrueFalseTotal
if $b_error 2 0 2
72  
73 0 $self->upload_files( $s_message );
74  
75 0 return ( 0, q## );
76  
77 }
78  
79  
80 sub upload_files
81 {
82  
83 1 ▶ my ( $or_self, $i_reportid ) = @_;
Subroutine upload_files: called CC=6 SCAR=18.3
Pod documented
84  
85 1 my $s_host = $or_self->cfg->{report_server};
86 1 my $i_port = $or_self->cfg->{report_api_port};
87 1 my $s_path = $ENV{TAPPER_OUTPUT_PATH};
88  
89 1 ▶ return 0 unless -d $s_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $s_path 0 1 1
90  
91 1 my @a_files = `find $s_path -type f`;
92  
93 1 $or_self->log->debug( @a_files );
94  
95 1 foreach my $s_file( @a_files ) {
96  
97 1 chomp $s_file;
98  
99 1 my $s_reportfile = $s_file;
100 1 $s_reportfile =~ s|^$s_path/*||;
101 #$s_reportfile =~ s|^./||;
102 #$s_reportfile =~ s|[^A-Za-z0-9_-]|_|g;
103  
104 1 my $or_server = IO::Socket::INET->new(
105 PeerAddr => $s_host,
106 PeerPort => $i_port,
107 );
108  
109 1 ▶ return "Cannot open remote receiver $s_host:$i_port" if not $or_server;
Branch: 1 branch
BranchTrueFalseTotal
unless $or_server 0 1 1
110  
111 1 ▶ open( my $fh_file, "<", $s_file ) or do{$or_self->log->warn("Can't open $s_file:$!"); $or_server->close();next;};
Branch: 1 branch
BranchTrueFalseTotal
open my $fh_file, "<", $s_file or do { $or_self->log->warn("Can't open ${s_file}:$!"); $or_server->close; next } 0 1 1
112 1 $or_server->print("#! upload $i_reportid $s_reportfile plain\n");
113 1 ▶ while ( my $line = <$fh_file> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh_file)) 1 1 2
114 1 $or_server->print($line);
115 }
116 1 close($fh_file);
117 1 $or_server->close();
118 1 unlink $s_file; # so we don't upload file again when MCP uploads remaining bits
119 }
120  
121 1 return 0;
122  
123 }
124  
125  
126 sub get_appendix {
127 30 ▶ my($self, $output) = @_;
Subroutine get_appendix: called CC=3 SCAR=11.0
Pod documented
128 30 my $appendix = '';
129 30 ▶ if (-e "$output.stdout" or -e "$output.stderr") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$output.stdout" or -e "$output.stderr") 12 18 30
Condition66%2/3
-e "$output.stdout" or -e "$output.stderr"
l!l&&r!l&&!r
12018
MC/DC50%1/2
-e "$output.stdout" or -e "$output.stderr"
-e "$output.stdout" -e "$output.stderr"
Truth table66%2/3
A or B
A= -e "$output.stdout"B= -e "$output.stderr"
ABresult
1X1
011
000
130 12 my $basename = basename($output);
131 12 my $dirname = dirname ($output);
132 12 my @files = <$dirname/$basename-*.stdout>;
133  
134 24 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 12 my @appendizes = sort map { my ($append) = m/(\d+)\D*$/; $append} @files;
136 12 $appendix = sprintf("-%03d",shift(@appendizes) + 1);
137 }
138 30 return $appendix;
139 }
140  
141  
142 sub kill_process
143 {
144 6 ▶ my ($pid) = @_;
Subroutine kill_process: called CC=5 SCAR=17.6
Pod documented
145  
146 # allow testprogram to react on SIGTERM, then do SIGKILL
147 6 kill ('SIGTERM', $pid);
148 6 waitpid $pid, 0;
149 6 ▶ my $grace_period = $ENV{HARNESS_ACTIVE} ? 0 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HARNESS_ACTIVE'} ? : 6 0 6
150 6 ▶ while ( $grace_period > 0 and (kill 0, $pid) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grace_period > 0 and kill 0, $pid) 0 6 6
Condition33%1/3
$grace_period > 0 and kill 0, $pid
!ll&&!rl&&r
600
MC/DC0%0/2
$grace_period > 0 and kill 0, $pid
$grace_period > 0 kill 0, $pid
Truth table33%1/3
A and B
A= $grace_period > 0B= kill 0, $pid
ABresult
0X0
100
111
151 0 $grace_period--;
152 0 sleep 1;
153 }
154 6 ▶ if (kill 0, $pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (kill 0, $pid) 2 4 6
155 2 kill 'SIGKILL', $pid;
156 2 waitpid $pid, 0;
157 }
158 }
159  
160  
161 sub get_process_tree
162 {
163 4 ▶ my ($pid) = @_;
Subroutine get_process_tree: called CC=3 SCAR=11.8
Pod documented
164  
165 4 ▶ return () unless $pid && $pid > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $pid and $pid > 1 0 4 4
Condition33%1/3
$pid and $pid > 1
!ll&&!rl&&r
004
MC/DC0%0/2
$pid and $pid > 1
$pid $pid > 1
Truth table33%1/3
A and B
A= $pidB= $pid > 1
ABresult
0X0
100
111
166  
167 4 require Proc::Killfam;
168 4 require Proc::ProcessTable;
169 4 return Proc::Killfam::get_pids(Proc::ProcessTable->new->table, $pid);
170 }
171  
172  
173 sub kill_process_tree
174 {
175 4 ▶ my ($pid) = @_;
Subroutine kill_process_tree: called CC=5 SCAR=16.1
Pod documented
176  
177 4 ▶ return unless $pid > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $pid > 1 0 4 4
178  
179 4 my @pids = get_process_tree($pid);
180 4 kill_process($_) foreach ($pid, @pids);
181 4 ▶ if (@pids) { kill_process_tree($_) foreach @pids }
Branch: 1 branch
BranchTrueFalseTotal
if (@pids) 2 2 4
182 }
183  
184  
185 sub testprogram_execute
186 {
187 21 ▶ my ($self, $test_program) = @_;
Subroutine testprogram_execute: called CC=35 SCAR=44.2
Pod documented
188  
189 21 my $program = $test_program->{program};
190 21 my $chdir = $test_program->{chdir};
191 21 my $progpath = $self->cfg->{paths}{testprog_path};
192 21 my $output = $program;
193 21 $output =~ s|[^A-Za-z0-9_-]|_|g;
194 21 $output = $test_program->{out_dir}.$output;
195  
196  
197 21 ▶ if ($program !~ m(^/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($program =~ m[^/]) 18 3 21
198 18 $ENV{PATH} = "$progpath:$ENV{PATH}";
199 18 $program = qx(which $program);
200 18 chomp $program;
201 }
202  
203 # try to catch non executables early
204 21 ▶ if (-e $program) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $program) 19 2 21
205 19 ▶ if (not -x $program) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $program) 0 19 19
206 0 system ("chmod", "ugo+x", $program);
207 0 ▶ return("tried to execute $program which is not an execuable and can not set exec flag") if not -x $program;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $program 0 0 0
208 }
209  
210 19 ▶ return("tried to execute $program which is a directory") if -d $program;
Branch: 1 branch
BranchTrueFalseTotal
if -d $program 0 19 19
211 19 ▶ return("tried to execute $program which is a special file (FIFO, socket, device, ..)") unless -f $program or -l $program;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $program or -l $program 0 19 19
Condition33%1/3
-f $program or -l $program
l!l&&r!l&&!r
1900
MC/DC0%0/2
-f $program or -l $program
-f $program -l $program
Truth table33%1/3
A or B
A= -f $programB= -l $program
ABresult
1X1
011
000
212 }
213  
214 21 ▶ foreach my $file (@{$test_program->{upload_before} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
$test_program->{"upload_before"} or [] 21 0 21
215  
216 0 my $target_name =~ s|[^A-Za-z0-9_-]|_|g;
217 0 $target_name = $test_program->{out_dir}.'/before/'.$target_name;
218 0 File::Copy::copy($file, $target_name);
219  
220 }
221  
222 21 $self->log->info("Try to execute test suite $program");
223  
224 21 my $appendix = $self->get_appendix($output);
225 21 pipe (my $read, my $write);
226 21 ▶ return ("Can't open pipe:$!") if not (defined $read and defined $write);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read and defined $write 0 21 21
Condition33%1/3
defined $read and defined $write
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $read and defined $write
defined $read defined $write
Truth table33%1/3
A and B
A= defined $readB= defined $write
ABresult
0X0
100
111
227  
228 21 my $pid=fork();
229 21 ▶ return( "fork failed: $!" ) if not defined($pid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 21 21
230  
231 21 ▶ if ($pid == 0) { # hello child
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) { } 9 12 21
232 9 close $read;
233  
234 9 ▶ %ENV = (%ENV, %{$test_program->{environment} || {} });
Branch: 1 branch
BranchTrueFalseTotal
$test_program->{"environment"} or {} 9 0 9
235 9 ▶ open (STDOUT, ">", "$output$appendix.stdout") or syswrite($write, "Can't open output file $output$appendix.stdout: $!"),exit 1;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">", "$output$appendix.stdout" or syswrite($write, "Can't open output file $output$appendix.stdout: $!"), exit 1 0 9 9
236 9 ▶ open (STDERR, ">", "$output$appendix.stderr") or syswrite($write, "Can't open output file $output$appendix.stderr: $!"),exit 1;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", "$output$appendix.stderr" or syswrite($write, "Can't open output file $output$appendix.stderr: $!"), exit 1 0 9 9
237 9 ▶ if ($chdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chdir) 0 9 9
238 0 ▶ if (-d $chdir) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $chdir) { } 0 0 0
elsif ($chdir eq 'AUTO' and $program =~ m[^/]) { } 0 0 0
239 0 chdir $chdir;
240 ▶ } elsif ($chdir eq "AUTO" and $program =~ m,^/, ) {
Condition0%0/3
$chdir eq "AUTO" and $program =~ m[^/]
!ll&&!rl&&r
000
MC/DC0%0/2
$chdir eq "AUTO" and $program =~ m[^/]
$chdir eq "AUTO" $program =~ m[^/]
Truth table0%0/3
A and B
A= $chdir eq "AUTO"B= $program =~ m[^/]
ABresult
0X0
100
111
241 0 chdir dirname($program);
242 }
243 }
244 9 ▶ exec ($program, @{$test_program->{argv} || []}) or syswrite($write,"$!\n");
Branch: 2 branches
BranchTrueFalseTotal
exec $program, @{$test_program->{"argv"} or [];} or syswrite $write, "$!\n" 0 0 0
$test_program->{"argv"} or [] 2 7 9
245 0 close $write;
246 0 exit -1;
247 } else {
248  
249 # hello parent
250 12 close $write;
251  
252 12 my $killed;
253 my $sig_name;
254 my $signal_kill = sub {
255 2 ▶ $killed = 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
256 2 ($sig_name) = @_;
257 2 $self->log->warn("Catched signal $sig_name");
258 2 kill_process_tree ($pid);
259 12 };
260 12 local $SIG{ALRM} = $signal_kill;
261 12 local $SIG{TERM} = $signal_kill;
262 12 local $SIG{KILL} = $signal_kill;
263 12 local $SIG{QUIT} = $signal_kill;
264 12 local $SIG{INT} = $signal_kill;
265  
266 12 ▶ alarm ($test_program->{timeout} || 0);
Condition100%2/2
$test_program->{'timeout'} || 0
l!l
75
MC/DC100%1/1
$test_program->{'timeout'} || 0
$test_program->{'timeout'}
Truth table100%2/2
A
A= $test_program->{'timeout'}
Aresult
11
00
267 12 waitpid($pid,0);
268 12 my $retval = $?;
269 12 alarm(0);
270  
271 12 ▶ foreach my $file (@{$test_program->{upload_after} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
$test_program->{"upload_after"} or [] 12 0 12
272 0 my $target_name =~ s|[^A-Za-z0-9_-]|_|g;
273 0 $target_name = $test_program->{out_dir}.'/after/'.$target_name;
274 0 File::Copy::copy($file, $target_name);
275 }
276 12 ▶ if ($test_program->{capture}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_program->{"capture"}) 2 10 12
277 2 my $captured_output;
278 2 ▶ if ( $test_program->{capture} eq 'tap' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($test_program->{'capture'} eq 'tap') { } 2 0 2
elsif ($test_program->{'capture'} eq 'tap-stderr') { } 0 0 0
279 2 eval { $captured_output = $self->capture_handler_tap("$output$appendix.stdout")};
280 2 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
281 }
282 elsif ( $test_program->{capture} eq 'tap-stderr' ) {
283 0 eval { $captured_output = $self->capture_handler_tap("$output$appendix.stderr")};
284 0 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
285 }
286 else {
287 0 return "Can not handle captured output, unknown capture type '$test_program->{capture}'. Valid types are (tap)";
288 }
289 2 my ( $b_error, $error_msg ) = $self->send_output($captured_output, $test_program);
290 2 ▶ return $error_msg if $b_error;
Branch: 1 branch
BranchTrueFalseTotal
if $b_error 0 2 2
291 }
292  
293 12 ▶ if ($killed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($killed) 2 10 12
294 return
295 "Killed $program after SIG:$sig_name"
296 .(
297 $sig_name eq "ALRM"
298 2 ▶ ? " (timeout ".$test_program->{timeout}." seconds)"
Branch: 1 branch
BranchTrueFalseTotal
$sig_name eq 'ALRM' ? : 2 0 2
299 : ""
300 );
301 }
302  
303 10 ▶ if ( $retval ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 3 7 10
304 3 my $error;
305 3 sysread($read,$error, $MAXREAD);
306 3 $error =~ s/[\r\n]//g;
307 3 return("Executing $program failed:$error");
308 }
309 }
310 7 return 0;
311 }
312  
313  
314 sub guest_start
315 {
316 1 ▶ my ($self) = @_;
Subroutine guest_start: called CC=15 SCAR=38.2
Pod documented
317 1 my ($error, $retval);
318 GUEST:
319 1 ▶ for (my $i=0; $i<=$#{$self->cfg->{guests}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$self->cfg->{"guests"};}) 2 1 3
320 2 my $guest = $self->cfg->{guests}->[$i];
321 2 ▶ if ($guest->{exec}){
Branch: 3 branches
BranchTrueFalseTotal
if ($guest->{'exec'}) { } 0 2 2
elsif ($guest->{'svm'}) { } 1 1 2
elsif ($guest->{'xen'}) { } 1 0 1
322 0 my $startscript = $guest->{exec};
323 0 $self->log->info("Try to start virtualisation guest with $startscript");
324 0 ▶ if (not -s $startscript) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -s $startscript) { } 0 0 0
325 0 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
326 error => qq(Startscript "$startscript" is empty or does not exist at all)});
327 0 next GUEST;
328 } else {
329 # just try to set it executable always
330 0 ▶ if (not -x $startscript) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $startscript) 0 0 0
331 0 ▶ unless (system ("chmod", "ugo+x", $startscript) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (system("chmod", "ugo+x", $startscript) == 0) 0 0 0
332 0 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
333 error =>
334 return qq(Unable to set executable bit on "$startscript": $!)
335 });
336 0 next GUEST;
337 }
338 }
339 }
340 0 ▶ if (not system($startscript) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (system($startscript) == 0) 0 0 0
341 0 $retval = qq(Can't start virtualisation guest using startscript "$startscript");
342 0 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
343 error => $retval});
344 0 next GUEST;
345 }
346 } elsif ($guest->{svm}){
347 1 my $xm = `which xm`; chomp $xm;
348 1 $self->log->info("Try load Xen guest described in ",$guest->{svm});
349 1 ($error, $retval) = $self->log_and_exec($xm, 'create', $guest->{svm});
350 1 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 1 0 1
351 1 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
352 error => $retval});
353 1 next GUEST;
354 }
355 } elsif ($guest->{xen}) {
356 1 $self->log->info("Try load Xen guest described in ",$guest->{xen});
357  
358 1 my $guest_file = $guest->{xen};
359 1 ▶ if ($guest_file =~ m/^(.+)\.(?:xl|svm)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guest_file =~ /^(.+)\.(?:xl|svm)$/) 1 0 1
360 1 $guest_file = $1;
361 }
362  
363 1 my $xm = `which xm`; chomp $xm;
364 1 my $xl = `which xl`; chomp $xl;
365  
366 1 ▶ if ( -e $xl ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e $xl) { } 1 0 1
elsif (-e $xm) { } 0 0 0
367 1 ($error, $retval) = $self->log_and_exec($xl, 'create', $guest_file.".xl");
368 1 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 1 0 1
369 1 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
370 error => $retval});
371 1 next GUEST;
372 }
373 } elsif ( -e $xm ) {
374 0 ($error, $retval) = $self->log_and_exec($xm, 'create', $guest_file.".svm");
375 0 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
376 0 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
377 error => $retval});
378 0 next GUEST;
379 }
380 } else {
381 0 $retval = "Can not find both xm and xl.";
382 0 $self->mcp_send({prc_number => ($i+1), state => 'error-guest',
383 error => $retval});
384 0 next GUEST;
385 }
386 }
387 0 $self->mcp_send({prc_number => ($i+1), state => 'start-guest'});
388 }
389 1 return 0;
390 }
391  
392  
393 sub create_log
394 {
395 8 ▶ my ($self) = @_;
Subroutine create_log: called CC=6 SCAR=25.6
Pod documented
396 8 my $testrun = $self->cfg->{test_run};
397 my $output_dir = ($self->cfg->{test_type} || '') eq 'minion'
398 ? $self->cfg->{paths}{minion_output_dir}
399 8 ▶ : $self->cfg->{paths}{output_dir};
Branch: 1 branch
BranchTrueFalseTotal
($self->cfg->{'test_type'} || '') eq 'minion' ? : 0 8 8
Condition50%1/2
$self->cfg->{'test_type'} || ''
l!l
08
MC/DC0%0/1
$self->cfg->{'test_type'} || ''
$self->cfg->{'test_type'}
Truth table50%1/2
A
A= $self->cfg->{'test_type'}
Aresult
11
00
400 8 my $outdir = "$output_dir/$testrun/test/";
401 8 my ($error, $retval);
402  
403 8 ▶ for (my $i = 0; $i <= $#{$self->cfg->{guests}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$self->cfg->{"guests"};}) 0 8 8
404 # guest count starts with 1, arrays start with 0
405 0 my $guest_number=$i+1;
406  
407 # every guest gets its own subdirectory
408 0 my $guestoutdir="$outdir/guest-$guest_number/";
409  
410 0 $error = $self->makedir($guestoutdir);
411 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
412  
413 0 $self->log_and_exec("touch $guestoutdir/console");
414 0 $self->log_and_exec("chmod 666 $guestoutdir/console");
415 0 ($error, $retval) = $self->log_and_exec("ln -sf $guestoutdir/console /tmp/guest$guest_number.fifo");
416 0 ▶ return "Can't create guest console file $guestoutdir/console: $retval" if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
417 }
418 8 return 0;
419 }
420  
421  
422 sub nfs_mount
423 {
424 0 ▶ my ($self) = @_;
Subroutine nfs_mount: not called CC=5 SCAR=34.0
Pod documented
425 0 my ($error, $retval);
426  
427 0 $error = $self->makedir($self->cfg->{paths}{prc_nfs_mountdir});
428 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
429  
430 0 ($error, $retval) = $self->log_and_exec("mount",$self->cfg->{paths}{prc_nfs_mountdir});
431 0 ▶ return 0 if not $error;
Branch: 1 branch
BranchTrueFalseTotal
unless $error 0 0 0
432 0 ($error, $retval) = $self->log_and_exec("mount",$self->cfg->{prc_nfs_server}.":".$self->cfg->{paths}{prc_nfs_mountdir},$self->cfg->{paths}{prc_nfs_mountdir});
433 # report error, but only if not already mounted
434 0 ▶ return "Can't mount ".$self->cfg->{paths}{prc_nfs_mountdir}.":$retval" if ($error and ! -d $self->cfg->{paths}{prc_nfs_mountdir}."/live");
Branch: 1 branch
BranchTrueFalseTotal
if $error and not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live' 0 0 0
Condition0%0/3
$error and not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live'
!ll&&!rl&&r
000
MC/DC0%0/2
$error and not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live'
$error not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live'
Truth table0%0/3
A and not(B)
A= $errorB= not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live'
ABresult
0X0
100
111
435 0 return 0;
436 }
437  
438  
439 sub control_testprogram
440 {
441 11 ▶ my ($self) = @_;
Subroutine control_testprogram: called CC=24 SCAR=38.6
Pod documented
442  
443 11 $ENV{TAPPER_TESTRUN} = $self->cfg->{test_run};
444 11 $ENV{TAPPER_SERVER} = $self->cfg->{mcp_server};
445 11 $ENV{TAPPER_REPORT_SERVER} = $self->cfg->{report_server};
446 11 $ENV{TAPPER_REPORT_API_PORT} = $self->cfg->{report_api_port};
447 11 $ENV{TAPPER_REPORT_PORT} = $self->cfg->{report_port};
448 11 $ENV{TAPPER_HOSTNAME} = $self->cfg->{hostname};
449 11 ▶ $ENV{TAPPER_REBOOT_COUNTER} = $self->cfg->{reboot_counter} if $self->cfg->{reboot_counter};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"reboot_counter"} 0 11 11
450 11 ▶ $ENV{TAPPER_MAX_REBOOT} = $self->cfg->{max_reboot} if $self->cfg->{max_reboot};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"max_reboot"} 0 11 11
451 11 ▶ $ENV{TAPPER_GUEST_NUMBER} = $self->cfg->{guest_number} || 0;
Condition50%1/2
$self->cfg->{'guest_number'} || 0
l!l
011
MC/DC0%0/1
$self->cfg->{'guest_number'} || 0
$self->cfg->{'guest_number'}
Truth table50%1/2
A
A= $self->cfg->{'guest_number'}
Aresult
11
00
452 11 ▶ $ENV{TAPPER_SYNC_FILE} = $self->cfg->{syncfile} if $self->cfg->{syncfile};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"syncfile"} 8 3 11
453 11 $ENV{TAPPER_SYNC_PATH} = $self->cfg->{paths}{sync_path}; # if -d ($self->cfg->{paths}{sync_path} || '');
454 11 ▶ if ($self->{cfg}->{testplan}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cfg"}{"testplan"}) 0 11 11
455 0 $ENV{TAPPER_TESTPLAN_ID} = $self->cfg->{testplan}{id};
456 0 $ENV{TAPPER_TESTPLAN_PATH} = $self->cfg->{testplan}{path};
457 }
458  
459 11 my $test_run = $self->cfg->{test_run};
460 my $output_dir = ($self->cfg->{test_type} || '') eq 'minion'
461 ? $self->cfg->{paths}{minion_output_dir}
462 11 ▶ : $self->cfg->{paths}{output_dir};
Branch: 1 branch
BranchTrueFalseTotal
($self->cfg->{'test_type'} || '') eq 'minion' ? : 0 11 11
Condition50%1/2
$self->cfg->{'test_type'} || ''
l!l
011
MC/DC0%0/1
$self->cfg->{'test_type'} || ''
$self->cfg->{'test_type'}
Truth table50%1/2
A
A= $self->cfg->{'test_type'}
Aresult
11
00
463 11 my $out_dir = "$output_dir/$test_run/test/";
464 11 my @testprogram_list;
465 11 ▶ @testprogram_list = @{$self->cfg->{testprogram_list}} if $self->cfg->{testprogram_list};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"testprogram_list"} 11 0 11
466  
467 # prepend outdir with guest number if we are in virtualisation guest
468 11 ▶ $out_dir.="guest-".$self->{cfg}->{guest_number}."/" if $self->{cfg}->{guest_number};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cfg"}{"guest_number"} 0 11 11
469  
470 11 my $error = $self->makedir($out_dir);
471  
472 # can't create output directory. Make
473 11 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 11 11
474 0 $self->log->warn($error);
475 0 $out_dir = tempdir( CLEANUP => 1 );
476 }
477  
478 11 $ENV{TAPPER_OUTPUT_PATH} = $out_dir;
479  
480 11 ▶ if ($self->cfg->{test_program}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"test_program"}) 0 11 11
481 0 my $argv;
482 my $environment;
483 0 my $chdir;
484 0 ▶ $argv = $self->cfg->{parameters} if $self->cfg->{parameters};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"parameters"} 0 0 0
485 0 ▶ $environment = $self->cfg->{environment} if $self->cfg->{environment};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"environment"} 0 0 0
486 0 ▶ $chdir = $self->cfg->{chdir} if $self->cfg->{chdir};
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg->{"chdir"} 0 0 0
487 0 ▶ my $timeout = $self->cfg->{timeout_testprogram} || 0;
Condition0%0/2
$self->cfg->{'timeout_testprogram'} || 0
l!l
00
MC/DC0%0/1
$self->cfg->{'timeout_testprogram'} || 0
$self->cfg->{'timeout_testprogram'}
Truth table0%0/2
A
A= $self->cfg->{'timeout_testprogram'}
Aresult
11
00
488 0 $timeout = int $timeout;
489 0 my $runtime = $self->cfg->{runtime};
490 push (@testprogram_list, {program => $self->cfg->{test_program},
491 chdir => $chdir,
492 parameters => $argv,
493 environment => $environment,
494 timeout => $timeout,
495 runtime => $runtime,
496 upload_before => $self->cfg->{upload_before},
497 upload_after => $self->cfg->{upload_after},
498 0 });
499 }
500  
501  
502 11 ▶ for (my $i=0; $i<=$#testprogram_list; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#testprogram_list) 15 6 21
503 15 my $testprogram = $testprogram_list[$i];
504  
505 15 ▶ $ENV{TAPPER_TS_RUNTIME} = $testprogram->{runtime} || 0;
Condition100%2/2
$testprogram->{'runtime'} || 0
l!l
105
MC/DC100%1/1
$testprogram->{'runtime'} || 0
$testprogram->{'runtime'}
Truth table100%2/2
A
A= $testprogram->{'runtime'}
Aresult
11
00
506  
507 # unify differences in program vs. program_list vs. virt
508 15 ▶ $testprogram->{program} ||= $testprogram->{test_program};
Condition33%1/3
$testprogram->{"program"} ||= $testprogram->{"test_program"}
l!l&&r!l&&!r
1500
MC/DC0%0/2
$testprogram->{"program"} ||= $testprogram->{"test_program"}
$testprogram->{"program"} $testprogram->{"test_program"}
Truth table33%1/3
A ||= B
A= $testprogram->{"program"}B= $testprogram->{"test_program"}
ABresult
1X1
011
000
509 15 ▶ $testprogram->{timeout} ||= $testprogram->{timeout_testprogram};
Condition66%2/3
$testprogram->{"timeout"} ||= $testprogram->{"timeout_testprogram"}
l!l&&r!l&&!r
5100
MC/DC0%0/2
$testprogram->{"timeout"} ||= $testprogram->{"timeout_testprogram"}
$testprogram->{"timeout"} $testprogram->{"timeout_testprogram"}
Truth table66%2/3
A ||= B
A= $testprogram->{"timeout"}B= $testprogram->{"timeout_testprogram"}
ABresult
1X1
011
000
510 15 ▶ $testprogram->{argv} = $testprogram->{parameters} if @{$testprogram->{parameters} || []};
Branch: 2 branches
BranchTrueFalseTotal
if @{$testprogram->{"parameters"} or [];} 8 7 15
$testprogram->{"parameters"} or [] 7 8 15
511  
512 # create hash for testprogram_execute
513 15 ▶ $testprogram->{timeout} ||= 0;
Condition50%1/2
$testprogram->{"timeout"} ||= 0
l!l
150
MC/DC0%0/1
$testprogram->{"timeout"} ||= 0
$testprogram->{"timeout"}
Truth table50%1/2
A
A= $testprogram->{"timeout"}
Aresult
11
00
514 15 $testprogram->{out_dir} = $out_dir;
515  
516 15 my $retval = $self->testprogram_execute($testprogram);
517  
518 10 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) { } 3 7 10
519 3 my $error_msg = "Error while executing $testprogram->{program}: $retval";
520 3 $self->mcp_inform({testprogram => $i, state => 'error-testprogram', error => $error_msg});
521 3 $self->log->info($error_msg);
522 } else {
523 7 $self->mcp_inform({testprogram => $i , state => 'end-testprogram'});
524 7 $self->log->info("Successfully finished test suite $testprogram->{program}");
525 }
526  
527 }
528  
529 6 return(0);
530 }
531  
532  
533 sub get_peers_from_file
534 {
535 0 ▶ my ($self, $file) = @_;
Subroutine get_peers_from_file: not called CC=3 SCAR=24.8
Pod documented
536 0 my $peers;
537  
538 0 $peers = LoadFile($file);
539 0 ▶ return "Syncfile does not contain a list of host names" if not ref($peers) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $peers eq "ARRAY" 0 0 0
540  
541 0 my $hostname = $self->cfg->{hostname};
542 0 my %peerhosts;
543 0 foreach my $host (@$peers) {
544 0 $peerhosts{$host} = 1;
545 }
546 0 delete $peerhosts{$hostname};
547  
548 0 return \%peerhosts;
549 }
550  
551  
552 sub wait_for_sync
553 {
554 0 ▶ my ($self, $syncfile) = @_;
Subroutine wait_for_sync: not called CC=9 SCAR=45.0
Pod documented
555  
556 0 my %peerhosts; # easier to delete than from array
557  
558 0 eval {
559 0 %peerhosts = %{$self->get_peers_from_file($syncfile)};
560 };
561 0 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
562  
563  
564 0 my $hostname = $self->cfg->{hostname};
565 0 my $port = $self->cfg->{sync_port};
566 0 my $sync_srv = IO::Socket::INET->new( LocalPort => $port, Listen => 5, );
567 0 my $select = IO::Select->new($sync_srv);
568  
569 0 $self->log->info("Trying to sync with: ". join(", ",sort keys %peerhosts));
570  
571 0 foreach my $host (keys %peerhosts) {
572 0 my $remote = IO::Socket::INET->new(PeerPort => $port, PeerAddr => $host,);
573 0 ▶ if ($remote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remote) 0 0 0
574 0 $remote->print($hostname);
575 0 $remote->close();
576 0 delete($peerhosts{$host});
577 }
578 0 ▶ if ($select->can_read(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($select->can_read(0)) 0 0 0
579 0 my $msg_srv = $sync_srv->accept();
580 0 my $remotehost;
581 0 $msg_srv->read($remotehost, 2048); # no hostnames are that long, anything longer is wrong and can be ignored
582 0 chomp $remotehost;
583 0 $msg_srv->close();
584 0 ▶ if ($peerhosts{$remotehost}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peerhosts{$remotehost}) { } 0 0 0
585 0 delete($peerhosts{$remotehost});
586 } else {
587 0 $self->log->warn(qq(Received sync request from host "$remotehost" which is not in our peerhost list. Request was sent from ),$msg_srv->peerhost);
588 }
589 }
590 0 $self->log->debug("In sync with $host.");
591  
592 }
593  
594 0 ▶ while (%peerhosts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%peerhosts) 0 0 0
595 0 ▶ if ($select->can_read()) { # TODO: timeout handling
Branch: 1 branch
BranchTrueFalseTotal
if ($select->can_read) { } 0 0 0
596 0 my $msg_srv = $sync_srv->accept();
597 0 my $remotehost;
598 0 $msg_srv->read($remotehost, 2048); # no hostnames are that long, anything longer is wrong and can be ignored
599 0 chomp $remotehost;
600 0 $msg_srv->close();
601 0 ▶ if ($peerhosts{$remotehost}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peerhosts{$remotehost}) { } 0 0 0
602 0 delete($peerhosts{$remotehost});
603 0 $self->log->debug("In sync with $remotehost.");
604 } else {
605 0 $self->log->warn(qq(Received sync request from host "$remotehost" which is not in our peerhost list. Request was sent from ),$msg_srv->peerhost);
606 }
607 } else {
608 # handle timeout here when can_read() has a timeout eventually
609 }
610 }
611 0 return 0;
612 }
613  
614  
615 sub send_keep_alive_loop
616 {
617 0 ▶ my ($self, $sleeptime) = @_;
Subroutine send_keep_alive_loop: not called CC=2 SCAR=17.9
Pod documented
618 0 ▶ return unless $sleeptime;
Branch: 1 branch
BranchTrueFalseTotal
unless $sleeptime 0 0 0
619 0 while (1) {
620 0 $self->mcp_inform("keep-alive");
621 0 sleep($sleeptime);
622 }
623 0 return;
624 }
625  
626  
627 sub run
628 {
629 8 ▶ my ($self) = @_;
Subroutine run: called CC=19 SCAR=36.5
Pod documented
630  
631 8 my $producer = Tapper::Remote::Config->new();
632 8 my $config = $producer->get_local_data("test-prc0");
633  
634 8 $self->cfg($config);
635  
636 8 $0 = "tapper-prc-testcontrol-".$self->cfg->{test_run};
637  
638 8 ▶ $self->cfg->{reboot_counter} = 0 if not defined($self->cfg->{reboot_counter});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->cfg->{"reboot_counter"} 4 4 8
639  
640 8 ▶ if ($self->cfg->{log_to_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"log_to_file"}) 0 8 8
641 0 $self->log_to_file('testing');
642 }
643  
644 # ignore error
645 8 $self->log_and_exec('ntpdate -s gwo');
646  
647 8 ▶ if ($config->{prc_nfs_server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"prc_nfs_server"}) 0 8 8
648 0 ▶ if ( my $retval = $self->nfs_mount() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $retval = $self->nfs_mount) 0 0 0
649 0 $self->log->warn($retval);
650 }
651 }
652  
653 8 ▶ if ( my $retval = $self->create_log() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $retval = $self->create_log) 0 8 8
654 0 $self->log->logdie($retval);
655 }
656  
657 8 ▶ if ($config->{scenario_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"scenario_id"}) 0 8 8
658 0 my $syncfile = $config->{paths}{sync_path}."/".$config->{scenario_id}."/syncfile";
659 0 ▶ if (-e $syncfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $syncfile) 0 0 0
660 0 $self->cfg->{syncfile} = $syncfile;
661  
662 0 ▶ if ( my $retval = $self->wait_for_sync($syncfile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $retval = $self->wait_for_sync($syncfile)) 0 0 0
663 0 $self->log->logdie("Can not sync - $retval");
664 }
665 }
666 }
667  
668 8 ▶ if ($self->{cfg}->{guest_count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cfg"}{"guest_count"}) 0 8 8
669 0 ▶ if ( my $retval = $self->guest_start() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $retval = $self->guest_start) 0 0 0
670 0 $self->log->error($retval);
671 }
672 }
673  
674 8 ▶ if ( not $self->cfg->{reboot_counter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cfg->{"reboot_counter"}) 7 1 8
675 7 $self->mcp_inform({state => 'start-testing'});
676 }
677  
678 8 ▶ if ( $self->cfg->{test_program} or $self->cfg->{testprogram_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"test_program"} or $self->cfg->{"testprogram_list"}) 6 2 8
Condition66%2/3
$self->cfg->{"test_program"} or $self->cfg->{"testprogram_list"}
l!l&&r!l&&!r
062
MC/DC50%1/2
$self->cfg->{"test_program"} or $self->cfg->{"testprogram_list"}
$self->cfg->{"test_program"} $self->cfg->{"testprogram_list"}
Truth table66%2/3
A or B
A= $self->cfg->{"test_program"}B= $self->cfg->{"testprogram_list"}
ABresult
1X1
011
000
679 6 $self->control_testprogram();
680 }
681  
682 4 ▶ if ($self->cfg->{max_reboot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"max_reboot"}) 2 2 4
683 2 $self->mcp_inform({state => 'reboot', count => $self->cfg->{reboot_counter}, max_reboot => $self->cfg->{max_reboot}});
684 2 ▶ if ($self->cfg->{reboot_counter} < $self->cfg->{max_reboot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"reboot_counter"} < $self->cfg->{"max_reboot"}) 2 0 2
685 2 $self->cfg->{reboot_counter}++;
686 2 ▶ YAML::Syck::DumpFile($config->{filename}, $self->{cfg}) or $self->mcp_error("Can't write config to file: $!");
Branch: 1 branch
BranchTrueFalseTotal
YAML::Syck::DumpFile($config->{"filename"}, $self->{"cfg"}) or $self->mcp_error("Can't write config to file: $!") 0 2 2
687 2 $self->log_and_exec("reboot");
688 2 return 0;
689 }
690  
691 }
692  
693 # TODO: too cheap work-around
694 #
695 # Make sure last end-testing can't overtake last
696 # end-testprogram (Yes, this did happen).
697 #
698 # Wait at least as long as the MCP loop time is, see
699 # tapper.cfg:
700 # - mcp.child.get_message_sleep_interval
701 # - times.poll_intervall
702  
703  
704 2 ▶ sleep ($ENV{HARNESS_ACTIVE} ? 1 : 10);
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HARNESS_ACTIVE'} ? : 2 0 2
705  
706 # send attachment report
707 2 my ( $b_error, $s_error_msg ) = $self->send_attachements();
708 2 ▶ if ( $b_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_error) 2 0 2
709 2 $self->log->error( $s_error_msg );
710 }
711  
712 2 $self->mcp_inform({state => 'end-testing'});
713  
714 2 return 1;
715  
716 }
717  
718 24 1;
719  
720 __END__
721  
722 =pod
723  
724 =encoding UTF-8
725  
726 =head1 NAME
727  
728 Tapper::PRC::Testcontrol - Control running test programs
729  
730 =head1 FUNCTIONS
731  
732 =head2 capture_handler_tap
733  
734 This function is a handler for the capture function. It handles capture
735 requests of type 'tap'. This means the captured output is supposed to be
736 TAP already and therefore no transformation is needed.
737  
738 @param file handle - opened file handle
739  
740 @return string - output in TAP format
741 @return error - die()
742  
743 =head2 send_output
744  
745 Send the captured TAP output to the report receiver.
746  
747 @param string - TAP text
748  
749 @return success - 0
750 @return error - error string
751  
752 =head2 send_output
753  
754 Send the a attachment to the report receiver and add attachements.
755  
756 @return success - 0
757 @return error - error string
758  
759 =head2 upload_files
760  
761 Upload files written in one stage of the testrun to report framework.
762  
763 @param int - report id
764 @param int - testrun id
765  
766 @return success - 0
767 @return error - error string
768  
769 =head2 get_appendix
770  
771 For testprogram with the same name the output file names will be
772 identical. To prevent this, we append a serial number. This function
773 calculates this appendix and returns the next one to use. If no such
774 serial is needed because no output file of the given name exists yet the
775 empty string is returned.
776  
777 @param string - name of the output file without appendix
778  
779 @return string - string to append to output file name to make it unique
780  
781 =head2 kill_process($pid)
782  
783 Gracefully kill a single process.
784  
785 =head2 get_process_tree($pid)
786  
787 Get list of children for a process. The process itself is not
788 contained in the list.
789  
790 =head2 kill_process_tree($pid)
791  
792 Kill whole tree of processes, depth-first, with extreme prejudice.
793  
794 =head2 testprogram_execute
795  
796 Execute one testprogram. Handle all error conditions.
797  
798 @param hash ref - contains all config options for program to execute
799 * program - program name
800 * timeout - timeout in seconds
801 * outdir - output directory
802 * parameters - arrayref of strings - parameters for test program
803 * environment - hashref of strings - environment variables for test program
804 * chdir - string - where to chdir before executing the testprogram
805  
806 @return success - 0
807 @return error - error string
808  
809 =head2 guest_start
810  
811 Start guest images for virtualisation. Only Xen guests can be started at the
812 moment.
813  
814 @return success - 0
815 @return error - error string
816  
817 =head2 create_log
818  
819 Checks whether fifos for guest logging exists and creates them if
820 not. Existing files of wrong type are deleted.
821  
822 @retval success - 0
823 @retval error - error string
824  
825 =head2 nfs_mount
826  
827 Mount the output directory from an NFS server. This method is used since we
828 only want to mount this NFS share in live mode.
829  
830 @return success - 0
831 @return error - error string
832  
833 =head2 control_testprogram
834  
835 Control running of one program including caring for its input, output and
836 the environment variables some testers asked for.
837  
838 @return success - 0
839 @return error - error string
840  
841 =head2 get_peers_from_file
842  
843 Read syncfile and extract list of peer hosts (not including this host).
844  
845 @param string - file name
846  
847 @return success - hash ref
848  
849 @throws plain error message
850  
851 =head2 wait_for_sync
852  
853 Synchronise with other hosts belonging to the same interdependent testrun.
854  
855 @param array ref - list of hostnames of peer machines
856  
857 @return success - 0
858 @return error - error string
859  
860 =head2 send_keep_alive_loop
861  
862 Send keepalive messages to MCP in an endless loop.
863  
864 @param int - sleep time between two keepalives
865  
866 =head2 run
867  
868 Main function of Program Run Control.
869  
870 =head1 AUTHORS
871  
872 =over 4
873  
874 =item *
875  
876 AMD OSRC Tapper Team <tapper@amd64.org>
877  
878 =item *
879  
880 Tapper Team <tapper-ops@amazon.com>
881  
882 =back
883  
884 =head1 COPYRIGHT AND LICENSE
885  
886 This software is Copyright (c) 2019 by Advanced Micro Devices, Inc..
887  
888 This is free software, licensed under:
889  
890 The (two-clause) FreeBSD License
891  
892 =cut
↑ Summary lib/Tapper/PRC.pm »