aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_gnunet_statistics.py.in
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/test_gnunet_statistics.py.in
parent078713080ee376ba8a490c70c474a1a2d22189c8 (diff)
downloadgnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.tar.gz
gnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.zip
-LRN: Python-based test script for statistics
Diffstat (limited to 'src/statistics/test_gnunet_statistics.py.in')
-rw-r--r--src/statistics/test_gnunet_statistics.py.in151
1 files changed, 151 insertions, 0 deletions
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 ()