Netperf/Client.pm

filter: Statementstmt 88.2% 90 / 102 Branchbran 54.5% 12 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 80.0% 8 / 10 Podpod 100% 6 / 6 totaltotal 81.8% 117 / 143 CC 13 SCAR 12.6
CC
13
Cov
82%
parse_netperf
6.0
run
5.2
get_bandwidth
4.0
CRAP 3.5
↑ Summary Netperf/Server.pm »
1 package Tapper::TestSuite::Netperf::Client;
2 4 our $AUTHORITY = 'cpan:TAPPER';
3 # ABSTRACT: Tapper - Network performance measurements - Client
4 4 $Tapper::TestSuite::Netperf::Client::VERSION = '5.0.0';
5 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 extends 'Tapper::TestSuite::Netperf';
7 4 ▶ use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶ use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $netperf_desc = "benchmarks-netperf";
11  
12  
13 1 ▶ sub tap_report_away {
Subroutine tap_report_away: called CC=3 SCAR=11.3
Pod documented
14 1 my ($self, $tap) = @_;
15  
16 1 my $reportid;
17 1 ▶ if (my $sock = IO::Socket::INET->new(PeerAddr => $ENV{TAPPER_REPORT_SERVER},
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = 'IO::Socket::INET'->new('PeerAddr', $ENV{'TAPPER_REPORT_SERVER'}, 'PeerPort', $ENV{'TAPPER_REPORT_PORT'}, 'Proto', 'tcp')) { } 1 0 1
18 PeerPort => $ENV{TAPPER_REPORT_PORT},
19 Proto => 'tcp')) {
20 1 eval{
21 1 my $timeout = 100;
22 0 ▶ local $SIG{ALRM}=sub{die("timeout for sending tap report ($timeout seconds) reached.");};
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 1 alarm($timeout);
24 1 ($reportid) = <$sock> =~m/(\d+)$/g;
25 1 $sock->print($tap);
26 };
27 1 alarm(0);
28 1 ▶ $self->log->error($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
29 1 close $sock;
30 } else {
31 0 return(1,"Can not connect to report server: $!");
32 }
33 1 return (0,$reportid);
34  
35 }
36  
37  
38 1 ▶ sub tap_report_send {
Subroutine tap_report_send: called CC=1 SCAR=0.0
Pod documented
39 1 my ($self, $report) = @_;
40  
41 1 my $tap = $self->tap_report_create($report);
42 1 $self->log->debug($tap);
43 1 return $self->tap_report_away($tap);
44 }
45  
46  
47  
48 1 ▶ sub tap_report_create {
Subroutine tap_report_create: called CC=3 SCAR=11.0
Pod documented
49 1 my ($self, $report) = @_;
50  
51 1 my @report = @$report;
52 1 my $hostname = $ENV{TAPPER_HOSTNAME};
53 1 my $testrun = $ENV{TAPPER_TESTRUN};
54 1 ▶ $hostname = $hostname // 'No hostname set';
Condition50%1/2
$hostname // "No hostname set"
l!l
10
MC/DC0%0/1
$hostname // "No hostname set"
$hostname
Truth table50%1/2
A
A= $hostname
Aresult
11
00
55 1 my $message;
56 1 $message .= "1..".scalar @report."\n";
57 1 $message .= "# Tapper-reportgroup-testrun: $testrun\n";
58 1 $message .= "# Tapper-suite-name: Netperf\n";
59 1 $message .= "# Tapper-suite-version: $Tapper::TestSuite::Netperf::VERSION\n";
60 1 $message .= "# Tapper-machine-name: $hostname\n";
61  
62 # @report starts with 0, reports start with 1
63 1 ▶ for (my $i=0; $i<=$#report; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#report) 3 1 4
64 3 chomp($report[$i]);
65 3 $message .="$report[$i]\n";
66 }
67 1 return ($message);
68 }
69  
70  
71  
72 1 ▶ sub get_bandwidth {
Subroutine get_bandwidth: called CC=4 SCAR=13.9
Pod documented
73 1 my ($self, $socket) = @_;
74  
75 1 my ($buf1, $buf2, $start_time, $end_time, $msg, $size);
76 1 my $offset=0; # get rid of warning
77  
78 1 $size = 1024*1024*32;
79 1 $buf1 = 'U'x($size);
80 1 $start_time = time();
81 1 my $tmpbuf;
82 1 ▶ while ($offset < length($buf1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < length $buf1) 32768 1 32769
83 32768 $offset += $socket->syswrite($buf1, 1024, $offset);
84 32768 $socket->sysread($tmpbuf, 1024);
85 32768 $buf2 .= $tmpbuf;
86 }
87 1 $end_time = time();
88 1 ▶ $end_time++ if not $end_time > $start_time;
Branch: 1 branch
BranchTrueFalseTotal
unless $end_time > $start_time 0 1 1
89 1 ▶ $msg = 'not ' unless $buf1 eq $buf2;
Branch: 1 branch
BranchTrueFalseTotal
unless $buf1 eq $buf2 0 1 1
90 1 $msg .= "ok - benchmarks-custom";
91 1 $msg .= "\n ---";
92 1 $msg .= "\n bytes_per_second: "; $msg .= ($size)/(($end_time-$start_time)*1.0);
93 1 $msg .= "\n length_send_buffer: "; $msg .= length($buf1);
94 1 $msg .= "\n length_receive_buffer: "; $msg .= length($buf2);
95 1 $msg .= "\n ...\n";
96 1 return $msg;
97 }
98  
99  
100 0 ▶ sub parse_netperf {
Subroutine parse_netperf: not called CC=2 SCAR=17.9
Pod documented
101 0 my ($self, $server, $netperf_file) = @_;
102  
103 0 my $output = `$netperf_file -P0 $server`;
104 0 ▶ if ($output !~ m/^[0-9. ]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /^[0-9. ]+$/) 0 0 0
105 0 $output =~ s/\n/\n#/gx;
106 0 return "not ok - $netperf_desc\n#$output";
107  
108 }
109 0 $output=~s|^\s*(\S)|$1|;
110 0 my @output = split /\s+/,$output;
111  
112 0 return "ok - $netperf_desc
113 ---
114 recv_socket_size_bytes: $output[0]
115 send_socket_size_bytes: $output[1]
116 send_message_size_bytes: $output[2]
117 time: $output[3]
118 throughput: $output[4]
119 ...
120 ";
121 }
122  
123  
124  
125 sub run
126 1 ▶ {
Subroutine run: called CC=5 SCAR=16.5
Pod documented
127 1 my ($self) = @_;
128  
129 1 my $config_file = $ENV{TAPPER_SYNC_FILE};
130 1 ▶ return "Config file is not set" if not $config_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $config_file 0 1 1
131  
132 1 my @report;
133 1 my $peers = YAML::LoadFile($config_file);
134 # even though, server and client are synced by PRC, the
135 # server may take a little more time to set up than the
136 # client so give it some extra time
137 1 sleep(2);
138 1 my $socket = IO::Socket::INET->new(PeerHost => $peers->[0], PeerPort => 5000);
139 1 my $msg;
140 1 ▶ $msg = 'not ' if not $socket;
Branch: 1 branch
BranchTrueFalseTotal
unless $socket 0 1 1
141 1 $msg .= "ok - Connect to peer";
142 1 push @report, $msg;
143  
144 1 $msg = $self->get_bandwidth($socket);
145 1 push @report, $msg;
146  
147 1 my $netperf_file = `which netperf`;
148 1 chomp($netperf_file);
149 1 ▶ if (-e $netperf_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $netperf_file) { } 0 1 1
150 0 $msg = $self->parse_netperf($peers->[0], $netperf_file);
151 0 push @report, $msg;
152 }
153 else {
154 1 push @report, 'not ok - $netperf_desc # SKIP no netperf available in PATH';
155 }
156  
157 1 my ($fail, $retval) = $self->tap_report_send(\@report);
158 1 ▶ return $retval if $fail;
Branch: 1 branch
BranchTrueFalseTotal
if $fail 0 1 1
159 1 return 0;
160 }
161  
162 4 1;
163  
164 __END__
↑ Summary Netperf/Server.pm »