1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

splittest

This commit is contained in:
Gabor Adam Toth 2011-04-29 16:03:17 +02:00
parent 6785ed048c
commit bd3e61970c
2 changed files with 31 additions and 0 deletions

View file

@ -24,6 +24,9 @@ nettest:
nettesterr: nettesterr:
for f in packets/error-*; do echo ">> $$f"; cat $$f | nc localhost $(PORT); done for f in packets/error-*; do echo ">> $$f"; cat $$f | nc localhost $(PORT); done
splittest:
for f in packets/full-*; do echo ">> $$f"; ./splittest.pl $$f $(PORT) | diff -u $$f -; done
nettestp1: nettestp1:
(for f in packets/part-1-p*; do cat $$f; done) | nc localhost $(PORT) | diff -u packets/full-1 - (for f in packets/part-1-p*; do cat $$f; done) | nc localhost $(PORT) | diff -u packets/full-1 -

28
test/splittest.pl Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
$| = 1;
print "Usage: splittest.pl <packet file> [<port> [<chunk length> [-v]]]\n" and exit unless @ARGV;
my $port = $ARGV[1] || 4440;
my $length = int($ARGV[2] || 1); $length = 1 if $length < 1;
my $verbose = $ARGV[3];
open FILE, '<', $ARGV[0] or die "$ARGV[0]: $!\n";
my $file = ''; $file .= $_ while <FILE>;
close FILE;
my $s = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localhost", PeerPort => $port) or die "localhost:$port: $!\n";
$s->autoflush(1);
my $c = 0;
while ($c < length $file) {
my $chunk = substr $file, $c, $length;
print "[$chunk]" if $verbose;
print $s $chunk;
$c += $length;
}
print while <$s>;
close $s;