test: moved testing script
authorRăzvan Crainea <razvan.crainea@gmail.com>
Sun, 27 May 2012 17:13:13 +0000 (20:13 +0300)
committerRăzvan Crainea <razvan.crainea@gmail.com>
Sun, 27 May 2012 17:48:07 +0000 (20:48 +0300)
test/Makefile [new file with mode: 0644]
test/client/.gitignore [new file with mode: 0644]
test/client/client [deleted file]
test/server/.gitignore [new file with mode: 0644]
test/server/server.c
test/test.sh [moved from test/client/test.sh with 70% similarity]

diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..22d865b
--- /dev/null
@@ -0,0 +1,12 @@
+all: client server
+
+.PHONY: client server clean
+client server:
+       make -C $@
+
+run: client server
+       @./test.sh
+
+clean:
+       -make -C client clean
+       -make -C server clean
diff --git a/test/client/.gitignore b/test/client/.gitignore
new file mode 100644 (file)
index 0000000..a54b530
--- /dev/null
@@ -0,0 +1,2 @@
+client.o
+client
diff --git a/test/client/client b/test/client/client
deleted file mode 100755 (executable)
index 6f7edef..0000000
Binary files a/test/client/client and /dev/null differ
diff --git a/test/server/.gitignore b/test/server/.gitignore
new file mode 100644 (file)
index 0000000..b594a0a
--- /dev/null
@@ -0,0 +1,2 @@
+server.o
+server
index 9c1e228..cf7b245 100644 (file)
@@ -43,9 +43,9 @@ int main(int argc, char **argv)
                printf("Cannot bind to server: %s(%d)\n", strerror(errno), errno);
                return -1;
        }
-       argv += 2;
 
        printf("Bound to: %s:%s\n", argv[0], argv[1]);
+       argv += 2;
        
        err = read(sock, argv[0], sizeof(argv[0]));
        if (err < 0) {
similarity index 70%
rename from test/client/test.sh
rename to test/test.sh
index b961f72..d36d0fe 100755 (executable)
@@ -1,13 +1,14 @@
 #!/bin/bash
 
 MODULE_NAME=af_p2pkp
-MODULE_DIR=../../module
-CLIENT=./client
+MODULE_DIR=../module
+CLIENT=client/client
+SERVER=server/server
+IP="127.0.0.1"
 
 LISTENERS_PORTS=(
        60000
        60001
-       60002
 )
 
 
@@ -17,25 +18,26 @@ echo 2 | update-alternatives --config nc &> /dev/null
 #increase tests debugging
 set -x
 
+# insert module, causing the message to be sent
+insmod $MODULE_DIR/$MODULE_NAME.ko
+
 # listen for UDP packets on localhost, port 60000 (run in background)
-for listener in "${LISTENERS_PORTS[@]}"; do
-       netcat -l -u -p $listener &
+for port in "${LISTENERS_PORTS[@]}"; do
+       $SERVER $IP $port testfile.$port &
        pids="$pids $!"
-       ARGUMENTS="127.0.0.1 $listener $ARGUMENTS"
+       ARGUMENTS="$IP $port $ARGUMENTS"
 done
 
 # wait for netcat to start listening
 sleep 1
 
-# insert module, causing the message to be sent
-insmod $MODULE_DIR/$MODULE_NAME.ko
-
 $CLIENT $ARGUMENTS
 
-# remove module
-rmmod $MODULE_NAME
-
 # kill netcat
 for pid in $pids; do
-       kill $pid &> /dev/null
+       wait $pid &> /dev/null
 done
+
+# remove module
+rmmod $MODULE_NAME
+