| 1 | package Tapper::MCP::Net::TAP; | ||||||||||||||||||||
| 2 | 29 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 29 | $Tapper::MCP::Net::TAP::VERSION = '5.0.9'; | |||||||||||||||||||
| 4 | 29 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 29 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 29 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 29 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 29 | requires 'testrun', 'cfg', 'log'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | sub prc_headerlines { | ||||||||||||||||||
|
Subroutine
prc_headerlines: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 14 | 0 | my ($self, $prc_number) = @_; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | my $hostname = $self->associated_hostname; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | my $testrun_id = $self->testrun->id; | |||||||||||||||||||
| 19 | 0 | ▶ | my $testplan_id = $self->cfg->{testplan}{id} // ''; | ||||||||||||||||||
|
Condition0%0/2
$self->cfg->{"testplan"}{"id"} // ""
MC/DC0%0/1
$self->cfg->{"testplan"}{"id"} // ""
$self->cfg->{"testplan"}{"id"}
Truth table0%0/2
A
A= $self->cfg->{"testplan"}{"id"}
| |||||||||||||||||||||
| 20 | 0 | ▶ | my $suitename = ($prc_number > 0) ? "Guest-Overview-$prc_number" : "PRC0-Overview"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | my $headerlines = [ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | "# Test-reportgroup-testrun: $testrun_id", | ||||||||||||||||||||
| 24 | ( $testplan_id ? "# Test-testplan-id: $testplan_id" : ()), | ||||||||||||||||||||
| 25 | "# Test-suite-name: $suitename", | ||||||||||||||||||||
| 26 | "# Test-suite-version: $Tapper::MCP::VERSION", | ||||||||||||||||||||
| 27 | "# Test-machine-name: $hostname", | ||||||||||||||||||||
| 28 | "# Test-section: prc-state-details", | ||||||||||||||||||||
| 29 | "# Test-reportgroup-primary: 0", | ||||||||||||||||||||
| 30 | ]; | ||||||||||||||||||||
| 31 | 0 | return $headerlines; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | sub tap_report_away | ||||||||||||||||||||
| 37 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
tap_report_away: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 38 | 0 | my ($self, $tap) = @_; | |||||||||||||||||||
| 39 | 0 | my $reportid; | |||||||||||||||||||
| 40 | 0 | ▶ | if (my $sock = IO::Socket::INET->new(PeerAddr => $self->cfg->{report_server}, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | PeerPort => $self->cfg->{report_port}, | ||||||||||||||||||||
| 42 | Proto => 'tcp')) { | ||||||||||||||||||||
| 43 | 0 | eval{ | |||||||||||||||||||
| 44 | 0 | my $timeout = 100; | |||||||||||||||||||
| 45 | 0 | ▶ | local $SIG{ALRM}=sub{die("timeout for sending tap report ($timeout seconds) reached.");}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 46 | 0 | alarm($timeout); | |||||||||||||||||||
| 47 | 0 | ($reportid) = <$sock> =~m/(\d+)$/g; | |||||||||||||||||||
| 48 | 0 | $sock->print($tap); | |||||||||||||||||||
| 49 | }; | ||||||||||||||||||||
| 50 | 0 | alarm(0); | |||||||||||||||||||
| 51 | 0 | ▶ | $self->log->error($@) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | close $sock; | |||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||
| 54 | 0 | return(1,"Can not connect to report server: $!"); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 0 | return (0,$reportid); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub tap_report_send | ||||||||||||||||||||
| 62 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
tap_report_send: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | 6 | my ($self, $reportlines, $headerlines) = @_; | |||||||||||||||||||
| 64 | 6 | my $tap = $self->tap_report_create($reportlines, $headerlines); | |||||||||||||||||||
| 65 | 6 | $self->log->debug($tap); | |||||||||||||||||||
| 66 | 6 | return $self->tap_report_away($tap); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | sub associated_hostname | ||||||||||||||||||||
| 71 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
associated_hostname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 72 | 6 | my ($self) = @_; | |||||||||||||||||||
| 73 | 6 | my $hostname; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 6 | eval { | |||||||||||||||||||
| 76 | # parts of this chain may not exists and thus thow an exception | ||||||||||||||||||||
| 77 | 6 | $hostname = $self->testrun->testrun_scheduling->host->name; | |||||||||||||||||||
| 78 | }; | ||||||||||||||||||||
| 79 | 6 | ▶ | return ($hostname // 'No hostname set'); | ||||||||||||||||||
|
Condition100%2/2
$hostname // "No hostname set"
MC/DC100%1/1
$hostname // "No hostname set"
$hostname
Truth table100%2/2
A
A= $hostname
| |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 6 | ▶ | sub mcp_headerlines { | ||||||||||||||||||
|
Subroutine
mcp_headerlines: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||
| 85 | 6 | my ($self) = @_; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 6 | ▶ | my $topic = $self->testrun->topic_name() || $self->testrun->shortname(); | ||||||||||||||||||
|
Condition33%1/3
$self->testrun->topic_name || $self->testrun->shortname
MC/DC0%0/2
$self->testrun->topic_name || $self->testrun->shortname
$self->testrun->topic_name
$self->testrun->shortname
Truth table33%1/3
A || B
A= $self->testrun->topic_nameB= $self->testrun->shortname
| |||||||||||||||||||||
| 88 | 6 | $topic =~ s/\s+/-/g; | |||||||||||||||||||
| 89 | 6 | my $hostname = $self->associated_hostname(); | |||||||||||||||||||
| 90 | 6 | my $testrun_id = $self->testrun->id; | |||||||||||||||||||
| 91 | 6 | ▶ | 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"}
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 6 | ▶ | my $headerlines = [ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | "# Test-reportgroup-testrun: $testrun_id", | ||||||||||||||||||||
| 95 | ( $testplan_id ? "# Test-testplan-id: $testplan_id" : ()), | ||||||||||||||||||||
| 96 | "# Test-suite-name: Topic-$topic", | ||||||||||||||||||||
| 97 | "# Test-suite-version: $Tapper::MCP::VERSION", | ||||||||||||||||||||
| 98 | "# Test-machine-name: $hostname", | ||||||||||||||||||||
| 99 | "# Test-section: MCP overview", | ||||||||||||||||||||
| 100 | "# Test-reportgroup-primary: 1", | ||||||||||||||||||||
| 101 | ]; | ||||||||||||||||||||
| 102 | 6 | return $headerlines; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | sub tap_report_create | ||||||||||||||||||||
| 107 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
tap_report_create: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 108 | 6 | my ($self, $reportlines, $headerlines) = @_; | |||||||||||||||||||
| 109 | 6 | my @reportlines = @$reportlines; | |||||||||||||||||||
| 110 | 6 | my $message; | |||||||||||||||||||
| 111 | 6 | $message .= "1..".($#reportlines+1)."\n"; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 6 | foreach my $line (map { chomp; $_ } @$headerlines) { | |||||||||||||||||||
| 114 | 36 | $message .= "$line\n"; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | # @reportlines starts with 0, reports start with 1 | ||||||||||||||||||||
| 118 | 6 | ▶ | for (my $i=1; $i<=$#reportlines+1; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 7 | ▶ | $message .= "not " if $reportlines[$i-1]->{error}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 7 | $message .="ok $i - "; | |||||||||||||||||||
| 121 | 7 | ▶ | $message .= $reportlines[$i-1]->{msg} if $reportlines[$i-1]->{msg}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 7 | $message .="\n"; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | $message .= "# ".$reportlines[$i-1]->{comment}."\n" | ||||||||||||||||||||
| 125 | 7 | ▶ | if $reportlines[$i-1]->{comment}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | 6 | return ($message); | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | sub upload_files | ||||||||||||||||||||
| 133 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
upload_files: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||
| 134 | 6 | my ($self, $reportid, $testrunid) = @_; | |||||||||||||||||||
| 135 | 6 | my $host = $self->cfg->{report_server}; | |||||||||||||||||||
| 136 | 6 | my $port = $self->cfg->{report_api_port}; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 6 | my $outputdir = $self->cfg->{paths}{output_dir}; | |||||||||||||||||||
| 139 | 6 | my $path = "$outputdir/$testrunid/"; | |||||||||||||||||||
| 140 | 6 | ▶ | return 0 unless -d $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | 1 | my @files=`find $path -type f`; | |||||||||||||||||||
| 142 | 1 | $self->log->debug(@files); | |||||||||||||||||||
| 143 | 1 | foreach my $file(@files) { | |||||||||||||||||||
| 144 | 1 | chomp $file; | |||||||||||||||||||
| 145 | 1 | my $reportfile=$file; | |||||||||||||||||||
| 146 | 1 | $reportfile =~ s|^$path||; | |||||||||||||||||||
| 147 | #$reportfile =~ s|^./||; | ||||||||||||||||||||
| 148 | #$reportfile =~ s|[^A-Za-z0-9_-]|_|g; | ||||||||||||||||||||
| 149 | 1 | my $cmdline = "#! upload $reportid "; | |||||||||||||||||||
| 150 | 1 | $cmdline .= $reportfile; | |||||||||||||||||||
| 151 | 1 | $cmdline .= " plain\n"; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 1 | my $server = IO::Socket::INET->new(PeerAddr => $host, | |||||||||||||||||||
| 154 | PeerPort => $port); | ||||||||||||||||||||
| 155 | 1 | ▶ | return "Cannot open remote receiver $host:$port" if not $server; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | ▶ | open(my $FH, "<",$file) or do{$self->log->warn("Can't open $file:$!"); $server->close();next;}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 1 | $server->print($cmdline); | |||||||||||||||||||
| 159 | 1 | ▶ | while (my $line = <$FH>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 160 | 1 | $server->print($line); | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | 1 | close($FH); | |||||||||||||||||||
| 163 | 1 | $server->close(); | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | 1 | system(qq{find "$outputdir" -maxdepth 1 -type d -mtime +30 -exec rm -fr \\{\\} \\;}); | |||||||||||||||||||
| 166 | 1 | return 0; | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 29 | 1; | |||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | __END__ | ||||||||||||||||||||