| 1 | package Tapper::SimNow; | ||||||||||||||
| 2 | # git description: v4.1.0-1-gefbd11b | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | $Tapper::SimNow::AUTHORITY = 'cpan:TAPPER'; | |||||||||||||
| 6 | } | ||||||||||||||
| 7 | { | ||||||||||||||
| 8 | 2 | $Tapper::SimNow::VERSION = '4.1.1'; | |||||||||||||
| 9 | } | ||||||||||||||
| 10 | # ABSTRACT: Tapper - Support for running SimNow sessions | ||||||||||||||
| 11 | |||||||||||||||
| 12 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 2 | ▶ | use common::sense; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 2 | ▶ | use File::Basename; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 2 | ▶ | use Tapper::Remote::Config; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 2 | ▶ | use Tapper::Remote::Net; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 2 | extends 'Tapper::Base'; | |||||||||||||
| 21 | |||||||||||||||
| 22 | has cfg => (is => 'rw', | ||||||||||||||
| 23 | isa => 'HashRef', | ||||||||||||||
| 24 | 0 | ▶ | default => sub { {} }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 25 | 2 | ); | |||||||||||||
| 26 | |||||||||||||||
| 27 | |||||||||||||||
| 28 | |||||||||||||||
| 29 | sub get_static_tap_headers | ||||||||||||||
| 30 | 1 | ▶ | { | ||||||||||||
|
Subroutine
get_static_tap_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 31 | 1 | my ($self, $report) = @_; | |||||||||||||
| 32 | 1 | $report->{headers}{'Tapper-reportgroup-testrun'} = $self->cfg->{test_run}; | |||||||||||||
| 33 | 1 | $report->{headers}{'Tapper-suite-name'} = "SimNow-Metainfo"; | |||||||||||||
| 34 | 1 | $report->{headers}{'Tapper-suite-version'} = $Tapper::SimNow::VERSION; | |||||||||||||
| 35 | 1 | $report->{headers}{'Tapper-machine-name'} = $self->cfg->{hostname}; | |||||||||||||
| 36 | 1 | return $report; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | |||||||||||||||
| 40 | sub generate_meta_report | ||||||||||||||
| 41 | 1 | ▶ | { | ||||||||||||
|
Subroutine
generate_meta_report: called CC=9 SCAR=25.0
Pod
documented
| |||||||||||||||
| 42 | |||||||||||||||
| 43 | 1 | my ($self) = @_; | |||||||||||||
| 44 | 1 | my $report; | |||||||||||||
| 45 | 1 | $report = $self->get_static_tap_headers($report); | |||||||||||||
| 46 | |||||||||||||||
| 47 | 1 | my $error = 0; | |||||||||||||
| 48 | 1 | my ($success, $retval) = $self->log_and_exec($self->cfg->{paths}->{simnow_path}."/simnow","--version"); | |||||||||||||
| 49 | 1 | ▶ | if ($success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | push @{$report->{tests}}, {error => 1, test => "Getting SimNow version"}; | |||||||||||||
| 51 | } else { | ||||||||||||||
| 52 | 1 | push @{$report->{tests}}, {test => "Getting SimNow version"}; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 1 | ▶ | if ($retval =~ m/This is AMD SimNow version (\d+\.\d+\.\d+(-NDA)?)/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 1 | $report->{headers}{'Tapper-SimNow-Version'} = $1; | |||||||||||||
| 56 | } else { | ||||||||||||||
| 57 | 0 | $report->{headers}{'Tapper-SimNow-Version'} = 'Not set'; | |||||||||||||
| 58 | 0 | $error = 1; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | 1 | push @{$report->{tests}}, {error => $error, test => "Parsing SimNow version"}; | |||||||||||||
| 61 | |||||||||||||||
| 62 | |||||||||||||||
| 63 | 1 | $error = 0; | |||||||||||||
| 64 | 1 | ▶ | if ($retval =~ m/This internal release is built from revision: (.+) of SVN URL: (.+)/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 65 | 1 | $report->{headers}{'Tapper-SimNow-SVN-Version'} = $1; | |||||||||||||
| 66 | 1 | $report->{headers}{'Tapper-SimNow-SVN-Repository'} = $2; | |||||||||||||
| 67 | } elsif ($retval =~ m/Build number: (.+)/) { | ||||||||||||||
| 68 | 0 | $report->{headers}{'Tapper-SimNow-SVN-Version'} = $1; | |||||||||||||
| 69 | 0 | $report->{headers}{'Tapper-SimNow-SVN-Repository'} = 'Not set'; | |||||||||||||
| 70 | } else { | ||||||||||||||
| 71 | 0 | $report->{headers}{'Tapper-SimNow-SVN-Version'} = 'Not set'; | |||||||||||||
| 72 | 0 | $report->{headers}{'Tapper-SimNow-SVN-Repository'} = 'Not set'; | |||||||||||||
| 73 | 0 | $error = 1; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | 1 | push @{$report->{tests}}, {error => $error, test => "Parsing SVN version"}; | |||||||||||||
| 76 | |||||||||||||||
| 77 | 1 | $error = 0; | |||||||||||||
| 78 | 1 | ▶ | if ($retval =~ m/supporting version (\d+) of the AMD SimNow Device Interface/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | 1 | $report->{headers}{'Tapper-SimNow-Device-Interface-Version'} = $1; | |||||||||||||
| 80 | } else { | ||||||||||||||
| 81 | 0 | $report->{headers}{'Tapper-SimNow-Device-Interface-Version'} = 'Not set'; | |||||||||||||
| 82 | 0 | $error = 1; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | 1 | push @{$report->{tests}}, {error => $error, test => "Parsing device interface version"}; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 1 | $error = 0; | |||||||||||||
| 88 | 1 | ▶ | if (open my $fh ,"<", $self->cfg->{files}{simnow_script}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 1 | my $content = do {local $/; <$fh>}; | |||||||||||||
| 90 | 1 | close $fh; | |||||||||||||
| 91 | |||||||||||||||
| 92 | 1 | ▶ | if ($content =~ m|open bsds/(\w+)\.bsd|) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | 0 | $report->{headers}{'Tapper-SimNow-BSD-File'} = $1; | |||||||||||||
| 94 | } else { | ||||||||||||||
| 95 | 1 | $error = 1; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | 1 | push @{$report->{tests}}, {error => $error, test => "Getting BSD file information"}; | |||||||||||||
| 98 | |||||||||||||||
| 99 | 1 | $error = 0; | |||||||||||||
| 100 | 1 | ▶ | if ($content =~ m|ide:0.image master .*/((?:\w\|\.)+?)(?:\.[a-zA-Z]+)?$|m) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 101 | 0 | $report->{headers}{'Tapper-SimNow-Image-File'} = $1; | |||||||||||||
| 102 | } else { | ||||||||||||||
| 103 | 1 | $error = 1; | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | 1 | push @{$report->{tests}}, {error => $error, test => "Getting image file information"}; | |||||||||||||
| 106 | |||||||||||||||
| 107 | 1 | $error = 0; | |||||||||||||
| 108 | } else { | ||||||||||||||
| 109 | 0 | $report->{headers}{'Tapper-SimNow-BSD-File'} = 'Not set'; | |||||||||||||
| 110 | 0 | $report->{headers}{'Tapper-SimNow-Image-File'} = 'Not set'; | |||||||||||||
| 111 | 0 | $error = 1; | |||||||||||||
| 112 | } | ||||||||||||||
| 113 | 1 | push @{$report->{tests}}, {error => $error, test => "Reading Simnow config file"}; | |||||||||||||
| 114 | 1 | return $report; | |||||||||||||
| 115 | |||||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | |||||||||||||||
| 119 | |||||||||||||||
| 120 | |||||||||||||||
| 121 | sub create_console | ||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||
|
Subroutine
create_console: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 123 | 0 | my ($self) = @_; | |||||||||||||
| 124 | 0 | $self->log->debug("Creating console links"); | |||||||||||||
| 125 | 0 | my $test_run = $self->cfg->{test_run}; | |||||||||||||
| 126 | 0 | my $out_dir = $self->cfg->{paths}{output_dir}."/$test_run/test/"; | |||||||||||||
| 127 | 0 | ▶ | $self->makedir($out_dir) unless -d $out_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | 0 | my $outfile = $out_dir."/simnow_console"; | |||||||||||||
| 129 | |||||||||||||||
| 130 | # create the file, otherwise simnow can't write to it | ||||||||||||||
| 131 | 0 | ▶ | open my $fh, ">", $outfile or return "Can not open $outfile: $!"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 132 | 0 | close $fh; | |||||||||||||
| 133 | |||||||||||||||
| 134 | 0 | my $pipedir = dirname($self->cfg->{files}{simnow_console}); | |||||||||||||
| 135 | 0 | ▶ | $self->makedir($pipedir) unless -d $pipedir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 136 | 0 | my $retval = $self->log_and_exec("ln","-sf", $outfile, $self->cfg->{files}{simnow_console}); | |||||||||||||
| 137 | 0 | return $retval; | |||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | |||||||||||||||
| 141 | |||||||||||||||
| 142 | sub start_simnow | ||||||||||||||
| 143 | 0 | ▶ | { | ||||||||||||
|
Subroutine
start_simnow: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 144 | 0 | my ($self) = @_; | |||||||||||||
| 145 | 0 | $self->log->debug("starting simnow"); | |||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | my $simnow_script = $self->cfg->{files}{simnow_script}; | |||||||||||||
| 148 | 0 | my $test_run = $self->cfg->{test_run}; | |||||||||||||
| 149 | 0 | my $out_dir = $self->cfg->{paths}{output_dir}."/$test_run/test/"; | |||||||||||||
| 150 | 0 | ▶ | $self->makedir($out_dir) unless -d $out_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 151 | 0 | my $output = $out_dir.'/simnow'; | |||||||||||||
| 152 | |||||||||||||||
| 153 | 0 | ▶ | open (STDOUT, ">>", "$output.stdout") or return("Can't open output file $output.stdout: $!"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 154 | 0 | ▶ | open (STDERR, ">>", "$output.stderr") or return("Can't open output file $output.stderr: $!"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 155 | |||||||||||||||
| 156 | my $retval = $self->run_one({command => $self->cfg->{paths}->{simnow_path}."/simnow", | ||||||||||||||
| 157 | argv => [ "-e", $simnow_script, '--nogui' ], | ||||||||||||||
| 158 | 0 | pid_file => $self->cfg->{paths}->{pids_path}."/simnow.pid", | |||||||||||||
| 159 | }); | ||||||||||||||
| 160 | 0 | return $retval; | |||||||||||||
| 161 | } | ||||||||||||||
| 162 | |||||||||||||||
| 163 | |||||||||||||||
| 164 | |||||||||||||||
| 165 | sub start_mediator | ||||||||||||||
| 166 | 0 | ▶ | { | ||||||||||||
|
Subroutine
start_mediator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 167 | 0 | my ($self) = @_; | |||||||||||||
| 168 | 0 | $self->log->debug("starting mediator"); | |||||||||||||
| 169 | |||||||||||||||
| 170 | my $retval = $self->run_one({command => $self->cfg->{paths}->{simnow_path}."/mediator", | ||||||||||||||
| 171 | 0 | pid_file => $self->cfg->{paths}->{pids_path}."/mediator.pid", | |||||||||||||
| 172 | }); | ||||||||||||||
| 173 | 0 | return $retval; | |||||||||||||
| 174 | } | ||||||||||||||
| 175 | |||||||||||||||
| 176 | |||||||||||||||
| 177 | |||||||||||||||
| 178 | |||||||||||||||
| 179 | sub run | ||||||||||||||
| 180 | 0 | ▶ | { | ||||||||||||
|
Subroutine
run: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||
| 181 | 0 | my ($self) = @_; | |||||||||||||
| 182 | 0 | $self->log->info("Starting Simnow"); | |||||||||||||
| 183 | |||||||||||||||
| 184 | 0 | my $consumer = Tapper::Remote::Config->new(); | |||||||||||||
| 185 | 0 | my $config = $consumer->get_local_data('simnow'); | |||||||||||||
| 186 | 0 | ▶ | die $config unless ref($config) eq 'HASH'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 187 | 0 | my $net = Tapper::Remote::Net->new($config); | |||||||||||||
| 188 | 0 | $self->cfg( $config ); | |||||||||||||
| 189 | 0 | $net->mcp_inform("start-test"); | |||||||||||||
| 190 | |||||||||||||||
| 191 | # simnow only runs in its own directory due to lib issues | ||||||||||||||
| 192 | 0 | chdir $self->cfg->{paths}->{simnow_path}; | |||||||||||||
| 193 | |||||||||||||||
| 194 | 0 | my $retval; | |||||||||||||
| 195 | { | ||||||||||||||
| 196 | 0 | $retval = $self->kill_instance($self->cfg->{paths}->{pids_path}."/simnow.pid"); | |||||||||||||
| 197 | 0 | ▶ | last if $retval; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | |||||||||||||||
| 199 | 0 | $retval = $self->create_console(); | |||||||||||||
| 200 | 0 | ▶ | last if $retval; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 201 | |||||||||||||||
| 202 | |||||||||||||||
| 203 | 0 | $retval = $self->start_mediator(); | |||||||||||||
| 204 | 0 | ▶ | last if $retval; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 205 | |||||||||||||||
| 206 | 0 | $retval = $self->start_simnow(); | |||||||||||||
| 207 | 0 | ▶ | last if $retval; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 208 | |||||||||||||||
| 209 | 0 | my $report = $self->generate_meta_report(); | |||||||||||||
| 210 | 0 | my $tap = $net->tap_report_create($report); | |||||||||||||
| 211 | 0 | my $error; | |||||||||||||
| 212 | 0 | ($error, $retval) = $net->tap_report_away($tap); | |||||||||||||
| 213 | 0 | ▶ | last if $error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 214 | |||||||||||||||
| 215 | } | ||||||||||||||
| 216 | 0 | ▶ | if ($retval) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 217 | 0 | $net->mcp_send({state => 'error-guest', error => $retval}); | |||||||||||||
| 218 | 0 | $self->log->logdie($retval); | |||||||||||||
| 219 | } | ||||||||||||||
| 220 | 0 | $net->mcp_inform("end-test"); | |||||||||||||
| 221 | |||||||||||||||
| 222 | 0 | $self->log->info("Simnow prepared and running"); | |||||||||||||
| 223 | 0 | return 0; | |||||||||||||
| 224 | } | ||||||||||||||
| 225 | |||||||||||||||
| 226 | 2 | 1; # End of Tapper::SimNow | |||||||||||||
| 227 | |||||||||||||||
| 228 | __END__ | ||||||||||||||