doc: abstract + architecture
[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=/tmp/testfile32
8 OUTPUT_DIR=/tmp
9 IP="127.0.0.1"
10 WAIT_TIME=3
11
12 LISTENERS_PORTS=(
13         60000
14         60001
15         60002
16         60003
17         60004
18         60005
19 )
20
21
22 #use nc.traditional
23 echo 2 | update-alternatives --config nc &> /dev/null
24
25 [ -d $OUTPUT_DIR ] || mkdir -p $OUTPUT_DIR
26
27 #increase tests debugging
28 #set -x
29
30 # insert module, causing the message to be sent
31 insmod $MODULE_DIR/$MODULE_NAME.ko
32
33 # listen for UDP packets on localhost, port 60000 (run in background)
34 for port in "${LISTENERS_PORTS[@]}"; do
35         $SERVER $IP $port $OUTPUT_DIR/testfile.$port &
36         pids="$pids $!"
37         ARGUMENTS="$IP $port $ARGUMENTS"
38 done
39
40 # wait for netcat to start listening
41 sleep $WAIT_TIME
42
43
44 if [ $# -eq 0 ]; then
45         [ -e $FILE ] || exit
46         $CLIENT $FILE $ARGUMENTS
47 else
48         for file in $@; do
49                 [ -e $file ] || continue
50                 $CLIENT $file $ARGUMENTS
51         done
52 fi
53
54
55 sleep $WAIT_TIME
56 # kill netcat
57 for pid in $pids; do
58         kill -9 $pid &> /dev/null
59 done
60 #for pid in $pids; do
61 #       wait $pid &> /dev/null
62 #done
63
64 # remove module
65 rmmod $MODULE_NAME
66