redundant
[oweals/gnunet.git] / src / arm / test_gnunet_arm.sh
1 #!/bin/sh
2
3 rm -rf /tmp/test-gnunetd-arm/
4 exe="./gnunet-arm -c test_arm_api_data.conf"
5 base=/tmp/gnunet-test-arm
6 out=/tmp/test-gnunetd-arm.log
7 #DEBUG="-L DEBUG"
8
9 # -------------------------------------------
10 echo -n "TEST: can this script work?... "
11 LINES=`ps -C gnunet-service-arm -o pid= | wc -l`
12 if test $LINES -ne 0; then
13   echo "No (arm exists). Exiting early."
14   exit 0
15 fi
16 LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
17 if test $LINES -ne 0; then
18   echo "No (resolver exists). Exiting early."
19   exit 0
20 fi
21 echo "Yes."
22
23
24 # ----------------------------------------------------------------------------------
25 echo -n "TEST: Bad argument checking... "
26
27 if $exe -x 2> /dev/null; then
28   echo "FAIL: error running $exe"
29   exit 1
30 fi
31 echo "PASS"
32
33 # ----------------------------------------------------------------------------------
34 echo -n "TEST: Start ARM... "
35
36 if ! $exe $DEBUG -s > $out ; then
37   echo "FAIL: error running $exe"
38   echo "Command output was:"
39   cat $out
40   exit 1
41 fi
42 LINES=`ps -u $USER -C gnunet-service-arm -o pid= | wc -l`
43 if test $LINES -eq 0; then
44   echo "FAIL: found $LINES gnunet-service-arm processes"
45   echo "Command output was:"
46   cat $out
47   exit 1
48 fi
49 echo "PASS"
50
51 # ----------------------------------------------------------------------------------
52 echo -n "TEST: Start another service... "
53
54 if ! $exe $DEBUG -i resolver > $out ; then
55   echo "FAIL: error running $exe"
56   echo "Command output was:"
57   cat $out
58   kill %%
59   exit 1
60 fi
61 sleep 1
62 LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
63 if test $LINES -ne 1; then
64   echo "FAIL: unexpected output (got $LINES lines, wanted 1)"
65   echo "Command output was:"
66   cat $out
67   $exe -e > /dev/null
68   exit 1
69 fi
70 echo "PASS"
71
72 # ----------------------------------------------------------------------------------
73 echo -n "TEST: Test -t on running service... "
74
75 if ! $exe $DEBUG -t resolver > $base.out; then
76     echo "FAIL: error running $exe"
77     exit 1
78 fi
79 LINES=`cat $base.out | grep resolver | grep not | wc -l`
80 if test $LINES -ne 0; then
81   echo "FAIL: unexpected output:"
82   cat $base.out
83   $exe -e
84   exit 1
85 fi
86 LINES=`cat $base.out | grep resolver | grep -v not | wc -l`
87 if test $LINES -ne 1; then
88   echo "FAIL: unexpected output"
89   cat $base.out
90   $exe -e
91   exit 1
92 fi
93 echo "PASS"
94
95 # ----------------------------------------------------------------------------------
96 echo -n "TEST: Stop a service... "
97
98 if ! $exe $DEBUG -k resolver > $out; then
99   echo "FAIL: error running $exe"
100   $exe -e
101   exit 1
102 fi
103 sleep 1
104 LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
105 if test $LINES -ne 0; then
106   sleep 5
107   LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
108 fi
109 if test $LINES -ne 0; then
110   sleep 2
111
112   echo "FAIL: unexpected output"
113   echo "Command output was:"
114   cat $out
115   $exe -e > /dev/null
116   exit 1
117 fi
118 echo "PASS"
119
120 # ----------------------------------------------------------------------------------
121 echo -n "TEST: Test -t on stopped service... "
122
123 if ! $exe $DEBUG -t resolver > $base.out; then
124   echo "FAIL: error running $exe"
125   cat $base.out
126   $exe -e > /dev/null
127   exit 1
128 fi
129 LINES=`cat $base.out | grep resolver | grep not | wc -l`
130 if test $LINES -ne 1; then
131   echo "FAIL: unexpected output"
132   cat $base.out 
133   $exe -e > /dev/null
134   exit 1
135 fi
136 echo "PASS"
137
138 # ----------------------------------------------------------------------------------
139 echo -n "TEST: Stop ARM... "
140
141 if ! $exe $DEBUG -e > $out; then
142   echo "FAIL: error running $exe"
143   exit 1
144 fi
145 sleep 1
146 LINES=`ps -C gnunet-service-arm -o pid= | wc -l`
147 if test $LINES -ne 0; then
148   sleep 5
149   LINES=`ps -C gnunet-service-arm -o pid= | wc -l`
150 fi
151 if test $LINES -ne 0; then
152   echo "FAIL: unexpected output, still have $LINES gnunet-service-arm processes"
153   echo "Command output was:"
154   cat $out  
155   exit 1
156 fi
157 echo "PASS"
158
159 rm -rf /tmp/test-gnunetd-arm/
160 rm -f $base.out $out
161