diff --git a/tests/tst-tcp-hash-cli.py b/tests/tst-tcp-hash-cli.py index 61f1352a9a16e92ad8b6786382c536eb8208b48b..b7ddeababcff7edc8b9a999ecee1c174d898b4da 100755 --- a/tests/tst-tcp-hash-cli.py +++ b/tests/tst-tcp-hash-cli.py @@ -2,6 +2,7 @@ import socket from Queue import Queue from threading import Thread +import sys class Worker(Thread): """Thread executing tasks from a given tasks queue""" @@ -40,25 +41,53 @@ def hash_function(data): def make_connection(): global data - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect(("192.168.122.89", 2500)) - data = "".join(data) - s.send(data) - s.send("END") - res = s.recv(1) - s.close() - print 'Received', ord(res[0]) + global drops + global hash_errors + + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect(("192.168.122.89", 2500)) + data = "".join(data) + s.send(data) + s.send("END") + res = s.recv(1) + s.close() + if (ord(res[0]) != expected): + hash_errors = hash_errors + 1 + + except: + drops = drops + 1 if __name__ == "__main__": + nthreads = 0 + connections = 0 + + try: + nthreads = int(sys.argv[1]) + connections = int(sys.argv[2]) + except: + print "Usage: ./tst-tcp-hash-cli.py <nthreads> <connections>" + sys.exit() + #data = range(0, (4096**2)*2, 11) data = range(0,4096, 11) data = map(lambda x: chr(x % 256), data) - print "Expecting:", hash_function(data) + expected = hash_function(data) + + print "Sending %d bytes requests, expected hash: %d" % (len(data), expected) + print "Creating %d threads and making %d connections, please wait..." % (nthreads, connections) - pool = ThreadPool(200) - for i in range(200): + drops = 0 + hash_errors = 0 + + pool = ThreadPool(nthreads) + for i in range(connections): pool.add_task(make_connection) pool.wait_completion() + # FIXME: these metrics may not be accurate as I didn't use locks and interfere with the test + print "Test completed with %d drops and %d hash errors" % (drops, hash_errors) + + diff --git a/tests/tst-tcp-hash-srv.cc b/tests/tst-tcp-hash-srv.cc index f7985f9bb24f8cc67846d4f62c736631e0a96f90..d879f95d60b625c6e70101e6f97ee4438f8d56e8 100644 --- a/tests/tst-tcp-hash-srv.cc +++ b/tests/tst-tcp-hash-srv.cc @@ -20,7 +20,7 @@ static u8 hash_function(u8 * data, u32 len) return result; } -#define dbg(...) tprintf_e("tst-tcp-hash-srv", __VA_ARGS__) +#define dbg(...) tprintf_d("tst-tcp-hash-srv", __VA_ARGS__) const int listen_port = 2500; const int chunk_size = 1024;