mirror of
https://github.com/yrutschle/sslh.git
synced 2025-06-06 18:33:24 +03:00
make t_load pretty print
This commit is contained in:
parent
0e3242c115
commit
74ce2acdc5
49
t_load
49
t_load
@ -46,8 +46,8 @@ my $stop_client_probability = .001;
|
|||||||
my %protocols = (
|
my %protocols = (
|
||||||
#"ssh" => { address => "localhost:9001", client => client("ssh") },
|
#"ssh" => { address => "localhost:9001", client => client("ssh") },
|
||||||
# "tls" => { address => "localhost:9002", client => client("tls") },
|
# "tls" => { address => "localhost:9002", client => client("tls") },
|
||||||
"openvpn" => {address => "localhost:9004", client => client("openvpn") },
|
"openvpn" => {address => "localhost:9004" },
|
||||||
"tinc" => {address => "localhost:9003", client => client("tinc") },
|
"tinc" => {address => "localhost:9003" },
|
||||||
);
|
);
|
||||||
|
|
||||||
##END CONFIG
|
##END CONFIG
|
||||||
@ -77,15 +77,12 @@ sub connect_service {
|
|||||||
sysread $cnx, $r, 8; # length "tinc: 0 " => 10
|
sysread $cnx, $r, 8; # length "tinc: 0 " => 10
|
||||||
}
|
}
|
||||||
my $expected = "$service: $test_data";
|
my $expected = "$service: $test_data";
|
||||||
($? = 1, die "* $service got [$r] expected [$expected]\n") if ($r ne $expected);
|
return ($r eq $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub client {
|
sub client {
|
||||||
my ($service) = @_;
|
my ($service, $client_id, $fd_out) = @_;
|
||||||
|
|
||||||
return sub {
|
|
||||||
my ($client_id) = @_;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
my $r;
|
my $r;
|
||||||
@ -96,7 +93,10 @@ sub client {
|
|||||||
|
|
||||||
warn "starting $service\n";
|
warn "starting $service\n";
|
||||||
|
|
||||||
connect_service($cnx, $service);
|
if (not connect_service($cnx, $service)) {
|
||||||
|
print $fd_out "$client_id\t0\tC\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
my $test_data = "$service $cnt" x int(rand($block_rpt)+1) . "\n";
|
my $test_data = "$service $cnt" x int(rand($block_rpt)+1) . "\n";
|
||||||
@ -105,7 +105,10 @@ sub client {
|
|||||||
my $expected= "$test_data";
|
my $expected= "$test_data";
|
||||||
my $r_l = length $r;
|
my $r_l = length $r;
|
||||||
my $e_l = length $expected;
|
my $e_l = length $expected;
|
||||||
warn ("len $r_l / $e_l (". ($r_l - $e_l). ")\t$client_id\t$service\n");
|
$fd_out->autoflush;
|
||||||
|
my $error = "";
|
||||||
|
$error = "M" if $r ne $expected;
|
||||||
|
print $fd_out ("$client_id\t$r_l\t$error\n");
|
||||||
($? = 1, die "$service got [$r] expected [$expected]\n") if ($r ne $expected);
|
($? = 1, die "$service got [$r] expected [$expected]\n") if ($r ne $expected);
|
||||||
#last if rand(1) < $stop_client_probability;
|
#last if rand(1) < $stop_client_probability;
|
||||||
$cnt++;
|
$cnt++;
|
||||||
@ -113,7 +116,6 @@ sub client {
|
|||||||
}
|
}
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $p (keys %protocols) {
|
foreach my $p (keys %protocols) {
|
||||||
if (!fork) {
|
if (!fork) {
|
||||||
@ -139,10 +141,15 @@ sleep 2; # valgrind can be heavy -- wait 5 seconds
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my ($c_in, $c_out);
|
||||||
|
pipe $c_in, $c_out;
|
||||||
|
|
||||||
|
if (!fork) {
|
||||||
|
# Process that starts all the clients
|
||||||
for my $client_id (1 .. $NUM_CNX) {
|
for my $client_id (1 .. $NUM_CNX) {
|
||||||
foreach my $p (keys %protocols) {
|
foreach my $p (keys %protocols) {
|
||||||
if (!fork) {
|
if (!fork) {
|
||||||
&{$protocols{$p}->{client}}($client_id);
|
client($p, "$p$client_id", $c_out);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
# Give a little time so we don't overrun the
|
# Give a little time so we don't overrun the
|
||||||
@ -150,6 +157,26 @@ for my $client_id (1 .. $NUM_CNX) {
|
|||||||
select undef, undef, undef, $start_time_delay;
|
select undef, undef, undef, $start_time_delay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
my %data;
|
||||||
|
|
||||||
|
# Process that retrieves client output to pretty print
|
||||||
|
print "\033[2J";
|
||||||
|
while (<$c_in>) {
|
||||||
|
chop;
|
||||||
|
my ($client_id, $r_l, $error, @rest) = split /\t/, $_;
|
||||||
|
|
||||||
|
my ($curr_rcv) = ${$data{$client_id}}[0];
|
||||||
|
my ($curr_error) = ${$data{$client_id}}[1];
|
||||||
|
$data{$client_id} = [ $r_l + $curr_rcv, "$curr_error$error" ];
|
||||||
|
|
||||||
|
print "\033[0;0H";
|
||||||
|
foreach my $i (sort keys %data) {
|
||||||
|
($r_l, $error) = @{$data{$i}};
|
||||||
|
print "\033[2K$i\t$r_l\t$error\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wait;
|
wait;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user