aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_gnunet_statistics.sh
blob: eb2d618d9ac3c8f354e1d032113b9b56eceffaa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/sh

rm -rf /tmp/test-gnunetd-statistics/
exe="./gnunet-statistics -c test_statistics_api_data.conf"
out=`mktemp /tmp/test-gnunet-statistics-logXXXXXXXX`
arm="gnunet-arm -c test_statistics_api_data.conf $DEBUG"
#DEBUG="-L DEBUG"
# -----------------------------------
echo -n "Preparing: Starting service..."

$arm -s > /dev/null
sleep 1
$arm -i statistics > /dev/null
sleep 1 
echo "DONE"

# ----------------------------------------------------------------------------------
echo -n "TEST: Bad argument checking..."

if $exe -x 2> /dev/null; then
  echo "FAIL: error running $exe"
  $arm -e
  exit 1
fi
echo "PASS"

# ----------------------------------------------------------------------------------
echo -n "TEST: Set value..."

if ! $exe $DEBUG -n test -s subsystem 42 ; then
  echo "FAIL: error running $exe"
  $arm -e
  exit 1
fi
echo "PASS"

# ----------------------------------------------------------------------------------
echo -n "TEST: Set another value..."

if ! $exe $DEBUG -n other -s osystem 43 ; then
  echo "FAIL: error running $exe"
  $arm -e
  exit 1
fi
echo "PASS"

# ----------------------------------------------------------------------------------
echo -n "TEST: viewing all stats..."

if ! $exe $DEBUG > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | wc -l`
if test $LINES -ne 2; then
    echo "FAIL: unexpected output"
    $arm -e
    exit 1
fi
echo "PASS"

# ----------------------------------------------------------------------------------
echo -n "TEST: viewing stats by name..."

if ! $exe $DEBUG -n other > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep 43 | wc -l`
if test $LINES -ne 1; then
    echo "FAIL: unexpected output"
    $arm -e
    exit 1
fi
echo "PASS"

# ----------------------------------------------------------------------------------
echo -n "TEST: viewing stats by subsystem..."

if ! $exe $DEBUG -s subsystem > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep 42 | wc -l`
if test $LINES -ne 1; then
    echo "FAIL: unexpected output"
    $arm -e
    exit 1
fi
echo "PASS"


# ----------------------------------------------------------------------------------
echo -n "TEST: Set persistent value..."

if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
  echo "FAIL: error running $exe"
  $arm -e
  exit 1
fi
if ! $exe $DEBUG > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep 40 | wc -l`
if test $LINES -ne 1; then
    echo "FAIL: unexpected output"
    cat $out
    $arm -e
    exit 1
fi
echo "PASS"

# -----------------------------------
echo -n "Restarting service..."
$arm -k statistics > /dev/null
sleep 1
$arm -i statistics > /dev/null
sleep 1
echo "DONE"

# ----------------------------------------------------------------------------------
echo -n "TEST: checking persistence..."

if ! $exe $DEBUG > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep 40 | wc -l`
if test $LINES -ne 1; then
    echo "FAIL: unexpected output"
    cat $out
    $arm -e
    exit 1
fi
echo "PASS"



# ----------------------------------------------------------------------------------
echo -n "TEST: Removing persistence..."

if ! $exe  $DEBUG -n lasting -s subsystem 40; then
  echo "FAIL: error running $exe"
  $arm -e
  exit 1
fi
if ! $exe $DEBUG > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep \! | wc -l`
if test $LINES -ne 0; then
    echo "FAIL: unexpected output"
    cat $out
    $arm -e
    exit 1
fi
echo "PASS"


# -----------------------------------
echo -n "Restarting service..."
$arm -k statistics > /dev/null
sleep 1
$arm -i statistics > /dev/null
sleep 1
echo "DONE"

# ----------------------------------------------------------------------------------
echo -n "TEST: checking removed persistence..."

if ! $exe $DEBUG > $out; then
    echo "FAIL: error running $exe"
    $arm -e
    exit 1
fi
LINES=`cat $out | grep 40 | wc -l`
if test $LINES -ne 0; then
    echo "FAIL: unexpected output"
    cat $out
    $arm -e
    exit 1
fi
echo "PASS"

# -----------------------------------
echo -n "Stopping service..."
$arm -e > /dev/null
sleep 1
echo "DONE"
rm -f $out
rm -rf /tmp/test-gnunetd-statistics/