| 1 | ## no critic (RequireUseStrict) | ||||||||||||||||||||||||||||
| 2 | package Tapper::TestSuite::HWTrack::Execute; | ||||||||||||||||||||||||||||
| 3 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | $Tapper::TestSuite::HWTrack::Execute::AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||
| 6 | { | ||||||||||||||||||||||||||||
| 7 | 1 | $Tapper::TestSuite::HWTrack::Execute::VERSION = '4.1.1'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Support package for Tapper::TestSuite::HWTrack | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Temp 'tempfile'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use YAML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | has dst => ( is => 'rw'); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub generate { | ||||||||||||||||||||||||||
|
Subroutine
generate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my (undef, $file) = tempfile( CLEANUP => 1 ); | |||||||||||||||||||||||||||
| 28 | 0 | my $lshw = "lshw"; | |||||||||||||||||||||||||||
| 29 | 0 | my $exec = "$lshw -xml > $file"; | |||||||||||||||||||||||||||
| 30 | 0 | system($exec); # can't use Tapper::Base->log_and_exec since | |||||||||||||||||||||||||||
| 31 | # this puts STDERR into the resulting XML file | ||||||||||||||||||||||||||||
| 32 | # which in turn becomes invalid XML | ||||||||||||||||||||||||||||
| 33 | 0 | return $self->gen_report($file); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub gen_report { | ||||||||||||||||||||||||||
|
Subroutine
gen_report: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $test_run = $ENV{TAPPER_TESTRUN}; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $hostname = $ENV{TAPPER_HOSTNAME} || Sys::Hostname::hostname(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'TAPPER_HOSTNAME'} || Sys::Hostname::hostname()
MC/DC0%0/2
$ENV{'TAPPER_HOSTNAME'} || Sys::Hostname::hostname()
$ENV{'TAPPER_HOSTNAME'}
Sys::Hostname::hostname()
Truth table0%0/3
A || B
A= $ENV{'TAPPER_HOSTNAME'}B= Sys::Hostname::hostname()
| |||||||||||||||||||||||||||||
| 42 | 0 | my $xml = XML::Simple->new(ForceArray => 1); | |||||||||||||||||||||||||||
| 43 | 0 | my $data = $xml->XMLin($file); | |||||||||||||||||||||||||||
| 44 | 0 | my $yaml = Dump($data); | |||||||||||||||||||||||||||
| 45 | 0 | $yaml .= "...\n"; | |||||||||||||||||||||||||||
| 46 | 0 | $yaml =~ s/^(.*)$/ $1/mg; # indent | |||||||||||||||||||||||||||
| 47 | 0 | my $report = sprintf(" | |||||||||||||||||||||||||||
| 48 | TAP Version 13 | ||||||||||||||||||||||||||||
| 49 | 1..2 | ||||||||||||||||||||||||||||
| 50 | # Tapper-Reportgroup-Testrun: %s | ||||||||||||||||||||||||||||
| 51 | # Tapper-Suite-Name: HWTrack | ||||||||||||||||||||||||||||
| 52 | # Tapper-Machine-Name: %s | ||||||||||||||||||||||||||||
| 53 | # Tapper-Suite-Version: %s | ||||||||||||||||||||||||||||
| 54 | ok 1 - Getting hardware information | ||||||||||||||||||||||||||||
| 55 | %s | ||||||||||||||||||||||||||||
| 56 | ok 2 - Sending | ||||||||||||||||||||||||||||
| 57 | ", $test_run, $hostname, $Tapper::TestSuite::HWTrack::VERSION, $yaml); | ||||||||||||||||||||||||||||
| 58 | 0 | return $report; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self, $report) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $cfg; | |||||||||||||||||||||||||||
| 67 | 0 | $cfg->{report_server} = $ENV{TAPPER_REPORT_SERVER}; | |||||||||||||||||||||||||||
| 68 | 0 | $cfg->{report_api_port} = $ENV{TAPPER_REPORT_API_PORT}; | |||||||||||||||||||||||||||
| 69 | 0 | $cfg->{report_port} = $ENV{TAPPER_REPORT_PORT}; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | print STDERR "host:port = ".$cfg->{report_server}.":".$cfg->{report_port}; | |||||||||||||||||||||||||||
| 72 | # following options are not yet used in this class | ||||||||||||||||||||||||||||
| 73 | 0 | $cfg->{mcp_server} = $ENV{TAPPER_SERVER}; | |||||||||||||||||||||||||||
| 74 | 0 | $cfg->{runtime} = $ENV{TAPPER_TS_RUNTIME}; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $sock = IO::Socket::INET->new(PeerAddr => $cfg->{report_server}, | ||||||||||||||||||||||||||||
| 77 | PeerPort => $cfg->{report_port}, | ||||||||||||||||||||||||||||
| 78 | 0 | Proto => 'tcp'); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | unless ($sock) { die "Can't open connection to ", $cfg->{report_server}, ":", $cfg->{report_port}, ": $!" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | my $select = IO::Select->new(); | |||||||||||||||||||||||||||
| 81 | 0 | $select->add($sock); | |||||||||||||||||||||||||||
| 82 | 0 | my $remaining = length($report); | |||||||||||||||||||||||||||
| 83 | 0 | say STDERR "\n$remaining"; | |||||||||||||||||||||||||||
| 84 | 0 | my $offset = 0; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | while ($remaining and $select->can_write()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$remaining and $select->can_write
MC/DC0%0/2
$remaining and $select->can_write
$remaining
$select->can_write
Truth table0%0/3
A and B
A= $remainingB= $select->can_write
| |||||||||||||||||||||||||||||
| 86 | 0 | my $written = syswrite($sock, $report, 1024, $offset); | |||||||||||||||||||||||||||
| 87 | 0 | $remaining -= $written; | |||||||||||||||||||||||||||
| 88 | 0 | $offset += $written; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | sleep 2; | |||||||||||||||||||||||||||
| 91 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 92 | 0 | return 0; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | 1; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||