| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Remote::Net; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
2
|
|
|
2
|
|
714716
|
$Tapper::Remote::Net::AUTHORITY = 'cpan:TAPPER'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$Tapper::Remote::Net::VERSION = '4.1.1'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
23
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
71
|
|
|
10
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
65
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
3982
|
use Moose::Role; |
|
|
2
|
|
|
|
|
9986
|
|
|
|
2
|
|
|
|
|
12
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires qw(cfg log); |
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
14371
|
use IO::Socket::INET; |
|
|
2
|
|
|
|
|
18387
|
|
|
|
2
|
|
|
|
|
38
|
|
|
17
|
2
|
|
|
2
|
|
2732
|
use YAML::Syck; |
|
|
2
|
|
|
|
|
2483
|
|
|
|
2
|
|
|
|
|
151
|
|
|
18
|
2
|
|
|
2
|
|
2013
|
use URI::Escape; |
|
|
2
|
|
|
|
|
3334
|
|
|
|
2
|
|
|
|
|
2836
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub mcp_inform |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
$msg = {state => $msg} if not ref($msg) eq 'HASH'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# set PRC number |
|
29
|
0
|
0
|
|
|
|
|
if ($self->cfg->{guest_number}) { |
|
30
|
0
|
|
|
|
|
|
$msg->{prc_number} = $self->{cfg}->{guest_number}; |
|
31
|
|
|
|
|
|
|
} else { |
|
32
|
|
|
|
|
|
|
# guest numbers start with 1, 0 is host or no virtualisation |
|
33
|
0
|
|
|
|
|
|
$msg->{prc_number} = 0; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
0
|
|
|
|
|
|
return $self->mcp_send($msg); |
|
36
|
|
|
|
|
|
|
}; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub mcp_send |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
0
|
|
|
0
|
1
|
|
my ($self, $message) = @_; |
|
43
|
0
|
0
|
0
|
|
|
|
my $server = $self->cfg->{mcp_host} || $self->cfg->{mcp_server} or return "MCP host unknown"; |
|
44
|
0
|
0
|
0
|
|
|
|
my $port = $self->cfg->{mcp_port} || $self->cfg->{port} or return "MCP port unknown"; |
|
45
|
0
|
|
0
|
|
|
|
$message->{testrun_id} ||= $self->cfg->{testrun_id} || $self->cfg->{test_run}; |
|
|
|
|
0
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my %headers; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $url = "GET /state/"; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# state always needs to be first URL part because server uses it as filter |
|
51
|
0
|
|
0
|
|
|
|
$url .= $message->{state} || 'unknown'; |
|
52
|
0
|
|
|
|
|
|
delete $message->{state}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
foreach my $key (keys %$message) { |
|
55
|
0
|
0
|
|
|
|
|
if ($message->{$key} =~ m|/| ) { |
|
56
|
0
|
|
|
|
|
|
$headers{$key} = $message->{$key}; |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
0
|
|
|
|
|
|
$url .= "/$key/"; |
|
59
|
0
|
|
|
|
|
|
$url .= uri_escape($message->{$key}); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
$url .= " HTTP/1.0\r\n"; |
|
63
|
0
|
|
|
|
|
|
foreach my $header (keys %headers) { |
|
64
|
0
|
|
|
|
|
|
$url .= "X-Tapper-$header: "; |
|
65
|
0
|
|
|
|
|
|
$url .= $headers{$header}; |
|
66
|
0
|
|
|
|
|
|
$url .= "\r\n"; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->log->info("Sending $url to $server"); |
|
70
|
0
|
0
|
|
|
|
|
if (my $sock = IO::Socket::INET->new(PeerAddr => $server, |
|
71
|
|
|
|
|
|
|
PeerPort => $port, |
|
72
|
|
|
|
|
|
|
Proto => 'tcp')){ |
|
73
|
0
|
|
|
|
|
|
$sock->print("$url\r\n"); |
|
74
|
0
|
|
|
|
|
|
close $sock; |
|
75
|
|
|
|
|
|
|
} else { |
|
76
|
0
|
|
|
|
|
|
$self->log->error("Can't connect to MCP on $server:$port: $@"); |
|
77
|
0
|
|
|
|
|
|
return("Can't connect to MCP: $!"); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
0
|
|
|
|
|
|
return(0); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub tap_report_away |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
1
|
|
my ($self, $tap) = @_; |
|
87
|
0
|
|
|
|
|
|
my $reportid; |
|
88
|
0
|
0
|
|
|
|
|
if (my $sock = IO::Socket::INET->new(PeerAddr => $self->cfg->{report_server}, |
|
89
|
|
|
|
|
|
|
PeerPort => $self->cfg->{report_port}, |
|
90
|
|
|
|
|
|
|
Proto => 'tcp')) { |
|
91
|
0
|
|
|
|
|
|
eval{ |
|
92
|
0
|
|
|
|
|
|
my $timeout = 100; |
|
93
|
0
|
|
|
0
|
|
|
local $SIG{ALRM}=sub{die("timeout for sending tap report ($timeout seconds) reached.");}; |
|
|
0
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
alarm($timeout); |
|
95
|
0
|
|
|
|
|
|
($reportid) = <$sock> =~m/(\d+)$/g; |
|
96
|
0
|
|
|
|
|
|
$sock->print($tap); |
|
97
|
|
|
|
|
|
|
}; |
|
98
|
0
|
|
|
|
|
|
alarm(0); |
|
99
|
0
|
0
|
|
|
|
|
$self->log->error($@) if $@; |
|
100
|
0
|
|
|
|
|
|
close $sock; |
|
101
|
|
|
|
|
|
|
} else { |
|
102
|
0
|
|
|
|
|
|
return(1,"Can not connect to report server: $!"); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
|
return (0,$reportid); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub tap_report_create |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
0
|
1
|
|
my ($self, $report) = @_; |
|
113
|
0
|
|
|
|
|
|
my $message; |
|
114
|
0
|
|
|
|
|
|
my @tests = @{$report->{tests}}; |
|
|
0
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$message .= "1..".int (@tests); |
|
117
|
0
|
|
|
|
|
|
$message .= "\n"; |
|
118
|
0
|
|
|
|
|
|
foreach my $header (keys %{$report->{headers}}) { |
|
|
0
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$message .= "# $header: "; |
|
120
|
0
|
|
|
|
|
|
$message .= $report->{headers}->{$header}; |
|
121
|
0
|
|
|
|
|
|
$message .= "\n"; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# @tests starts with 0, reports start with 1 |
|
125
|
0
|
|
|
|
|
|
for (my $i=1; $i<=@tests; $i++) { |
|
126
|
0
|
0
|
|
|
|
|
$message .= "not " if $tests[$i-1]->{error}; |
|
127
|
0
|
|
|
|
|
|
$message .="ok $i - "; |
|
128
|
0
|
0
|
|
|
|
|
$message .= $tests[$i-1]->{test} if $tests[$i-1]->{test}; |
|
129
|
0
|
|
|
|
|
|
$message .="\n"; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
0
|
|
|
|
|
|
return ($message); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub nfs_mount |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
138
|
0
|
|
|
|
|
|
my ($error, $retval); |
|
139
|
0
|
|
|
|
|
|
$error = $self->makedir($self->cfg->{paths}{prc_nfs_mountdir}); |
|
140
|
0
|
0
|
|
|
|
|
return $error if $error; |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
($error, $retval) = $self->log_and_exec("mount", |
|
143
|
|
|
|
|
|
|
$self->cfg->{prc_nfs_server}.":".$self->cfg->{paths}{prc_nfs_mountdir}, |
|
144
|
|
|
|
|
|
|
$self->cfg->{paths}{prc_nfs_mountdir}); |
|
145
|
0
|
0
|
|
|
|
|
return "Can't mount ".$self->cfg->{paths}{prc_nfs_mountdir}.":$retval" if $error; |
|
146
|
0
|
|
|
|
|
|
return 0; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub log_to_file |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
0
|
1
|
|
my ($self, $state) = @_; |
|
154
|
0
|
|
|
|
|
|
my $output = $self->cfg->{paths}{output_dir}; |
|
155
|
0
|
|
0
|
|
|
|
$output .= "/".($self->cfg->{testrun_id} || $self->cfg->{test_run}); |
|
156
|
0
|
|
|
|
|
|
$output .= "/$state"; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $error = $self->makedir ($output); |
|
159
|
0
|
0
|
|
|
|
|
return $error if $error; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
$output .= "/Tapper"; |
|
162
|
0
|
0
|
|
|
|
|
open (STDOUT, ">>", "$output.stdout") or $self->logdie("Can't open output file $output.stdout: $!"); |
|
163
|
0
|
0
|
|
|
|
|
open (STDERR, ">>", "$output.stderr") or $self->logdie("Can't open output file $output.stderr: $!"); |
|
164
|
0
|
|
|
|
|
|
return 0; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__END__ |
|
170
|
|
|
|
|
|
|
=pod |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=encoding utf-8 |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 NAME |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Tapper::Remote::Net |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
use Tapper::Remote::Net; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 NAME |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Tapper::Remote::Net - Communication with MCP |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 mcp_inform |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Generate the message to be send to MCP and hand it over to mcp_send. |
|
191
|
|
|
|
|
|
|
If the message is given as string its converted to hash. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
@param string or hash reference - message to send to MCP |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
@return success - 0 |
|
196
|
|
|
|
|
|
|
@return error - error string |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 mcp_send |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Tell the MCP server our current status. This is done using a HTTP request. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
@param hash ref - message to send to MCP |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
@return success - 0 |
|
205
|
|
|
|
|
|
|
@return error - error string |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 tap_report_away |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Actually send the tap report to receiver. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
@param string - report to be sent |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
@return success - (0, report id) |
|
214
|
|
|
|
|
|
|
@return error - (1, error string) |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 tap_report_create |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Create a report string from a report in hash form. Since the function only |
|
219
|
|
|
|
|
|
|
does data transformation, no error should ever occur. |
|
220
|
|
|
|
|
|
|
The expected hash should contain the following keys: |
|
221
|
|
|
|
|
|
|
* tests - contains an array of hashes with |
|
222
|
|
|
|
|
|
|
** error - indicated whether this test failed (if true) |
|
223
|
|
|
|
|
|
|
** test - description of the test |
|
224
|
|
|
|
|
|
|
* headers - Tapper headers with values |
|
225
|
|
|
|
|
|
|
* sections - array of hashes containing tests and headers ad described above and |
|
226
|
|
|
|
|
|
|
a section_name |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
@param hash ref - report data |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
@return report string |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 nfs_mount |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Mount the output directory from an NFS server. This method is used since we |
|
235
|
|
|
|
|
|
|
only want to mount this NFS share in live mode. |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
@return success - 0 |
|
238
|
|
|
|
|
|
|
@return error - error string |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 log_to_file |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Turn stdout and stderr into files. This way we get output that would |
|
243
|
|
|
|
|
|
|
otherwise be lost. The function expects a state that will be used. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
@param string - state |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
@return success - 0 |
|
248
|
|
|
|
|
|
|
@return error - string |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 AUTHOR |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by Advanced Micro Devices, Inc.. |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
This is free software, licensed under: |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |
|
263
|
|
|
|
|
|
|
|