code clean up
[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 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 > $base.out; then
51     echo "FAIL: error running $exe"
52     $arm -e
53     exit 1
54 fi
55 LINES=`cat $base.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 > $base.out; then
67     echo "FAIL: error running $exe"
68     $arm -e
69     exit 1
70 fi
71 LINES=`cat $base.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 > $base.out; then
83     echo "FAIL: error running $exe"
84     $arm -e
85     exit 1
86 fi
87 LINES=`cat $base.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 > $base.out; then
118     echo "FAIL: error running $exe"
119     $arm -e
120     exit 1
121 fi
122 LINES=`cat $base.out | grep 40 | wc -l`
123 if test $LINES -ne 1; then
124     echo "FAIL: unexpected output"
125     $arm -e
126     exit 1
127 fi
128 echo "PASS"
129
130
131
132 # ----------------------------------------------------------------------------------
133 echo -n "TEST: Removing persistence..."
134
135 if ! $exe  $DEBUG -n lasting -s subsystem 40; then
136   echo "FAIL: error running $exe"
137   $arm -e
138   exit 1
139 fi
140 echo "PASS"
141
142
143 # -----------------------------------
144 echo -n "Restarting service..."
145 $arm -k statistics > /dev/null
146 sleep 1
147 $arm -i statistics > /dev/null
148 sleep 1
149 echo "DONE"
150
151 # ----------------------------------------------------------------------------------
152 echo -n "TEST: checking removed persistence..."
153
154 if ! $exe $DEBUG > $base.out; then
155     echo "FAIL: error running $exe"
156     $arm -e
157     exit 1
158 fi
159 LINES=`cat $base.out | grep 40 | wc -l`
160 if test $LINES -ne 0; then
161     echo "FAIL: unexpected output"
162     $arm -e
163     exit 1
164 fi
165 echo "PASS"
166
167 # -----------------------------------
168 echo -n "Stopping service..."
169 $arm -e > /dev/null
170 sleep 1
171 echo "DONE"
172 rm -f $base.out
173 rm -rf /tmp/test-gnunetd-statistics/