-removing 2nd argument from GNUNET_CLIENT_disconnect as it was virtually always GNUNE...
[oweals/gnunet.git] / src / statistics / test_gnunet_statistics.sh
1 #!/bin/sh
2
3 rm -rf /tmp/test-gnunetd-statistics/
4 exe="./gnunet-statistics -c test_statistics_api_data.conf"
5 out=`mktemp /tmp/test-gnunet-statistics-logXXXXXXXX`
6 arm="gnunet-arm -c test_statistics_api_data.conf $DEBUG"
7 #DEBUG="-L DEBUG"
8 # -----------------------------------
9 echo -n "Preparing: Starting service..."
10
11 $arm -s > /dev/null
12 sleep 1
13 $arm -i statistics > /dev/null
14 sleep 1 
15 echo "DONE"
16
17 # ----------------------------------------------------------------------------------
18 echo -n "TEST: Bad argument checking..."
19
20 if $exe -x 2> /dev/null; then
21   echo "FAIL: error running $exe"
22   $arm -e
23   exit 1
24 fi
25 echo "PASS"
26
27 # ----------------------------------------------------------------------------------
28 echo -n "TEST: Set value..."
29
30 if ! $exe $DEBUG -n test -s subsystem 42 ; then
31   echo "FAIL: error running $exe"
32   $arm -e
33   exit 1
34 fi
35 echo "PASS"
36
37 # ----------------------------------------------------------------------------------
38 echo -n "TEST: Set another value..."
39
40 if ! $exe $DEBUG -n other -s osystem 43 ; then
41   echo "FAIL: error running $exe"
42   $arm -e
43   exit 1
44 fi
45 echo "PASS"
46
47 # ----------------------------------------------------------------------------------
48 echo -n "TEST: viewing all stats..."
49
50 if ! $exe $DEBUG > $out; then
51     echo "FAIL: error running $exe"
52     $arm -e
53     exit 1
54 fi
55 LINES=`cat $out | wc -l`
56 if test $LINES -ne 2; then
57     echo "FAIL: unexpected output"
58     $arm -e
59     exit 1
60 fi
61 echo "PASS"
62
63 # ----------------------------------------------------------------------------------
64 echo -n "TEST: viewing stats by name..."
65
66 if ! $exe $DEBUG -n other > $out; then
67     echo "FAIL: error running $exe"
68     $arm -e
69     exit 1
70 fi
71 LINES=`cat $out | grep 43 | wc -l`
72 if test $LINES -ne 1; then
73     echo "FAIL: unexpected output"
74     $arm -e
75     exit 1
76 fi
77 echo "PASS"
78
79 # ----------------------------------------------------------------------------------
80 echo -n "TEST: viewing stats by subsystem..."
81
82 if ! $exe $DEBUG -s subsystem > $out; then
83     echo "FAIL: error running $exe"
84     $arm -e
85     exit 1
86 fi
87 LINES=`cat $out | grep 42 | wc -l`
88 if test $LINES -ne 1; then
89     echo "FAIL: unexpected output"
90     $arm -e
91     exit 1
92 fi
93 echo "PASS"
94
95
96 # ----------------------------------------------------------------------------------
97 echo -n "TEST: Set persistent value..."
98
99 if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
100   echo "FAIL: error running $exe"
101   $arm -e
102   exit 1
103 fi
104 if ! $exe $DEBUG > $out; then
105     echo "FAIL: error running $exe"
106     $arm -e
107     exit 1
108 fi
109 LINES=`cat $out | grep 40 | wc -l`
110 if test $LINES -ne 1; then
111     echo "FAIL: unexpected output"
112     cat $out
113     $arm -e
114     exit 1
115 fi
116 echo "PASS"
117
118 # -----------------------------------
119 echo -n "Restarting service..."
120 $arm -k statistics > /dev/null
121 sleep 1
122 $arm -i statistics > /dev/null
123 sleep 1
124 echo "DONE"
125
126 # ----------------------------------------------------------------------------------
127 echo -n "TEST: checking persistence..."
128
129 if ! $exe $DEBUG > $out; then
130     echo "FAIL: error running $exe"
131     $arm -e
132     exit 1
133 fi
134 LINES=`cat $out | grep 40 | wc -l`
135 if test $LINES -ne 1; then
136     echo "FAIL: unexpected output"
137     cat $out
138     $arm -e
139     exit 1
140 fi
141 echo "PASS"
142
143
144
145 # ----------------------------------------------------------------------------------
146 echo -n "TEST: Removing persistence..."
147
148 if ! $exe  $DEBUG -n lasting -s subsystem 40; then
149   echo "FAIL: error running $exe"
150   $arm -e
151   exit 1
152 fi
153 if ! $exe $DEBUG > $out; then
154     echo "FAIL: error running $exe"
155     $arm -e
156     exit 1
157 fi
158 LINES=`cat $out | grep \! | wc -l`
159 if test $LINES -ne 0; then
160     echo "FAIL: unexpected output"
161     cat $out
162     $arm -e
163     exit 1
164 fi
165 echo "PASS"
166
167
168 # -----------------------------------
169 echo -n "Restarting service..."
170 $arm -k statistics > /dev/null
171 sleep 1
172 $arm -i statistics > /dev/null
173 sleep 1
174 echo "DONE"
175
176 # ----------------------------------------------------------------------------------
177 echo -n "TEST: checking removed persistence..."
178
179 if ! $exe $DEBUG > $out; then
180     echo "FAIL: error running $exe"
181     $arm -e
182     exit 1
183 fi
184 LINES=`cat $out | grep 40 | wc -l`
185 if test $LINES -ne 0; then
186     echo "FAIL: unexpected output"
187     cat $out
188     $arm -e
189     exit 1
190 fi
191 echo "PASS"
192
193 # -----------------------------------
194 echo -n "Stopping service..."
195 $arm -e > /dev/null
196 sleep 1
197 echo "DONE"
198 rm -f $out
199 rm -rf /tmp/test-gnunetd-statistics/