test: moved testing script
[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 IP="127.0.0.1"
8
9 LISTENERS_PORTS=(
10         60000
11         60001
12 )
13
14
15 #use nc.traditional
16 echo 2 | update-alternatives --config nc &> /dev/null
17
18 #increase tests debugging
19 set -x
20
21 # insert module, causing the message to be sent
22 insmod $MODULE_DIR/$MODULE_NAME.ko
23
24 # listen for UDP packets on localhost, port 60000 (run in background)
25 for port in "${LISTENERS_PORTS[@]}"; do
26         $SERVER $IP $port testfile.$port &
27         pids="$pids $!"
28         ARGUMENTS="$IP $port $ARGUMENTS"
29 done
30
31 # wait for netcat to start listening
32 sleep 1
33
34 $CLIENT $ARGUMENTS
35
36 # kill netcat
37 for pid in $pids; do
38         wait $pid &> /dev/null
39 done
40
41 # remove module
42 rmmod $MODULE_NAME
43