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