aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_gnunet_statistics.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_gnunet_statistics.py.in')
-rw-r--r--src/statistics/test_gnunet_statistics.py.in162
1 files changed, 0 insertions, 162 deletions
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
deleted file mode 100644
index ce277b13e..000000000
--- a/src/statistics/test_gnunet_statistics.py.in
+++ /dev/null
@@ -1,162 +0,0 @@
1#!@PYTHONEXE@
2
3import os
4import sys
5import shutil
6import re
7import subprocess
8import time
9
10if os.name == "nt":
11 tmp = os.getenv("TEMP")
12elif None != os.environ.get("TMPDIR"):
13 tmp = os.getenv("TMPDIR")
14elif None != os.environ.get("TMP"):
15 tmp = os.getenv("TMP")
16else:
17 tmp = "/tmp"
18
19if os.name == 'nt':
20 st = './gnunet-statistics.exe'
21 arm = 'gnunet-arm.exe'
22else:
23 st = './gnunet-statistics'
24 arm = 'gnunet-arm'
25
26run_st = [st, '-c', 'test_statistics_api_data.conf']
27run_arm = [arm, '-c', 'test_statistics_api_data.conf']
28debug = os.getenv('DEBUG')
29if debug:
30 run_arm += [debug.split(' ')]
31
32
33def cleanup():
34 shutil.rmtree(os.path.join(tmp, "gnunet/test-gnunet-statistics"), True)
35
36
37def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
38 if want_stdo:
39 stdo = subprocess.PIPE
40 else:
41 stdo = None
42 if want_stde:
43 stde = subprocess.PIPE
44 else:
45 stde = None
46 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
47 stdo, stde = p.communicate()
48 if not nofail:
49 if p.returncode != 0:
50 sys.exit(p.returncode)
51 return (p.returncode, stdo, stde)
52
53
54def fail(result):
55 print(result)
56 r_arm(['-e'], want_stdo=False)
57 sys.exit(1)
58
59
60def r_arm(extra_args, **kw):
61 rc, stdo, stde = sub_run(run_arm + extra_args, **kw)
62 if rc != 0:
63 fail("FAIL: error running {}".format(run_arm))
64 return (rc, stdo, stde)
65
66
67def r_st(extra_args, normal=True, **kw):
68 rc, stdo, stde = sub_run(run_st + extra_args, **kw)
69 if normal:
70 if rc != 0:
71 fail("FAIL: error running {}".format(run_st))
72 else:
73 if rc == 0:
74 fail("FAIL: expected error while running {}".format(run_st))
75 return (rc, stdo, stde)
76
77
78def restart():
79 print("Restarting service...")
80 t = r_arm(['-k', 'statistics'])
81 time.sleep(1)
82 t = r_arm(['-i', 'statistics'])
83 time.sleep(1)
84
85
86cleanup()
87
88print("Preparing: Starting service...")
89t = r_arm(['-s'], want_stdo=False)
90time.sleep(1)
91t = r_arm(['-i', 'statistics'], want_stdo=False)
92time.sleep(1)
93
94print("TEST: Bad argument checking...", end='')
95r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True)
96print("PASS")
97
98print("TEST: Set value...", end='')
99r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False)
100print("PASS")
101
102print("TEST: Set another value...", end='')
103r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False)
104print("PASS")
105
106print("TEST: Viewing all stats...", end='')
107rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
108if len(stdo.splitlines()) != 2:
109 fail("FAIL: unexpected output:\n{}".format(stdo))
110print("PASS")
111
112print("TEST: Viewing stats by name...", end='')
113rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True)
114if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1:
115 fail("FAIL: unexpected output:\n{}".format(stdo))
116print("PASS")
117
118print("TEST: Viewing stats by subsystem...", end='')
119rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True)
120if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1:
121 fail("FAIL: unexpected output:\n{}".format(stdo))
122print("PASS")
123
124print("TEST: Set persistent value...", end='')
125rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'],
126 nofail=True,
127 want_stdo=False)
128rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
129if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
130 fail("FAIL: unexpected output:\n{}".format(stdo))
131print("PASS")
132
133restart()
134
135print("TEST: Checking persistence...", end='')
136rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
137if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
138 fail("FAIL: unexpected output:\n{}".format(stdo))
139print("PASS")
140
141print("TEST: Removing persistence...", end='')
142rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'],
143 nofail=True,
144 want_stdo=False)
145rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
146if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0:
147 fail("FAIL: unexpected output:\n{}".format(stdo))
148print("PASS")
149
150restart()
151
152print("TEST: Checking removed persistence...", end='')
153rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
154if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0:
155 fail("FAIL: unexpected output:\n{}".format(stdo))
156print("PASS")
157
158print("Stopping service...")
159t = r_arm(['-e'], want_stdo=False)
160time.sleep(1)
161
162cleanup()