]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/UDPEcho/tests/echotest.pl
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / UDPEcho / tests / echotest.pl
diff --git a/apps/UDPEcho/tests/echotest.pl b/apps/UDPEcho/tests/echotest.pl
new file mode 100644 (file)
index 0000000..30ae0d5
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FileHandle;
+use IPC::Open2;
+
+if (@ARGV != 1) {
+    print "Usage: echotest.pl <target ipv6>\n";
+    exit(1);
+}
+
+my $alpha = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+my $testbuf = "";
+while (length($testbuf) < 1280 - 40 - 8) {
+    $testbuf .= $alpha;
+}
+
+open2(*READER, *WRITER, "nc6 -u $ARGV[0] 7");
+
+my $trials = 0;
+while (1) {
+    my $len = int(rand(1000));
+    print $len . "\n";
+    print WRITER substr($testbuf, 0, $len) . "\n";
+
+    my $rin = '';
+    vec($rin,fileno(READER),1) = 1;
+    my $found = select($rin, undef, undef, "6");
+    if ($found == 1) {
+        my $foo;
+        sysread READER, $foo, 1280;
+        if ($foo eq $testbuf) {
+            print "WARNING: payload mismatch\n";
+        }
+    } else {
+        print "FAILURE: len: $len\n";
+    }
+
+    $trials++;
+    print "TRIAL: $trials\n";
+    sleep(.05);
+}
+# need to kill off the nc6 process
+print WRITER eof;
+