5f335db3c0d4b82f8ba8a006040178ecc6f9e021
[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 AAAA -e 3,3,-1"
5 INPUTBOB="-k AAAA -e 1000,100,24"
6
7 # necessary to make the testing prefix deterministic, so we can access the config files
8 PREFIX=/tmp/test-scalarproduct`date +%H%M%S`
9
10 # where can we find the peers config files?
11 CFGALICE="-c $PREFIX/0/config"
12 CFGBOB="-c $PREFIX/1/config"
13
14 # launch two peers in line topology non-interactively
15 #
16 # interactive mode would terminate the test immediately 
17 # because the rest of the script is already in stdin, 
18 # thus redirecting stdin does not suffice)
19 GNUNET_LOG='scalarproduct;;;;DEBUG' GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 2>service.log &
20 PID=$!
21
22 echo $PID
23 read
24 sleep 5
25 # get bob's peer ID, necessary for alice
26 PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
27
28 GNUNET_LOG='scalarproduct;;;;DEBUG' gnunet-scalarproduct $CFGBOB $INPUTBOB 2>bob.log &
29 RESULT=`GNUNET_LOG='scalarproduct;;;;DEBUG' gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB 2>alice.log`
30 RESULT=`printf "%X\n" "0x$RESULT"`
31
32 cat alice.log bob.log service.log >> test_scalarproduct.log
33 rm -f alice.log bob.log service.log
34 ISSUES=$((`grep scalarproduct test_scalarproduct.log | grep -c ERROR` + `grep scalarproduct test_scalarproduct.log | grep -c WARNING`))
35
36 # terminate the testbed
37 kill $PID 
38
39 EXPECTED="CCC"
40 if [ "$ISSUES" -eq "0" ]
41 then
42         if [ "$RESULT" == "$EXPECTED" ]
43         then
44           echo "OK"
45           rm -f test_scalarproduct.log
46           exit 0
47         fi
48 else
49   echo "Result $RESULT NOTOK, see $PWD/test_scalarproduct.log for details"
50   exit 1
51 fi
52