test: added timer for client
[p2p-kernel-protocol.git] / test / test.sh
1 #!/bin/bash
2
3 MODULE_NAME=af_p2pkp
4 MODULE_DIR=../module
5 CLIENT=client/client
6 SERVER=server/server
7 FILE=/root/Dropbox/school/p2pkp/test/client/test_file
8 IP="127.0.0.1"
9
10 LISTENERS_PORTS=(
11         60000
12         60001
13 )
14
15
16 #use nc.traditional
17 echo 2 | update-alternatives --config nc &> /dev/null
18
19 [ -e $FILE ] || exit
20
21 #increase tests debugging
22 set -x
23
24 # insert module, causing the message to be sent
25 insmod $MODULE_DIR/$MODULE_NAME.ko
26
27 # listen for UDP packets on localhost, port 60000 (run in background)
28 for port in "${LISTENERS_PORTS[@]}"; do
29         $SERVER $IP $port testfile.$port &
30         pids="$pids $!"
31         ARGUMENTS="$IP $port $ARGUMENTS"
32 done
33
34 # wait for netcat to start listening
35 sleep 1
36
37 $CLIENT $FILE $ARGUMENTS
38
39 # kill netcat
40 for pid in $pids; do
41         wait $pid &> /dev/null
42 done
43
44 # remove module
45 rmmod $MODULE_NAME
46