-handle disconnect case more nicely
[oweals/gnunet.git] / src / scalarproduct / test_scalarproduct.sh
1 #!/bin/bash
2 # compute a simple scalar product
3 # payload for this test:
4 INPUTALICE="-k CCC -e 'AB,10;RO,3;FL,3;LOL,-1;'"
5 INPUTBOB="-k CCC -e 'BC,-20000;RO,1000;FL,100;LOL,24;'"
6 EXPECTED="0CCC"
7
8 # necessary to make the testing prefix deterministic, so we can access the config files
9 PREFIX=/tmp/test-scalarproduct`date +%H%M%S`
10
11 # where can we find the peers config files?
12 CFGALICE="-c $PREFIX/0/config"
13 CFGBOB="-c $PREFIX/1/config"
14
15 # launch two peers in line topology non-interactively
16 #
17 # interactive mode would terminate the test immediately
18 # because the rest of the script is already in stdin,
19 # thus redirecting stdin does not suffice)
20 # GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG'
21 GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 &
22 PID=$!
23 # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe
24 echo "Waiting for peers to start..."
25 sleep 5
26 echo "Running test..."
27
28 # get bob's peer ID, necessary for alice
29 PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
30
31 #GNUNET_LOG=';;;;DEBUG'
32 gnunet-scalarproduct $CFGBOB $INPUTBOB &
33 #GNUNET_LOG=';;;;DEBUG'
34 RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB`
35
36 # terminate the testbed
37 kill $PID
38
39 if [ "$RESULT" == "$EXPECTED" ]
40 then
41         echo "OK"
42         exit 0
43 else
44         echo "Result $RESULT, expected $EXPECTED - NOTOK"
45         exit 1
46 fi
47