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