diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 19:35:11 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 19:35:11 +0200 |
commit | ddfee3f564bff9c5d5719af3132d7869b8783ec4 (patch) | |
tree | e6fd7801fe6808797f3418bf081ab68d5a5ec27b /src/statistics/test_gnunet_statistics.py.in | |
parent | 852718c2473e41bc01ada0d53ad93c7da78e6ec8 (diff) | |
download | gnunet-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.in | 171 |
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 | |||
3 | import os | ||
4 | import sys | ||
5 | import shutil | ||
6 | import re | ||
7 | import subprocess | ||
8 | import time | ||
9 | |||
10 | raw_tmp = True | ||
11 | if os.name == "nt": | ||
12 | tmp = os.getenv("TEMP") | ||
13 | elif None != os.environ.get("TMPDIR"): | ||
14 | tmp = os.getenv("TMPDIR") | ||
15 | elif None != os.environ.get("TMP"): | ||
16 | tmp = os.getenv("TMP") | ||
17 | else: | ||
18 | raw_tmp = False | ||
19 | tmp = subprocess.check_output(["gnunet-config", "-f", "-s", "PATHS", "-o", "GNUNET_TMP"], | ||
20 | text=True) | ||
21 | |||
22 | if os.name == 'nt': | ||
23 | st = './gnunet-statistics.exe' | ||
24 | arm = 'gnunet-arm.exe' | ||
25 | else: | ||
26 | st = './gnunet-statistics' | ||
27 | arm = 'gnunet-arm' | ||
28 | |||
29 | run_st = [st, '-c', 'test_statistics_api_data.conf'] | ||
30 | run_arm = [arm, '-c', 'test_statistics_api_data.conf'] | ||
31 | debug = os.getenv('DEBUG') | ||
32 | if debug: | ||
33 | run_arm += [debug.split(' ')] | ||
34 | |||
35 | |||
36 | if raw_tmp: | ||
37 | cleanup_path = "gnunet/test-gnunet-statistics" | ||
38 | else: | ||
39 | cleanup_path = "test-gnunet-statistics" | ||
40 | |||
41 | |||
42 | def cleanup(): | ||
43 | shutil.rmtree(os.path.join(tmp, cleanup_path), True) | ||
44 | |||
45 | |||
46 | def 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 | |||
63 | def fail(result): | ||
64 | print(result) | ||
65 | r_arm(['-e'], want_stdo=False) | ||
66 | sys.exit(1) | ||
67 | |||
68 | |||
69 | def 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 | |||
76 | def 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 | |||
87 | def 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 | |||
95 | cleanup() | ||
96 | |||
97 | print("Preparing: Starting service...") | ||
98 | t = r_arm(['-s'], want_stdo=False) | ||
99 | time.sleep(1) | ||
100 | t = r_arm(['-i', 'statistics'], want_stdo=False) | ||
101 | time.sleep(1) | ||
102 | |||
103 | print("TEST: Bad argument checking...", end='') | ||
104 | r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True) | ||
105 | print("PASS") | ||
106 | |||
107 | print("TEST: Set value...", end='') | ||
108 | r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False) | ||
109 | print("PASS") | ||
110 | |||
111 | print("TEST: Set another value...", end='') | ||
112 | r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False) | ||
113 | print("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 | |||
121 | print("TEST: Viewing stats by name...", end='') | ||
122 | rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True) | ||
123 | if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1: | ||
124 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
125 | print("PASS") | ||
126 | |||
127 | print("TEST: Viewing stats by subsystem...", end='') | ||
128 | rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True) | ||
129 | if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1: | ||
130 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
131 | print("PASS") | ||
132 | |||
133 | print("TEST: Set persistent value...", end='') | ||
134 | rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], | ||
135 | nofail=True, | ||
136 | want_stdo=False) | ||
137 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) | ||
138 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: | ||
139 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
140 | print("PASS") | ||
141 | |||
142 | restart() | ||
143 | |||
144 | print("TEST: Checking persistence...", end='') | ||
145 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) | ||
146 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: | ||
147 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
148 | print("PASS") | ||
149 | |||
150 | print("TEST: Removing persistence...", end='') | ||
151 | rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], | ||
152 | nofail=True, | ||
153 | want_stdo=False) | ||
154 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) | ||
155 | if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0: | ||
156 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
157 | print("PASS") | ||
158 | |||
159 | restart() | ||
160 | |||
161 | print("TEST: Checking removed persistence...", end='') | ||
162 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) | ||
163 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0: | ||
164 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
165 | print("PASS") | ||
166 | |||
167 | print("Stopping service...") | ||
168 | t = r_arm(['-e'], want_stdo=False) | ||
169 | time.sleep(1) | ||
170 | |||
171 | cleanup() | ||