aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-07-09 11:19:47 +0000
committerChristian Grothoff <christian@grothoff.org>2012-07-09 11:19:47 +0000
commit8bdc9a4b52d7b36c2beacdf645a64d4f200ec280 (patch)
tree155e887260cfe79fdae0bec16fe054d75802f8f8 /src/statistics
parent078713080ee376ba8a490c70c474a1a2d22189c8 (diff)
downloadgnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.tar.gz
gnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.zip
-LRN: Python-based test script for statistics
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/Makefile.am14
-rw-r--r--src/statistics/test_gnunet_statistics.py.in151
-rwxr-xr-xsrc/statistics/test_gnunet_statistics.sh199
3 files changed, 163 insertions, 201 deletions
diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am
index ddf5fda0e..5485a9c18 100644
--- a/src/statistics/Makefile.am
+++ b/src/statistics/Makefile.am
@@ -83,10 +83,20 @@ test_statistics_api_watch_zero_value_LDADD = \
83 $(top_builddir)/src/util/libgnunetutil.la 83 $(top_builddir)/src/util/libgnunetutil.la
84 84
85check_SCRIPTS = \ 85check_SCRIPTS = \
86 test_gnunet_statistics.sh 86 test_gnunet_statistics.py
87
88do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
89
90%.py: %.py.in Makefile
91 $(do_subst) < $(srcdir)/$< > $@
92 chmod +x $@
93
94test_gnunet_statistics.py: test_gnunet_statistics.py.in Makefile
95 $(do_subst) < $(srcdir)/test_gnunet_statistics.py.in > test_gnunet_statistics.py
96 chmod +x test_gnunet_statistics.py
87 97
88EXTRA_DIST = \ 98EXTRA_DIST = \
89 test_statistics_api_data.conf \ 99 test_statistics_api_data.conf \
90 $(check_SCRIPTS) 100 test_gnunet_statistics.py.in
91 101
92 102
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
new file mode 100644
index 000000000..b5697d246
--- /dev/null
+++ b/src/statistics/test_gnunet_statistics.py.in
@@ -0,0 +1,151 @@
1#!@PYTHON@
2from __future__ import print_function
3import os
4import sys
5import shutil
6import re
7import subprocess
8import time
9
10if os.name == "nt":
11 tmp = os.getenv ("TEMP")
12else:
13 tmp = "/tmp"
14
15if os.name == 'nt':
16 st = 'gnunet-statistics.exe'
17 arm = 'gnunet-arm.exe'
18else:
19 st = 'gnunet-statistics'
20 arm = 'gnunet-arm'
21
22run_st = [st, '-c', 'test_statistics_api_data.conf']
23run_arm = [arm, '-c', 'test_statistics_api_data.conf']
24debug = os.getenv ('DEBUG')
25if debug:
26 run_arm += [debug.split (' ')]
27
28def cleanup ():
29 shutil.rmtree (os.path.join (tmp, "test-gnunetd-statistics"), True)
30
31def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
32 if want_stdo:
33 stdo = subprocess.PIPE
34 else:
35 stdo = None
36 if want_stde:
37 stde = subprocess.PIPE
38 else:
39 stde = None
40 p = subprocess.Popen (args, stdout = stdo, stderr = stde)
41 stdo, stde = p.communicate ()
42 if not nofail:
43 if p.returncode != 0:
44 sys.exit (p.returncode)
45 return (p.returncode, stdo, stde)
46
47def fail (result):
48 print (result)
49 r_arm (['-e'], want_stdo = False)
50 sys.exit (1)
51
52def r_arm (extra_args, **kw):
53 rc, stdo, stde = sub_run (run_arm + extra_args, **kw)
54 if rc != 0:
55 fail ("FAIL: error running {}".format (run_arm))
56 return (rc, stdo, stde)
57
58def r_st (extra_args, normal = True, **kw):
59 rc, stdo, stde = sub_run (run_st + extra_args, **kw)
60 if normal:
61 if rc != 0:
62 fail ("FAIL: error running {}".format (run_st))
63 else:
64 if rc == 0:
65 fail ("FAIL: expected error while running {}".format (run_st))
66 return (rc, stdo, stde)
67
68def restart ():
69 print ("Restarting service...")
70 t = r_arm (['-k', 'statistics'])
71 time.sleep (1)
72 t = r_arm (['-i', 'statistics'])
73 time.sleep (1)
74 print ("DONE")
75
76
77cleanup ()
78
79print ("Preparing: Starting service...")
80t = r_arm (['-s'], want_stdo = False)
81time.sleep (1)
82t = r_arm (['-i', 'statistics'], want_stdo = False)
83time.sleep (1)
84print ("DONE")
85
86print ("TEST: Bad argument checking...", end='')
87r_st (['-x'], normal = False, nofail = True, want_stdo = False)
88print ("PASS")
89
90print ("TEST: Set value...", end='')
91r_st (['-n', 'test', '-s', 'subsystem', '42'], nofail = True, want_stdo = False)
92print ("PASS")
93
94print ("TEST: Set another value...", end='')
95r_st (['-n', 'other', '-s', 'osystem', '43'], nofail = True, want_stdo = False)
96print ("PASS")
97
98print ("TEST: Viewing all stats...", end='')
99rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
100if len (stdo.splitlines ()) != 2:
101 fail ("FAIL: unexpected output:\n{}".format (stdo))
102print ("PASS")
103
104print ("TEST: Viewing stats by name...", end='')
105rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True)
106if len ([x for x in stdo.splitlines () if re.search ('43', x)]) != 1:
107 fail ("FAIL: unexpected output:\n{}".format (stdo))
108print ("PASS")
109
110print ("TEST: Viewing stats by subsystem...", end='')
111rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True)
112if len ([x for x in stdo.splitlines () if re.search ('42', x)]) != 1:
113 fail ("FAIL: unexpected output:\n{}".format (stdo))
114print ("PASS")
115
116print ("TEST: Set persistent value...", end='')
117rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False)
118rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
119if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
120 fail ("FAIL: unexpected output:\n{}".format (stdo))
121print ("PASS")
122
123restart ()
124
125print ("TEST: Checking persistence...", end='')
126rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
127if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
128 fail ("FAIL: unexpected output:\n{}".format (stdo))
129print ("PASS")
130
131print ("TEST: Removing persistence...", end='')
132rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False)
133rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
134if len ([x for x in stdo.splitlines () if re.search ('!', x)]) != 0:
135 fail ("FAIL: unexpected output:\n{}".format (stdo))
136print ("PASS")
137
138restart ()
139
140print ("TEST: Checking removed persistence...", end='')
141rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
142if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 0:
143 fail ("FAIL: unexpected output:\n{}".format (stdo))
144print ("PASS")
145
146print ("Stopping service...")
147t = r_arm (['-e'], want_stdo = False)
148time.sleep (1)
149print ("DONE")
150
151cleanup ()
diff --git a/src/statistics/test_gnunet_statistics.sh b/src/statistics/test_gnunet_statistics.sh
deleted file mode 100755
index eb2d618d9..000000000
--- a/src/statistics/test_gnunet_statistics.sh
+++ /dev/null
@@ -1,199 +0,0 @@
1#!/bin/sh
2
3rm -rf /tmp/test-gnunetd-statistics/
4exe="./gnunet-statistics -c test_statistics_api_data.conf"
5out=`mktemp /tmp/test-gnunet-statistics-logXXXXXXXX`
6arm="gnunet-arm -c test_statistics_api_data.conf $DEBUG"
7#DEBUG="-L DEBUG"
8# -----------------------------------
9echo -n "Preparing: Starting service..."
10
11$arm -s > /dev/null
12sleep 1
13$arm -i statistics > /dev/null
14sleep 1
15echo "DONE"
16
17# ----------------------------------------------------------------------------------
18echo -n "TEST: Bad argument checking..."
19
20if $exe -x 2> /dev/null; then
21 echo "FAIL: error running $exe"
22 $arm -e
23 exit 1
24fi
25echo "PASS"
26
27# ----------------------------------------------------------------------------------
28echo -n "TEST: Set value..."
29
30if ! $exe $DEBUG -n test -s subsystem 42 ; then
31 echo "FAIL: error running $exe"
32 $arm -e
33 exit 1
34fi
35echo "PASS"
36
37# ----------------------------------------------------------------------------------
38echo -n "TEST: Set another value..."
39
40if ! $exe $DEBUG -n other -s osystem 43 ; then
41 echo "FAIL: error running $exe"
42 $arm -e
43 exit 1
44fi
45echo "PASS"
46
47# ----------------------------------------------------------------------------------
48echo -n "TEST: viewing all stats..."
49
50if ! $exe $DEBUG > $out; then
51 echo "FAIL: error running $exe"
52 $arm -e
53 exit 1
54fi
55LINES=`cat $out | wc -l`
56if test $LINES -ne 2; then
57 echo "FAIL: unexpected output"
58 $arm -e
59 exit 1
60fi
61echo "PASS"
62
63# ----------------------------------------------------------------------------------
64echo -n "TEST: viewing stats by name..."
65
66if ! $exe $DEBUG -n other > $out; then
67 echo "FAIL: error running $exe"
68 $arm -e
69 exit 1
70fi
71LINES=`cat $out | grep 43 | wc -l`
72if test $LINES -ne 1; then
73 echo "FAIL: unexpected output"
74 $arm -e
75 exit 1
76fi
77echo "PASS"
78
79# ----------------------------------------------------------------------------------
80echo -n "TEST: viewing stats by subsystem..."
81
82if ! $exe $DEBUG -s subsystem > $out; then
83 echo "FAIL: error running $exe"
84 $arm -e
85 exit 1
86fi
87LINES=`cat $out | grep 42 | wc -l`
88if test $LINES -ne 1; then
89 echo "FAIL: unexpected output"
90 $arm -e
91 exit 1
92fi
93echo "PASS"
94
95
96# ----------------------------------------------------------------------------------
97echo -n "TEST: Set persistent value..."
98
99if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
100 echo "FAIL: error running $exe"
101 $arm -e
102 exit 1
103fi
104if ! $exe $DEBUG > $out; then
105 echo "FAIL: error running $exe"
106 $arm -e
107 exit 1
108fi
109LINES=`cat $out | grep 40 | wc -l`
110if test $LINES -ne 1; then
111 echo "FAIL: unexpected output"
112 cat $out
113 $arm -e
114 exit 1
115fi
116echo "PASS"
117
118# -----------------------------------
119echo -n "Restarting service..."
120$arm -k statistics > /dev/null
121sleep 1
122$arm -i statistics > /dev/null
123sleep 1
124echo "DONE"
125
126# ----------------------------------------------------------------------------------
127echo -n "TEST: checking persistence..."
128
129if ! $exe $DEBUG > $out; then
130 echo "FAIL: error running $exe"
131 $arm -e
132 exit 1
133fi
134LINES=`cat $out | grep 40 | wc -l`
135if test $LINES -ne 1; then
136 echo "FAIL: unexpected output"
137 cat $out
138 $arm -e
139 exit 1
140fi
141echo "PASS"
142
143
144
145# ----------------------------------------------------------------------------------
146echo -n "TEST: Removing persistence..."
147
148if ! $exe $DEBUG -n lasting -s subsystem 40; then
149 echo "FAIL: error running $exe"
150 $arm -e
151 exit 1
152fi
153if ! $exe $DEBUG > $out; then
154 echo "FAIL: error running $exe"
155 $arm -e
156 exit 1
157fi
158LINES=`cat $out | grep \! | wc -l`
159if test $LINES -ne 0; then
160 echo "FAIL: unexpected output"
161 cat $out
162 $arm -e
163 exit 1
164fi
165echo "PASS"
166
167
168# -----------------------------------
169echo -n "Restarting service..."
170$arm -k statistics > /dev/null
171sleep 1
172$arm -i statistics > /dev/null
173sleep 1
174echo "DONE"
175
176# ----------------------------------------------------------------------------------
177echo -n "TEST: checking removed persistence..."
178
179if ! $exe $DEBUG > $out; then
180 echo "FAIL: error running $exe"
181 $arm -e
182 exit 1
183fi
184LINES=`cat $out | grep 40 | wc -l`
185if test $LINES -ne 0; then
186 echo "FAIL: unexpected output"
187 cat $out
188 $arm -e
189 exit 1
190fi
191echo "PASS"
192
193# -----------------------------------
194echo -n "Stopping service..."
195$arm -e > /dev/null
196sleep 1
197echo "DONE"
198rm -f $out
199rm -rf /tmp/test-gnunetd-statistics/