diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 14:17:54 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 14:17:54 +0200 |
commit | b4f068d6c7b111d0713e880dbffb06927450ebf1 (patch) | |
tree | b66f528d6af5c07cc311bc59f6d02f5e22e1f5a8 /src/arm/test_gnunet_arm.py.in | |
parent | 14d9446a7d2bf06dc03ba35f361bf0bbcd9e7b44 (diff) | |
download | gnunet-b4f068d6c7b111d0713e880dbffb06927450ebf1.tar.gz gnunet-b4f068d6c7b111d0713e880dbffb06927450ebf1.zip |
BUILD: Move arm to service/cli
Diffstat (limited to 'src/arm/test_gnunet_arm.py.in')
-rw-r--r-- | src/arm/test_gnunet_arm.py.in | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in deleted file mode 100644 index 2b30b6b97..000000000 --- a/src/arm/test_gnunet_arm.py.in +++ /dev/null | |||
@@ -1,129 +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 | # FIXME: There's too much repetition, move generally used parts into reusable modules. | ||
11 | if os.name == "nt": | ||
12 | tmp = os.getenv("TEMP") | ||
13 | else: | ||
14 | tmp = "/tmp" | ||
15 | |||
16 | if os.name == 'nt': | ||
17 | st = 'gnunet-statistics.exe' | ||
18 | arm = './gnunet-arm.exe' | ||
19 | else: | ||
20 | st = 'gnunet-statistics' | ||
21 | arm = './gnunet-arm' | ||
22 | |||
23 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] | ||
24 | debug = os.getenv('DEBUG') | ||
25 | if debug: | ||
26 | run_arm += [debug.split(' ')] | ||
27 | |||
28 | |||
29 | def cleanup(): | ||
30 | shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True) | ||
31 | |||
32 | |||
33 | def sub_run(args, want_stdo=True, want_stde=False, nofail=False): | ||
34 | if want_stdo: | ||
35 | stdo = subprocess.PIPE | ||
36 | else: | ||
37 | stdo = None | ||
38 | if want_stde: | ||
39 | stde = subprocess.PIPE | ||
40 | else: | ||
41 | stde = None | ||
42 | p = subprocess.Popen(args, stdout=stdo, stderr=stde) | ||
43 | stdo, stde = p.communicate() | ||
44 | if not nofail: | ||
45 | if p.returncode != 0: | ||
46 | sys.exit(p.returncode) | ||
47 | return (p.returncode, stdo, stde) | ||
48 | |||
49 | |||
50 | def fail(result): | ||
51 | print(result) | ||
52 | r_arm(['-e'], want_stdo=False) | ||
53 | sys.exit(1) | ||
54 | |||
55 | |||
56 | def end_arm_failure(command, rc, stdo, stde, normal): | ||
57 | if normal: | ||
58 | if rc != 0: | ||
59 | fail( | ||
60 | "FAIL: error running {}\nCommand output was:\n{}\n{}".format( | ||
61 | command, stdo, stde | ||
62 | ) | ||
63 | ) | ||
64 | else: | ||
65 | if rc == 0: | ||
66 | fail( | ||
67 | "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" | ||
68 | .format(command, stdo, stde) | ||
69 | ) | ||
70 | |||
71 | |||
72 | def print_only_failure(command, rc, stdo, stde, normal): | ||
73 | if normal: | ||
74 | if rc != 0: | ||
75 | print( | ||
76 | "FAIL: error running {}\nCommand output was:\n{}\n{}".format( | ||
77 | command, stdo, stde | ||
78 | ) | ||
79 | ) | ||
80 | sys.exit(1) | ||
81 | else: | ||
82 | if rc == 0: | ||
83 | print( | ||
84 | "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" | ||
85 | .format(command, stdo, stde) | ||
86 | ) | ||
87 | sys.exit(1) | ||
88 | |||
89 | |||
90 | def r_something(to_run, extra_args, failure=None, normal=True, **kw): | ||
91 | rc, stdo, stde = sub_run( | ||
92 | to_run + extra_args, nofail=True, want_stde=True, **kw | ||
93 | ) | ||
94 | if failure is not None: | ||
95 | failure(to_run + extra_args, rc, stdo, stde, normal) | ||
96 | return (rc, stdo, stde) | ||
97 | |||
98 | |||
99 | def r_arm(extra_args, **kw): | ||
100 | return r_something(run_arm, extra_args, **kw) | ||
101 | |||
102 | |||
103 | cleanup() | ||
104 | |||
105 | print("TEST: Bad argument checking...", end='') | ||
106 | r_arm(['-x'], normal=False, failure=print_only_failure) | ||
107 | print("PASS") | ||
108 | |||
109 | print("TEST: Start ARM...", end='') | ||
110 | r_arm(['-s'], failure=print_only_failure) | ||
111 | time.sleep(1) | ||
112 | print("PASS") | ||
113 | |||
114 | print("TEST: Start another service...", end='') | ||
115 | r_arm(['-i', 'resolver'], failure=end_arm_failure) | ||
116 | time.sleep(1) | ||
117 | print("PASS") | ||
118 | |||
119 | print("TEST: Stop a service...", end='') | ||
120 | r_arm(['-k', 'resolver'], failure=end_arm_failure) | ||
121 | time.sleep(1) | ||
122 | print("PASS") | ||
123 | |||
124 | print("TEST: Stop ARM...", end='') | ||
125 | r_arm(['-e'], failure=print_only_failure) | ||
126 | time.sleep(1) | ||
127 | print("PASS") | ||
128 | |||
129 | cleanup() | ||