clean up for configs
[oweals/gnunet.git] / src / scalarproduct / test_scalarproduct.sh
index ee828e4aae4b457a342f4ebb5e5052d647bc0a5b..5ba94f6416b89c7efed8a3c318bbc91a094c6f95 100755 (executable)
@@ -1,33 +1,42 @@
 #!/bin/bash
-
-#necessary to make the testing prefix deterministic, so we can access the config files
-GNUNET_TESTING_PREFIX=/tmp/test-scalarproduct1337
-CFGA="-c ./test_scalarproduct_alice.conf"
-CFGB="-c ./test_scalarproduct_bob.conf"
-                                       #can't use ` directly
-SESSIONDATA="-k AAAA -e 10,10,10"
-EXPECTED="2C0"
-
-gnunet-arm -s $CFGA
-sleep 2
-gnunet-arm -s $CFGB
-sleep 2
-
-IDB=`gnunet-peerinfo -s $CFGB | awk -F "\x60" '{print $2}' | awk -F "'" '{print $1}'`
-
-gnunet-scalarproduct $CFGB $SESSIONDATA
-
-RESULT=`gnunet-scalarproduct $CFGA $SESSIONDATA -p $IDB`
-
-gnunet-arm -e $CFGA &
-gnunet-arm -e $CFGB &
-
+# compute a simple scalar product
+# payload for this test:
+INPUTALICE="-k CCC -e 3,3,-1"
+INPUTBOB="-k CCC -e 1000,100,24"
+
+# necessary to make the testing prefix deterministic, so we can access the config files
+PREFIX=/tmp/test-scalarproduct`date +%H%M%S`
+
+# where can we find the peers config files?
+CFGALICE="-c $PREFIX/0/config"
+CFGBOB="-c $PREFIX/1/config"
+
+# launch two peers in line topology non-interactively
+#
+# interactive mode would terminate the test immediately 
+# because the rest of the script is already in stdin, 
+# thus redirecting stdin does not suffice)
+GNUNET_LOG='scalarproduct;;;;DEBUG' GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 &
+PID=$!
+# sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe
+sleep 5
+
+# get bob's peer ID, necessary for alice
+PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
+
+GNUNET_LOG=';;;;DEBUG' gnunet-scalarproduct $CFGBOB $INPUTBOB &
+RESULT=`GNUNET_LOG=';;;;DEBUG' gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB`
+
+# terminate the testbed
+kill $PID 
+
+EXPECTED="0CCC"
 if [ "$RESULT" == "$EXPECTED" ]
 then
-  echo "OK"
-  exit 0
+       echo "OK"
+       exit 0
 else
-  echo "Result $RESULT NOTOK"
-  exit 1
+       echo "Result $RESULT NOTOK"
+       exit 1
 fi