RECLAIM: refactoring; cleanup
[oweals/gnunet.git] / src / dht / test_dht_tools.sh
1 #!/bin/sh
2 # This file is in the public domain.
3
4 out=`mktemp /tmp/test-gnunet-dht-logXXXXXXXX`
5 tempcfg=`mktemp /tmp/test-dht-tools.XXXXXXXX`
6 checkout="check.out"
7 armexe="gnunet-arm -c $tempcfg "
8 putexe="gnunet-dht-put -c $tempcfg "
9 getexe="gnunet-dht-get -c $tempcfg "
10 peerinfo="gnunet-peerinfo -c $tempcfg -sq"
11 stop_arm()
12 {
13   if ! $armexe $DEBUG -e -d > $out ; then
14     echo "FAIL: error running $armexe"
15     echo "Command output was:"
16     cat $out
17     rm -f $out $tempcfg
18     exit 1
19   fi
20   rm -f $out $tempcfg
21 }
22
23 cp test_dht_tools.conf $tempcfg
24
25 echo -n "TEST: Starting ARM..."
26 if ! $armexe $DEBUG -s > $out ; then
27   echo "FAIL: error running $armexe"
28   echo "Command output was:"
29   cat $out
30   stop_arm
31   exit 1
32 fi
33 echo "PASS"
34
35 echo -n "TEST: Testing put..."
36 if ! $putexe -k testkey -d testdata -t 8 > $out ; then
37   echo "FAIL: error running $putexe"
38   echo "Command output was:"
39   cat $out
40   stop_arm
41   exit 1
42 fi
43 echo "PASS"
44
45 echo -n "TEST: Testing get..."
46 echo "Result 0, type 8:" > $checkout
47 echo "testdata" >> $checkout
48
49 if ! $getexe -k testkey -T 100ms -t 8 > $out ; then
50   echo "FAIL: error running $putexe"
51   echo "Command output was:"
52   cat $out
53   stop_arm
54   exit 1
55 fi
56
57 if ! diff --strip-trailing-cr -q $out $checkout ; then
58   echo "FAIL: $out and $checkout differ:"
59   diff --strip-trailing-cr $out $checkout
60   stop_arm
61   exit 1
62 fi
63 echo "PASS"
64 stop_arm