aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_arm.py.in
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 14:17:54 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 14:17:54 +0200
commitb4f068d6c7b111d0713e880dbffb06927450ebf1 (patch)
treeb66f528d6af5c07cc311bc59f6d02f5e22e1f5a8 /src/arm/test_gnunet_arm.py.in
parent14d9446a7d2bf06dc03ba35f361bf0bbcd9e7b44 (diff)
downloadgnunet-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.in129
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
3import os
4import sys
5import shutil
6import re
7import subprocess
8import time
9
10# FIXME: There's too much repetition, move generally used parts into reusable modules.
11if os.name == "nt":
12 tmp = os.getenv("TEMP")
13else:
14 tmp = "/tmp"
15
16if os.name == 'nt':
17 st = 'gnunet-statistics.exe'
18 arm = './gnunet-arm.exe'
19else:
20 st = 'gnunet-statistics'
21 arm = './gnunet-arm'
22
23run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
24debug = os.getenv('DEBUG')
25if debug:
26 run_arm += [debug.split(' ')]
27
28
29def cleanup():
30 shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True)
31
32
33def 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
50def fail(result):
51 print(result)
52 r_arm(['-e'], want_stdo=False)
53 sys.exit(1)
54
55
56def 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
72def 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
90def 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
99def r_arm(extra_args, **kw):
100 return r_something(run_arm, extra_args, **kw)
101
102
103cleanup()
104
105print("TEST: Bad argument checking...", end='')
106r_arm(['-x'], normal=False, failure=print_only_failure)
107print("PASS")
108
109print("TEST: Start ARM...", end='')
110r_arm(['-s'], failure=print_only_failure)
111time.sleep(1)
112print("PASS")
113
114print("TEST: Start another service...", end='')
115r_arm(['-i', 'resolver'], failure=end_arm_failure)
116time.sleep(1)
117print("PASS")
118
119print("TEST: Stop a service...", end='')
120r_arm(['-k', 'resolver'], failure=end_arm_failure)
121time.sleep(1)
122print("PASS")
123
124print("TEST: Stop ARM...", end='')
125r_arm(['-e'], failure=print_only_failure)
126time.sleep(1)
127print("PASS")
128
129cleanup()