| 1 | package Tapper::PRC::Testcontrol; | ||||||||||||||||||||||||||||
| 2 | 25 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 25 | $Tapper::PRC::Testcontrol::VERSION = '5.0.5'; | |||||||||||||||||||||||||||
| 4 | 26 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 26 | ▶ | use IPC::Open3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 26 | ▶ | use File::Copy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 26 | ▶ | use File::Temp qw/tempdir/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 26 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 26 | ▶ | use YAML 'LoadFile'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 26 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 26 | ▶ | use English '-no_match_vars'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 26 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 26 | ▶ | use File::Basename qw/basename dirname/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 26 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 26 | ▶ | use Tapper::Remote::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 26 | ▶ | use Tapper::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | # ABSTRACT: Control running test programs | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 25 | extends 'Tapper::PRC'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 25 | our $MAXREAD = 1024; # read that much in one read | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub capture_handler_tap | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
capture_handler_tap: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 32 | 2 | my $content; | |||||||||||||||||||||||||||
| 33 | 2 | ▶ | open my $fh, '<', $filename or die "Can not open $filename to send captured report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | { local $/; $content = <$fh> } | |||||||||||||||||||||||||||
| 35 | 2 | close $fh; | |||||||||||||||||||||||||||
| 36 | 2 | return $content; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub send_output | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
send_output: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | my ($self, $captured_output, $testprogram) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # add missing minimum Tapper meta information | ||||||||||||||||||||||||||||
| 45 | 2 | my $headerlines = ""; | |||||||||||||||||||||||||||
| 46 | 2 | ▶ | $headerlines .= "# Test-suite-name: ".basename($testprogram->{program})."\n" unless $captured_output =~ /\# (Tapper|Test)-suite-name:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | $headerlines .= "# Test-machine-name: ".$self->cfg->{hostname}."\n" unless $captured_output =~ /\# (Tapper|Test)-machine-name:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $headerlines .= "# Test-reportgroup-testrun: ".$self->cfg->{test_run}."\n" unless $captured_output =~ /\# (Tapper|Test)-reportgroup-testrun:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | $captured_output =~ s/^(1\.\.\d+\n)/$1$headerlines/m; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | my ($error, $message) = $self->tap_report_away($captured_output); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | return $message if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | return 0; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | sub send_attachements { | ||||||||||||||||||||||||||
|
Subroutine
send_attachements: called CC=5 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | my $testplan_id = $self->cfg->{testplan}{id} // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->cfg->{"testplan"}{"id"} // ""
MC/DC0%0/1
$self->cfg->{"testplan"}{"id"} // ""
$self->cfg->{"testplan"}{"id"}
Truth table50%1/2
A
A= $self->cfg->{"testplan"}{"id"}
| |||||||||||||||||||||||||||||
| 65 | my ( $b_error, $s_message ) = $self->tap_report_away( | ||||||||||||||||||||||||||||
| 66 | "TAP version 13\n" | ||||||||||||||||||||||||||||
| 67 | . "1..1\n" | ||||||||||||||||||||||||||||
| 68 | . "# Test-suite-name: PRC" . ( $self->cfg->{guest_number} || 0 ) . "-Attachments\n" | ||||||||||||||||||||||||||||
| 69 | . "# Test-machine-name: " . $self->cfg->{hostname} . "\n" | ||||||||||||||||||||||||||||
| 70 | 2 | ▶ | . "# Test-reportgroup-testrun: " . $self->cfg->{test_run} . "\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->cfg->{'guest_number'} || 0
MC/DC0%0/1
$self->cfg->{'guest_number'} || 0
$self->cfg->{'guest_number'}
Truth table50%1/2
A
A= $self->cfg->{'guest_number'}
| |||||||||||||||||||||||||||||
| 71 | . ( $testplan_id ? "# Test-testplan-id: $testplan_id\n" : '') | ||||||||||||||||||||||||||||
| 72 | . "ok - Test attachments\n" | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return ( 1, $s_message ) if $b_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $self->upload_files( $s_message ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | return ( 0, q## ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub upload_files | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
upload_files: called CC=10 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | my ( $or_self, $i_reportid ) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | my $s_host = $or_self->cfg->{report_server}; | |||||||||||||||||||||||||||
| 90 | 1 | my $i_port = $or_self->cfg->{report_api_port}; | |||||||||||||||||||||||||||
| 91 | 1 | my $s_path = $ENV{TAPPER_OUTPUT_PATH}; | |||||||||||||||||||||||||||
| 92 | 1 | my $i_testrun = $or_self->cfg->{test_run}; | |||||||||||||||||||||||||||
| 93 | 1 | ▶ | my $s_testplan = $or_self->cfg->{testplan}{id} || "none"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$or_self->cfg->{'testplan'}{'id'} || 'none'
MC/DC0%0/1
$or_self->cfg->{'testplan'}{'id'} || 'none'
$or_self->cfg->{'testplan'}{'id'}
Truth table50%1/2
A
A= $or_self->cfg->{'testplan'}{'id'}
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | ▶ | return 0 unless -d $s_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | my @a_files = `find $s_path -type f`; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | $or_self->log->debug( @a_files ); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | my $ostore_endpoint = Tapper::Config->subconfig->{ostore}{endpoint}; | |||||||||||||||||||||||||||
| 102 | 1 | my $ua = LWP::UserAgent->new(); | |||||||||||||||||||||||||||
| 103 | 1 | ▶ | if (defined($ostore_endpoint)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $ostore_endpoint =~ s,/$,,; | |||||||||||||||||||||||||||
| 105 | 0 | $ostore_endpoint .= "/upload"; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | foreach my $s_file( @a_files ) { | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | chomp $s_file; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | my $s_reportfile = $s_file; | |||||||||||||||||||||||||||
| 113 | 1 | $s_reportfile =~ s|^$s_path/*||; | |||||||||||||||||||||||||||
| 114 | #$s_reportfile =~ s|^./||; | ||||||||||||||||||||||||||||
| 115 | #$s_reportfile =~ s|[^A-Za-z0-9_-]|_|g; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | if (defined($ostore_endpoint)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | my $resp = $ua->post( | |||||||||||||||||||||||||||
| 119 | $ostore_endpoint, | ||||||||||||||||||||||||||||
| 120 | "X-Ostore-report" => $i_reportid, | ||||||||||||||||||||||||||||
| 121 | "X-Ostore-testrun" => $i_testrun, | ||||||||||||||||||||||||||||
| 122 | "X-Ostore-testplan" => $s_testplan, | ||||||||||||||||||||||||||||
| 123 | "X-Ostore-suitename" => "PRC0-Attachments", | ||||||||||||||||||||||||||||
| 124 | "X-Ostore-filename" => $s_reportfile, | ||||||||||||||||||||||||||||
| 125 | "X-Ostore-uploadedby" => "tapper-minion-worker", | ||||||||||||||||||||||||||||
| 126 | Content_Type => "form-data", | ||||||||||||||||||||||||||||
| 127 | Content => [ file => [ $s_file ] ], | ||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return "Cannot upload file to object storage at $ostore_endpoint" unless $resp->code == 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 1 | my $or_server = IO::Socket::INET->new( | |||||||||||||||||||||||||||
| 132 | PeerAddr => $s_host, | ||||||||||||||||||||||||||||
| 133 | PeerPort => $i_port, | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | ▶ | return "Cannot open remote receiver $s_host:$i_port" if not $or_server; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | open( my $fh_file, "<", $s_file ) or do{$or_self->log->warn("Can't open $s_file:$!"); $or_server->close();next;}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 1 | $or_server->print("#! upload $i_reportid $s_reportfile plain\n"); | |||||||||||||||||||||||||||
| 140 | 1 | ▶ | while ( my $line = <$fh_file> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 1 | $or_server->print($line); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 1 | close($fh_file); | |||||||||||||||||||||||||||
| 144 | 1 | $or_server->close(); | |||||||||||||||||||||||||||
| 145 | 1 | unlink $s_file; # so we don't upload file again when MCP uploads remaining bits | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | return 0; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 32 | ▶ | sub get_appendix { | ||||||||||||||||||||||||||
|
Subroutine
get_appendix: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 32 | my($self, $output) = @_; | |||||||||||||||||||||||||||
| 155 | 32 | my $appendix = ''; | |||||||||||||||||||||||||||
| 156 | 32 | ▶ | if (-e "$output.stdout" or -e "$output.stderr") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e "$output.stdout" or -e "$output.stderr"
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"
| |||||||||||||||||||||||||||||
| 157 | 12 | my $basename = basename($output); | |||||||||||||||||||||||||||
| 158 | 12 | my $dirname = dirname ($output); | |||||||||||||||||||||||||||
| 159 | 26 | ▶ | my @files = <$dirname/$basename-*.stdout>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 26 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 162 | 12 | my @appendizes = sort map { my ($append) = m/(\d+)\D*$/; $append} @files; | |||||||||||||||||||||||||||
| 163 | 12 | $appendix = sprintf("-%03d",shift(@appendizes) + 1); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 32 | return $appendix; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub kill_process | ||||||||||||||||||||||||||||
| 170 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
kill_process: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 6 | my ($pid) = @_; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | # allow testprogram to react on SIGTERM, then do SIGKILL | ||||||||||||||||||||||||||||
| 174 | 6 | kill ('SIGTERM', $pid); | |||||||||||||||||||||||||||
| 175 | 6 | waitpid $pid, 0; | |||||||||||||||||||||||||||
| 176 | 6 | ▶ | my $grace_period = $ENV{HARNESS_ACTIVE} ? 0 : 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 6 | ▶ | while ( $grace_period > 0 and (kill 0, $pid) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$grace_period > 0 and kill 0, $pid
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
| |||||||||||||||||||||||||||||
| 178 | 0 | $grace_period--; | |||||||||||||||||||||||||||
| 179 | 0 | sleep 1; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 6 | ▶ | if (kill 0, $pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 2 | kill 'SIGKILL', $pid; | |||||||||||||||||||||||||||
| 183 | 2 | waitpid $pid, 0; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | sub get_process_tree | ||||||||||||||||||||||||||||
| 189 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_process_tree: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | 4 | my ($pid) = @_; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 4 | ▶ | return () unless $pid && $pid > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pid and $pid > 1
MC/DC0%0/2
$pid and $pid > 1
$pid
$pid > 1
Truth table33%1/3
A and B
A= $pidB= $pid > 1
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 4 | require Proc::Killfam; | |||||||||||||||||||||||||||
| 195 | 4 | require Proc::ProcessTable; | |||||||||||||||||||||||||||
| 196 | 4 | return Proc::Killfam::get_pids(Proc::ProcessTable->new->table, $pid); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | sub kill_process_tree | ||||||||||||||||||||||||||||
| 201 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
kill_process_tree: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 4 | my ($pid) = @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 4 | ▶ | return unless $pid > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 4 | my @pids = get_process_tree($pid); | |||||||||||||||||||||||||||
| 207 | 4 | kill_process($_) foreach ($pid, @pids); | |||||||||||||||||||||||||||
| 208 | 4 | ▶ | if (@pids) { kill_process_tree($_) foreach @pids } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub testprogram_execute | ||||||||||||||||||||||||||||
| 213 | 23 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
testprogram_execute: called CC=35 SCAR=43.2
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 23 | my ($self, $test_program) = @_; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 23 | my $program = $test_program->{program}; | |||||||||||||||||||||||||||
| 217 | 23 | my $chdir = $test_program->{chdir}; | |||||||||||||||||||||||||||
| 218 | 23 | my $progpath = $self->cfg->{paths}{testprog_path}; | |||||||||||||||||||||||||||
| 219 | 23 | my $output = $program; | |||||||||||||||||||||||||||
| 220 | 23 | $output =~ s|[^A-Za-z0-9_-]|_|g; | |||||||||||||||||||||||||||
| 221 | 23 | $output = $test_program->{out_dir}.$output; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 23 | ▶ | if ($program !~ m(^/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 19 | $ENV{PATH} = "$progpath:$ENV{PATH}"; | |||||||||||||||||||||||||||
| 226 | 19 | $program = qx(which $program); | |||||||||||||||||||||||||||
| 227 | 19 | chomp $program; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # try to catch non executables early | ||||||||||||||||||||||||||||
| 231 | 23 | ▶ | if (-e $program) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 20 | ▶ | if (not -x $program) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | system ("chmod", "ugo+x", $program); | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | return("tried to execute $program which is not an execuable and can not set exec flag") if not -x $program; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 20 | ▶ | return("tried to execute $program which is a directory") if -d $program; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 20 | ▶ | return("tried to execute $program which is a special file (FIFO, socket, device, ..)") unless -f $program or -l $program; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $program or -l $program
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
| |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 23 | ▶ | foreach my $file (@{$test_program->{upload_before} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$test_program->{'upload_before'} || []
MC/DC0%0/1
$test_program->{'upload_before'} || []
$test_program->{'upload_before'}
Truth table50%1/2
A
A= $test_program->{'upload_before'}
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | my $target_name =~ s|[^A-Za-z0-9_-]|_|g; | |||||||||||||||||||||||||||
| 244 | 0 | $target_name = $test_program->{out_dir}.'/before/'.$target_name; | |||||||||||||||||||||||||||
| 245 | 0 | File::Copy::copy($file, $target_name); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 23 | $self->log->info("Try to execute test suite $program"); | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 23 | my $appendix = $self->get_appendix($output); | |||||||||||||||||||||||||||
| 252 | 23 | pipe (my $read, my $write); | |||||||||||||||||||||||||||
| 253 | 23 | ▶ | return ("Can't open pipe:$!") if not (defined $read and defined $write); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $read and defined $write
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
| |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 23 | my $pid=fork(); | |||||||||||||||||||||||||||
| 256 | 23 | ▶ | return( "fork failed: $!" ) if not defined($pid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 23 | ▶ | if ($pid == 0) { # hello child | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 10 | close $read; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 10 | ▶ | %ENV = (%ENV, %{$test_program->{environment} || {} }); | ||||||||||||||||||||||||||
|
Condition50%1/2
$test_program->{'environment'} || {}
MC/DC0%0/1
$test_program->{'environment'} || {}
$test_program->{'environment'}
Truth table50%1/2
A
A= $test_program->{'environment'}
| |||||||||||||||||||||||||||||
| 262 | 10 | ▶ | open (STDOUT, ">", "$output$appendix.stdout") or syswrite($write, "Can't open output file $output$appendix.stdout: $!"),exit 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 10 | ▶ | open (STDERR, ">", "$output$appendix.stderr") or syswrite($write, "Can't open output file $output$appendix.stderr: $!"),exit 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 10 | ▶ | if ($chdir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (-d $chdir) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 266 | 0 | chdir $chdir; | |||||||||||||||||||||||||||
| 267 | ▶ | } elsif ($chdir eq "AUTO" and $program =~ m,^/, ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$chdir eq "AUTO" and $program =~ m[^/]
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[^/]
| |||||||||||||||||||||||||||||
| 268 | 0 | chdir dirname($program); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | 10 | ▶ | exec ($program, @{$test_program->{argv} || []}) or syswrite($write,"$!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$test_program->{'argv'} || []
MC/DC100%1/1
$test_program->{'argv'} || []
$test_program->{'argv'}
Truth table100%2/2
A
A= $test_program->{'argv'}
| |||||||||||||||||||||||||||||
| 272 | 1 | close $write; | |||||||||||||||||||||||||||
| 273 | 1 | exit -1; | |||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # hello parent | ||||||||||||||||||||||||||||
| 277 | 13 | close $write; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 13 | my $killed; | |||||||||||||||||||||||||||
| 280 | my $sig_name; | ||||||||||||||||||||||||||||
| 281 | 2 | ▶ | my $signal_kill = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 282 | 2 | $killed = 1; | |||||||||||||||||||||||||||
| 283 | 2 | ($sig_name) = @_; | |||||||||||||||||||||||||||
| 284 | 2 | $self->log->warn("Catched signal $sig_name"); | |||||||||||||||||||||||||||
| 285 | 2 | kill_process_tree ($pid); | |||||||||||||||||||||||||||
| 286 | 13 | }; | |||||||||||||||||||||||||||
| 287 | 13 | local $SIG{ALRM} = $signal_kill; | |||||||||||||||||||||||||||
| 288 | 13 | local $SIG{TERM} = $signal_kill; | |||||||||||||||||||||||||||
| 289 | 13 | local $SIG{KILL} = $signal_kill; | |||||||||||||||||||||||||||
| 290 | 13 | local $SIG{QUIT} = $signal_kill; | |||||||||||||||||||||||||||
| 291 | 13 | local $SIG{INT} = $signal_kill; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 13 | ▶ | alarm ($test_program->{timeout} || 0); | ||||||||||||||||||||||||||
|
Condition100%2/2
$test_program->{'timeout'} || 0
MC/DC100%1/1
$test_program->{'timeout'} || 0
$test_program->{'timeout'}
Truth table100%2/2
A
A= $test_program->{'timeout'}
| |||||||||||||||||||||||||||||
| 294 | 13 | waitpid($pid,0); | |||||||||||||||||||||||||||
| 295 | 13 | my $retval = $?; | |||||||||||||||||||||||||||
| 296 | 13 | alarm(0); | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 13 | ▶ | foreach my $file (@{$test_program->{upload_after} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$test_program->{'upload_after'} || []
MC/DC0%0/1
$test_program->{'upload_after'} || []
$test_program->{'upload_after'}
Truth table50%1/2
A
A= $test_program->{'upload_after'}
| |||||||||||||||||||||||||||||
| 299 | 0 | my $target_name =~ s|[^A-Za-z0-9_-]|_|g; | |||||||||||||||||||||||||||
| 300 | 0 | $target_name = $test_program->{out_dir}.'/after/'.$target_name; | |||||||||||||||||||||||||||
| 301 | 0 | File::Copy::copy($file, $target_name); | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 13 | ▶ | if ($test_program->{capture}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 2 | my $captured_output; | |||||||||||||||||||||||||||
| 305 | 2 | ▶ | if ( $test_program->{capture} eq 'tap' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 306 | 2 | eval { $captured_output = $self->capture_handler_tap("$output$appendix.stdout")}; | |||||||||||||||||||||||||||
| 307 | 2 | ▶ | return $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | elsif ( $test_program->{capture} eq 'tap-stderr' ) { | ||||||||||||||||||||||||||||
| 310 | 0 | eval { $captured_output = $self->capture_handler_tap("$output$appendix.stderr")}; | |||||||||||||||||||||||||||
| 311 | 0 | ▶ | return $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | else { | ||||||||||||||||||||||||||||
| 314 | 0 | return "Can not handle captured output, unknown capture type '$test_program->{capture}'. Valid types are (tap)"; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | 2 | my ( $b_error, $error_msg ) = $self->send_output($captured_output, $test_program); | |||||||||||||||||||||||||||
| 317 | 2 | ▶ | return $error_msg if $b_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 13 | ▶ | if ($killed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | return | ||||||||||||||||||||||||||||
| 322 | "Killed $program after SIG:$sig_name" | ||||||||||||||||||||||||||||
| 323 | .( | ||||||||||||||||||||||||||||
| 324 | $sig_name eq "ALRM" | ||||||||||||||||||||||||||||
| 325 | 2 | ▶ | ? " (timeout ".$test_program->{timeout}." seconds)" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | : "" | ||||||||||||||||||||||||||||
| 327 | ); | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 11 | ▶ | if ( $retval ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 3 | my $error; | |||||||||||||||||||||||||||
| 332 | 3 | sysread($read,$error, $MAXREAD); | |||||||||||||||||||||||||||
| 333 | 3 | $error =~ s/[\r\n]//g; | |||||||||||||||||||||||||||
| 334 | 3 | return("Executing $program failed:$error"); | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 8 | return 0; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | sub guest_start | ||||||||||||||||||||||||||||
| 342 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
guest_start: called CC=15 SCAR=38.2
Pod
documented
| |||||||||||||||||||||||||||||
| 343 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 344 | 1 | my ($error, $retval); | |||||||||||||||||||||||||||
| 345 | GUEST: | ||||||||||||||||||||||||||||
| 346 | 1 | ▶ | for (my $i=0; $i<=$#{$self->cfg->{guests}}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 2 | my $guest = $self->cfg->{guests}->[$i]; | |||||||||||||||||||||||||||
| 348 | 2 | ▶ | if ($guest->{exec}){ | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 349 | 0 | my $startscript = $guest->{exec}; | |||||||||||||||||||||||||||
| 350 | 0 | $self->log->info("Try to start virtualisation guest with $startscript"); | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | if (not -s $startscript) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 353 | error => qq(Startscript "$startscript" is empty or does not exist at all)}); | ||||||||||||||||||||||||||||
| 354 | 0 | next GUEST; | |||||||||||||||||||||||||||
| 355 | } else { | ||||||||||||||||||||||||||||
| 356 | # just try to set it executable always | ||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if (not -x $startscript) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | unless (system ("chmod", "ugo+x", $startscript) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 360 | error => | ||||||||||||||||||||||||||||
| 361 | return qq(Unable to set executable bit on "$startscript": $!) | ||||||||||||||||||||||||||||
| 362 | }); | ||||||||||||||||||||||||||||
| 363 | 0 | next GUEST; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if (not system($startscript) == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | $retval = qq(Can't start virtualisation guest using startscript "$startscript"); | |||||||||||||||||||||||||||
| 369 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 370 | error => $retval}); | ||||||||||||||||||||||||||||
| 371 | 0 | next GUEST; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | } elsif ($guest->{svm}){ | ||||||||||||||||||||||||||||
| 374 | 1 | my $xm = `which xm`; chomp $xm; | |||||||||||||||||||||||||||
| 375 | 1 | $self->log->info("Try load Xen guest described in ",$guest->{svm}); | |||||||||||||||||||||||||||
| 376 | 1 | ($error, $retval) = $self->log_and_exec($xm, 'create', $guest->{svm}); | |||||||||||||||||||||||||||
| 377 | 1 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 1 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 379 | error => $retval}); | ||||||||||||||||||||||||||||
| 380 | 1 | next GUEST; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | } elsif ($guest->{xen}) { | ||||||||||||||||||||||||||||
| 383 | 1 | $self->log->info("Try load Xen guest described in ",$guest->{xen}); | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 1 | my $guest_file = $guest->{xen}; | |||||||||||||||||||||||||||
| 386 | 1 | ▶ | if ($guest_file =~ m/^(.+)\.(?:xl|svm)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 1 | $guest_file = $1; | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 1 | my $xm = `which xm`; chomp $xm; | |||||||||||||||||||||||||||
| 391 | 1 | my $xl = `which xl`; chomp $xl; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 1 | ▶ | if ( -e $xl ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 394 | 1 | ($error, $retval) = $self->log_and_exec($xl, 'create', $guest_file.".xl"); | |||||||||||||||||||||||||||
| 395 | 1 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | 1 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 397 | error => $retval}); | ||||||||||||||||||||||||||||
| 398 | 1 | next GUEST; | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | } elsif ( -e $xm ) { | ||||||||||||||||||||||||||||
| 401 | 0 | ($error, $retval) = $self->log_and_exec($xm, 'create', $guest_file.".svm"); | |||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 404 | error => $retval}); | ||||||||||||||||||||||||||||
| 405 | 0 | next GUEST; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | } else { | ||||||||||||||||||||||||||||
| 408 | 0 | $retval = "Can not find both xm and xl."; | |||||||||||||||||||||||||||
| 409 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'error-guest', | |||||||||||||||||||||||||||
| 410 | error => $retval}); | ||||||||||||||||||||||||||||
| 411 | 0 | next GUEST; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | 0 | $self->mcp_send({prc_number => ($i+1), state => 'start-guest'}); | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | 1 | return 0; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | sub create_log | ||||||||||||||||||||||||||||
| 421 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
create_log: called CC=6 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||
| 422 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 423 | 9 | my $testrun = $self->cfg->{test_run}; | |||||||||||||||||||||||||||
| 424 | my $output_dir = ($self->cfg->{test_type} || '') eq 'minion' | ||||||||||||||||||||||||||||
| 425 | ? $self->cfg->{paths}{minion_output_dir} | ||||||||||||||||||||||||||||
| 426 | 9 | ▶ | : $self->cfg->{paths}{output_dir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->cfg->{'test_type'} || ''
MC/DC0%0/1
$self->cfg->{'test_type'} || ''
$self->cfg->{'test_type'}
Truth table50%1/2
A
A= $self->cfg->{'test_type'}
| |||||||||||||||||||||||||||||
| 427 | 9 | my $outdir = "$output_dir/$testrun/test/"; | |||||||||||||||||||||||||||
| 428 | 9 | my ($error, $retval); | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 9 | ▶ | for (my $i = 0; $i <= $#{$self->cfg->{guests}}; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | # guest count starts with 1, arrays start with 0 | ||||||||||||||||||||||||||||
| 432 | 0 | my $guest_number=$i+1; | |||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | # every guest gets its own subdirectory | ||||||||||||||||||||||||||||
| 435 | 0 | my $guestoutdir="$outdir/guest-$guest_number/"; | |||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | $error = $self->makedir($guestoutdir); | |||||||||||||||||||||||||||
| 438 | 0 | ▶ | return $error if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 0 | $self->log_and_exec("touch $guestoutdir/console"); | |||||||||||||||||||||||||||
| 441 | 0 | $self->log_and_exec("chmod 666 $guestoutdir/console"); | |||||||||||||||||||||||||||
| 442 | 0 | ($error, $retval) = $self->log_and_exec("ln -sf $guestoutdir/console /tmp/guest$guest_number.fifo"); | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | return "Can't create guest console file $guestoutdir/console: $retval" if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | 9 | return 0; | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | sub nfs_mount | ||||||||||||||||||||||||||||
| 450 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
nfs_mount: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 451 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 452 | 0 | my ($error, $retval); | |||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 0 | $error = $self->makedir($self->cfg->{paths}{prc_nfs_mountdir}); | |||||||||||||||||||||||||||
| 455 | 0 | ▶ | return $error if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | ($error, $retval) = $self->log_and_exec("mount",$self->cfg->{paths}{prc_nfs_mountdir}); | |||||||||||||||||||||||||||
| 458 | 0 | ▶ | return 0 if not $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | 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}); | |||||||||||||||||||||||||||
| 460 | # report error, but only if not already mounted | ||||||||||||||||||||||||||||
| 461 | 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
Condition0%0/3
$error and not -d $self->cfg->{"paths"}{"prc_nfs_mountdir"} . '/live'
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'
| |||||||||||||||||||||||||||||
| 462 | 0 | return 0; | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | sub control_testprogram | ||||||||||||||||||||||||||||
| 467 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
control_testprogram: called CC=27 SCAR=42.1
Pod
documented
| |||||||||||||||||||||||||||||
| 468 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 12 | $ENV{TAPPER_TESTRUN} = $self->cfg->{test_run}; | |||||||||||||||||||||||||||
| 471 | 12 | $ENV{TAPPER_SERVER} = $self->cfg->{mcp_server}; | |||||||||||||||||||||||||||
| 472 | 12 | $ENV{TAPPER_REPORT_SERVER} = $self->cfg->{report_server}; | |||||||||||||||||||||||||||
| 473 | 12 | $ENV{TAPPER_REPORT_API_PORT} = $self->cfg->{report_api_port}; | |||||||||||||||||||||||||||
| 474 | 12 | $ENV{TAPPER_REPORT_PORT} = $self->cfg->{report_port}; | |||||||||||||||||||||||||||
| 475 | 12 | $ENV{TAPPER_HOSTNAME} = $self->cfg->{hostname}; | |||||||||||||||||||||||||||
| 476 | 12 | ▶ | $ENV{TAPPER_REBOOT_COUNTER} = $self->cfg->{reboot_counter} if $self->cfg->{reboot_counter}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | 12 | ▶ | $ENV{TAPPER_MAX_REBOOT} = $self->cfg->{max_reboot} if $self->cfg->{max_reboot}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | 12 | ▶ | $ENV{TAPPER_GUEST_NUMBER} = $self->cfg->{guest_number} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->cfg->{'guest_number'} || 0
MC/DC0%0/1
$self->cfg->{'guest_number'} || 0
$self->cfg->{'guest_number'}
Truth table50%1/2
A
A= $self->cfg->{'guest_number'}
| |||||||||||||||||||||||||||||
| 479 | 12 | ▶ | $ENV{TAPPER_SYNC_FILE} = $self->cfg->{syncfile} if $self->cfg->{syncfile}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 12 | $ENV{TAPPER_SYNC_PATH} = $self->cfg->{paths}{sync_path}; # if -d ($self->cfg->{paths}{sync_path} || ''); | |||||||||||||||||||||||||||
| 481 | 12 | ▶ | if ($self->{cfg}->{testplan}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | 0 | $ENV{TAPPER_TESTPLAN_ID} = $self->cfg->{testplan}{id}; | |||||||||||||||||||||||||||
| 483 | 0 | $ENV{TAPPER_TESTPLAN_PATH} = $self->cfg->{testplan}{path}; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 12 | ▶ | if (defined $self->cfg->{resources} && ref $self->cfg->{resources} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->cfg->{"resources"} and ref $self->cfg->{"resources"} eq "ARRAY"
MC/DC0%0/2
defined $self->cfg->{"resources"} and ref $self->cfg->{"resources"} eq "ARRAY"
defined $self->cfg->{"resources"}
ref $self->cfg->{"resources"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $self->cfg->{"resources"}B= ref $self->cfg->{"resources"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 487 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 488 | 0 | foreach my $resource (@{$self->cfg->{resources}}) { | |||||||||||||||||||||||||||
| 489 | 0 | $ENV{"TAPPER_RESOURCE_$i"} = $resource; | |||||||||||||||||||||||||||
| 490 | 0 | $i++; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 12 | my $test_run = $self->cfg->{test_run}; | |||||||||||||||||||||||||||
| 495 | my $output_dir = ($self->cfg->{test_type} || '') eq 'minion' | ||||||||||||||||||||||||||||
| 496 | ? $self->cfg->{paths}{minion_output_dir} | ||||||||||||||||||||||||||||
| 497 | 12 | ▶ | : $self->cfg->{paths}{output_dir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->cfg->{'test_type'} || ''
MC/DC0%0/1
$self->cfg->{'test_type'} || ''
$self->cfg->{'test_type'}
Truth table50%1/2
A
A= $self->cfg->{'test_type'}
| |||||||||||||||||||||||||||||
| 498 | 12 | my $out_dir = "$output_dir/$test_run/test/"; | |||||||||||||||||||||||||||
| 499 | 12 | my @testprogram_list; | |||||||||||||||||||||||||||
| 500 | 12 | ▶ | @testprogram_list = @{$self->cfg->{testprogram_list}} if $self->cfg->{testprogram_list}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | # prepend outdir with guest number if we are in virtualisation guest | ||||||||||||||||||||||||||||
| 503 | 12 | ▶ | $out_dir.="guest-".$self->{cfg}->{guest_number}."/" if $self->{cfg}->{guest_number}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 12 | my $error = $self->makedir($out_dir); | |||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | # can't create output directory. Make | ||||||||||||||||||||||||||||
| 508 | 12 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 0 | $self->log->warn($error); | |||||||||||||||||||||||||||
| 510 | 0 | $out_dir = tempdir( CLEANUP => 1 ); | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 12 | $ENV{TAPPER_OUTPUT_PATH} = $out_dir; | |||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 12 | ▶ | if ($self->cfg->{test_program}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | 0 | my $argv; | |||||||||||||||||||||||||||
| 517 | my $environment; | ||||||||||||||||||||||||||||
| 518 | 0 | my $chdir; | |||||||||||||||||||||||||||
| 519 | 0 | ▶ | $argv = $self->cfg->{parameters} if $self->cfg->{parameters}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $environment = $self->cfg->{environment} if $self->cfg->{environment}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | 0 | ▶ | $chdir = $self->cfg->{chdir} if $self->cfg->{chdir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 0 | ▶ | my $timeout = $self->cfg->{timeout_testprogram} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->cfg->{'timeout_testprogram'} || 0
MC/DC0%0/1
$self->cfg->{'timeout_testprogram'} || 0
$self->cfg->{'timeout_testprogram'}
Truth table0%0/2
A
A= $self->cfg->{'timeout_testprogram'}
| |||||||||||||||||||||||||||||
| 523 | 0 | $timeout = int $timeout; | |||||||||||||||||||||||||||
| 524 | 0 | my $runtime = $self->cfg->{runtime}; | |||||||||||||||||||||||||||
| 525 | push (@testprogram_list, {program => $self->cfg->{test_program}, | ||||||||||||||||||||||||||||
| 526 | chdir => $chdir, | ||||||||||||||||||||||||||||
| 527 | parameters => $argv, | ||||||||||||||||||||||||||||
| 528 | environment => $environment, | ||||||||||||||||||||||||||||
| 529 | timeout => $timeout, | ||||||||||||||||||||||||||||
| 530 | runtime => $runtime, | ||||||||||||||||||||||||||||
| 531 | upload_before => $self->cfg->{upload_before}, | ||||||||||||||||||||||||||||
| 532 | upload_after => $self->cfg->{upload_after}, | ||||||||||||||||||||||||||||
| 533 | 0 | }); | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 12 | ▶ | for (my $i=0; $i<=$#testprogram_list; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | 17 | my $testprogram = $testprogram_list[$i]; | |||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 17 | ▶ | $ENV{TAPPER_TS_RUNTIME} = $testprogram->{runtime} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$testprogram->{'runtime'} || 0
MC/DC100%1/1
$testprogram->{'runtime'} || 0
$testprogram->{'runtime'}
Truth table100%2/2
A
A= $testprogram->{'runtime'}
| |||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | # unify differences in program vs. program_list vs. virt | ||||||||||||||||||||||||||||
| 543 | 17 | ▶ | $testprogram->{program} ||= $testprogram->{test_program}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$testprogram->{"program"} ||= $testprogram->{"test_program"}
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"}
| |||||||||||||||||||||||||||||
| 544 | 17 | ▶ | $testprogram->{timeout} ||= $testprogram->{timeout_testprogram}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$testprogram->{"timeout"} ||= $testprogram->{"timeout_testprogram"}
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"}
| |||||||||||||||||||||||||||||
| 545 | 17 | ▶ | $testprogram->{argv} = $testprogram->{parameters} if @{$testprogram->{parameters} || []}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$testprogram->{'parameters'} || []
MC/DC100%1/1
$testprogram->{'parameters'} || []
$testprogram->{'parameters'}
Truth table100%2/2
A
A= $testprogram->{'parameters'}
| |||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | # create hash for testprogram_execute | ||||||||||||||||||||||||||||
| 548 | 17 | ▶ | $testprogram->{timeout} ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$testprogram->{"timeout"} ||= 0
MC/DC0%0/1
$testprogram->{"timeout"} ||= 0
$testprogram->{"timeout"}
Truth table50%1/2
A
A= $testprogram->{"timeout"}
| |||||||||||||||||||||||||||||
| 549 | 17 | $testprogram->{out_dir} = $out_dir; | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 17 | my $retval = $self->testprogram_execute($testprogram); | |||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | 11 | ▶ | if ($retval) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | 3 | my $error_msg = "Error while executing $testprogram->{program}: $retval"; | |||||||||||||||||||||||||||
| 555 | 3 | $self->mcp_inform({testprogram => $i, state => 'error-testprogram', error => $error_msg}); | |||||||||||||||||||||||||||
| 556 | 3 | $self->log->info($error_msg); | |||||||||||||||||||||||||||
| 557 | } else { | ||||||||||||||||||||||||||||
| 558 | 8 | $self->mcp_inform({testprogram => $i , state => 'end-testprogram'}); | |||||||||||||||||||||||||||
| 559 | 8 | $self->log->info("Successfully finished test suite $testprogram->{program}"); | |||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 6 | return(0); | |||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | sub get_peers_from_file | ||||||||||||||||||||||||||||
| 569 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_peers_from_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 570 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 571 | 0 | my $peers; | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | $peers = LoadFile($file); | |||||||||||||||||||||||||||
| 574 | 0 | ▶ | return "Syncfile does not contain a list of host names" if not ref($peers) eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | 0 | my $hostname = $self->cfg->{hostname}; | |||||||||||||||||||||||||||
| 577 | 0 | my %peerhosts; | |||||||||||||||||||||||||||
| 578 | 0 | foreach my $host (@$peers) { | |||||||||||||||||||||||||||
| 579 | 0 | $peerhosts{$host} = 1; | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | 0 | delete $peerhosts{$hostname}; | |||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | return \%peerhosts; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | sub wait_for_sync | ||||||||||||||||||||||||||||
| 588 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
wait_for_sync: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 589 | 0 | my ($self, $syncfile) = @_; | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 0 | my %peerhosts; # easier to delete than from array | |||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 0 | eval { | |||||||||||||||||||||||||||
| 594 | 0 | %peerhosts = %{$self->get_peers_from_file($syncfile)}; | |||||||||||||||||||||||||||
| 595 | }; | ||||||||||||||||||||||||||||
| 596 | 0 | ▶ | return $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 0 | my $hostname = $self->cfg->{hostname}; | |||||||||||||||||||||||||||
| 600 | 0 | my $port = $self->cfg->{sync_port}; | |||||||||||||||||||||||||||
| 601 | 0 | my $sync_srv = IO::Socket::INET->new( LocalPort => $port, Listen => 5, ); | |||||||||||||||||||||||||||
| 602 | 0 | my $select = IO::Select->new($sync_srv); | |||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 0 | $self->log->info("Trying to sync with: ". join(", ",sort keys %peerhosts)); | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 0 | foreach my $host (keys %peerhosts) { | |||||||||||||||||||||||||||
| 607 | 0 | my $remote = IO::Socket::INET->new(PeerPort => $port, PeerAddr => $host,); | |||||||||||||||||||||||||||
| 608 | 0 | ▶ | if ($remote) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 0 | $remote->print($hostname); | |||||||||||||||||||||||||||
| 610 | 0 | $remote->close(); | |||||||||||||||||||||||||||
| 611 | 0 | delete($peerhosts{$host}); | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ($select->can_read(0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 614 | 0 | my $msg_srv = $sync_srv->accept(); | |||||||||||||||||||||||||||
| 615 | 0 | my $remotehost; | |||||||||||||||||||||||||||
| 616 | 0 | $msg_srv->read($remotehost, 2048); # no hostnames are that long, anything longer is wrong and can be ignored | |||||||||||||||||||||||||||
| 617 | 0 | chomp $remotehost; | |||||||||||||||||||||||||||
| 618 | 0 | $msg_srv->close(); | |||||||||||||||||||||||||||
| 619 | 0 | ▶ | if ($peerhosts{$remotehost}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 620 | 0 | delete($peerhosts{$remotehost}); | |||||||||||||||||||||||||||
| 621 | } else { | ||||||||||||||||||||||||||||
| 622 | 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); | |||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | 0 | $self->log->debug("In sync with $host."); | |||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 0 | ▶ | while (%peerhosts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if ($select->can_read()) { # TODO: timeout handling | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | 0 | my $msg_srv = $sync_srv->accept(); | |||||||||||||||||||||||||||
| 632 | 0 | my $remotehost; | |||||||||||||||||||||||||||
| 633 | 0 | $msg_srv->read($remotehost, 2048); # no hostnames are that long, anything longer is wrong and can be ignored | |||||||||||||||||||||||||||
| 634 | 0 | chomp $remotehost; | |||||||||||||||||||||||||||
| 635 | 0 | $msg_srv->close(); | |||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ($peerhosts{$remotehost}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 637 | 0 | delete($peerhosts{$remotehost}); | |||||||||||||||||||||||||||
| 638 | 0 | $self->log->debug("In sync with $remotehost."); | |||||||||||||||||||||||||||
| 639 | } else { | ||||||||||||||||||||||||||||
| 640 | 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); | |||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||
| 642 | } else { | ||||||||||||||||||||||||||||
| 643 | # handle timeout here when can_read() has a timeout eventually | ||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||
| 646 | 0 | return 0; | |||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | sub send_keep_alive_loop | ||||||||||||||||||||||||||||
| 651 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
send_keep_alive_loop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 652 | 0 | my ($self, $sleeptime) = @_; | |||||||||||||||||||||||||||
| 653 | 0 | ▶ | return unless $sleeptime; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 654 | 0 | while (1) { | |||||||||||||||||||||||||||
| 655 | 0 | $self->mcp_inform("keep-alive"); | |||||||||||||||||||||||||||
| 656 | 0 | sleep($sleeptime); | |||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | 0 | return; | |||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | sub run | ||||||||||||||||||||||||||||
| 663 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=19 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||
| 664 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | 9 | my $producer = Tapper::Remote::Config->new(); | |||||||||||||||||||||||||||
| 667 | 9 | my $config = $producer->get_local_data("test-prc0"); | |||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | 9 | $self->cfg($config); | |||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | 9 | $0 = "tapper-prc-testcontrol-".$self->cfg->{test_run}; | |||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | 9 | ▶ | $self->cfg->{reboot_counter} = 0 if not defined($self->cfg->{reboot_counter}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 9 | ▶ | if ($self->cfg->{log_to_file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | 0 | $self->log_to_file('testing'); | |||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | # ignore error | ||||||||||||||||||||||||||||
| 680 | 9 | $self->log_and_exec('ntpdate -s gwo'); | |||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | 9 | ▶ | if ($config->{prc_nfs_server}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if ( my $retval = $self->nfs_mount() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 684 | 0 | $self->log->warn($retval); | |||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 9 | ▶ | if ( my $retval = $self->create_log() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 689 | 0 | $self->log->logdie($retval); | |||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | 9 | ▶ | if ($config->{scenario_id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 693 | 0 | my $syncfile = $config->{paths}{sync_path}."/".$config->{scenario_id}."/syncfile"; | |||||||||||||||||||||||||||
| 694 | 0 | ▶ | if (-e $syncfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 695 | 0 | $self->cfg->{syncfile} = $syncfile; | |||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | 0 | ▶ | if ( my $retval = $self->wait_for_sync($syncfile) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 698 | 0 | $self->log->logdie("Can not sync - $retval"); | |||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | 9 | ▶ | if ($self->{cfg}->{guest_count}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if ( my $retval = $self->guest_start() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 705 | 0 | $self->log->error($retval); | |||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | 9 | ▶ | if ( not $self->cfg->{reboot_counter} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 710 | 8 | $self->mcp_inform({state => 'start-testing'}); | |||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | 9 | ▶ | if ( $self->cfg->{test_program} or $self->cfg->{testprogram_list} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->cfg->{"test_program"} or $self->cfg->{"testprogram_list"}
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"}
| |||||||||||||||||||||||||||||
| 714 | 7 | $self->control_testprogram(); | |||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 4 | ▶ | if ($self->cfg->{max_reboot}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 718 | 2 | $self->mcp_inform({state => 'reboot', count => $self->cfg->{reboot_counter}, max_reboot => $self->cfg->{max_reboot}}); | |||||||||||||||||||||||||||
| 719 | 2 | ▶ | if ($self->cfg->{reboot_counter} < $self->cfg->{max_reboot}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 720 | 2 | $self->cfg->{reboot_counter}++; | |||||||||||||||||||||||||||
| 721 | 2 | ▶ | YAML::Syck::DumpFile($config->{filename}, $self->{cfg}) or $self->mcp_error("Can't write config to file: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 722 | 2 | $self->log_and_exec("reboot"); | |||||||||||||||||||||||||||
| 723 | 2 | return 0; | |||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | # TODO: too cheap work-around | ||||||||||||||||||||||||||||
| 729 | # | ||||||||||||||||||||||||||||
| 730 | # Make sure last end-testing can't overtake last | ||||||||||||||||||||||||||||
| 731 | # end-testprogram (Yes, this did happen). | ||||||||||||||||||||||||||||
| 732 | # | ||||||||||||||||||||||||||||
| 733 | # Wait at least as long as the MCP loop time is, see | ||||||||||||||||||||||||||||
| 734 | # tapper.cfg: | ||||||||||||||||||||||||||||
| 735 | # - mcp.child.get_message_sleep_interval | ||||||||||||||||||||||||||||
| 736 | # - times.poll_intervall | ||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 2 | ▶ | sleep ($ENV{HARNESS_ACTIVE} ? 1 : 10); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | # send attachment report | ||||||||||||||||||||||||||||
| 742 | 2 | my ( $b_error, $s_error_msg ) = $self->send_attachements(); | |||||||||||||||||||||||||||
| 743 | 2 | ▶ | if ( $b_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 744 | 2 | $self->log->error( $s_error_msg ); | |||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | 2 | $self->mcp_inform({state => 'end-testing'}); | |||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | 2 | return 1; | |||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | 25 | 1; | |||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | __END__ | ||||||||||||||||||||||||||||