report diagnostics
[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 echo "PASS"
105
106 # -----------------------------------
107 echo -n "Restarting service..."
108 $arm -k statistics > /dev/null
109 sleep 1
110 $arm -i statistics > /dev/null
111 sleep 1
112 echo "DONE"
113
114 # ----------------------------------------------------------------------------------
115 echo -n "TEST: checking persistence..."
116
117 if ! $exe $DEBUG > $out; then
118     echo "FAIL: error running $exe"
119     $arm -e
120     exit 1
121 fi
122 LINES=`cat $out | grep 40 | wc -l`
123 if test $LINES -ne 1; then
124     echo "FAIL: unexpected output"
125     cat $out
126     $arm -e
127     exit 1
128 fi
129 echo "PASS"
130
131
132
133 # ----------------------------------------------------------------------------------
134 echo -n "TEST: Removing persistence..."
135
136 if ! $exe  $DEBUG -n lasting -s subsystem 40; then
137   echo "FAIL: error running $exe"
138   $arm -e
139   exit 1
140 fi
141 echo "PASS"
142
143
144 # -----------------------------------
145 echo -n "Restarting service..."
146 $arm -k statistics > /dev/null
147 sleep 1
148 $arm -i statistics > /dev/null
149 sleep 1
150 echo "DONE"
151
152 # ----------------------------------------------------------------------------------
153 echo -n "TEST: checking removed persistence..."
154
155 if ! $exe $DEBUG > $out; then
156     echo "FAIL: error running $exe"
157     $arm -e
158     exit 1
159 fi
160 LINES=`cat $out | grep 40 | wc -l`
161 if test $LINES -ne 0; then
162     echo "FAIL: unexpected output"
163     $arm -e
164     exit 1
165 fi
166 echo "PASS"
167
168 # -----------------------------------
169 echo -n "Stopping service..."
170 $arm -e > /dev/null
171 sleep 1
172 echo "DONE"
173 rm -f $out
174 rm -rf /tmp/test-gnunetd-statistics/