need to sleep here
[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 sleep 1
51
52 # ----------------------------------------------------------------------------------
53 echo -n "TEST: Start another service... "
54
55 if ! $exe $DEBUG -i resolver > $out ; then
56   echo "FAIL: error running $exe"
57   echo "Command output was:"
58   cat $out
59   kill %%
60   exit 1
61 fi
62 sleep 1
63 LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
64 if test $LINES -ne 1; then
65   echo "FAIL: unexpected output (got $LINES lines, wanted 1)"
66   echo "Command output was:"
67   cat $out
68   $exe -e > /dev/null
69   exit 1
70 fi
71 echo "PASS"
72
73 # ----------------------------------------------------------------------------------
74 echo -n "TEST: Test -t on running service... "
75
76 if ! $exe $DEBUG -t resolver > $base.out; then
77     echo "FAIL: error running $exe"
78     exit 1
79 fi
80 LINES=`cat $base.out | grep resolver | grep not | wc -l`
81 if test $LINES -ne 0; then
82   echo "FAIL: unexpected output:"
83   cat $base.out
84   $exe -e
85   exit 1
86 fi
87 LINES=`cat $base.out | grep resolver | grep -v not | wc -l`
88 if test $LINES -ne 1; then
89   echo "FAIL: unexpected output"
90   cat $base.out
91   $exe -e
92   exit 1
93 fi
94 echo "PASS"
95
96 # ----------------------------------------------------------------------------------
97 echo -n "TEST: Stop a service... "
98
99 if ! $exe $DEBUG -k resolver > $out; then
100   echo "FAIL: error running $exe"
101   $exe -e
102   exit 1
103 fi
104 sleep 1
105 LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
106 if test $LINES -ne 0; then
107   sleep 5
108   LINES=`ps -C gnunet-service-resolver -o pid= | wc -l`
109 fi
110 if test $LINES -ne 0; then
111   sleep 2
112
113   echo "FAIL: unexpected output"
114   echo "Command output was:"
115   cat $out
116   $exe -e > /dev/null
117   exit 1
118 fi
119 echo "PASS"
120
121 # ----------------------------------------------------------------------------------
122 echo -n "TEST: Test -t on stopped service... "
123
124 if ! $exe $DEBUG -t resolver > $base.out; then
125   echo "FAIL: error running $exe"
126   cat $base.out
127   $exe -e > /dev/null
128   exit 1
129 fi
130 LINES=`cat $base.out | grep resolver | grep not | wc -l`
131 if test $LINES -ne 1; then
132   echo "FAIL: unexpected output"
133   cat $base.out 
134   $exe -e > /dev/null
135   exit 1
136 fi
137 echo "PASS"
138
139 # ----------------------------------------------------------------------------------
140 echo -n "TEST: Stop ARM... "
141
142 if ! $exe $DEBUG -e > $out; then
143   echo "FAIL: error running $exe"
144   exit 1
145 fi
146 sleep 1
147 LINES=`ps -C gnunet-service-arm -o pid= | wc -l`
148 if test $LINES -ne 0; then
149   sleep 5
150   LINES=`ps -C gnunet-service-arm -o pid= | wc -l`
151 fi
152 if test $LINES -ne 0; then
153   echo "FAIL: unexpected output, still have $LINES gnunet-service-arm processes"
154   echo "Command output was:"
155   cat $out  
156   exit 1
157 fi
158 echo "PASS"
159
160 rm -rf /tmp/test-gnunetd-arm/
161 rm -f $base.out $out
162