aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_arm.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/test_gnunet_arm.py.in')
-rw-r--r--src/arm/test_gnunet_arm.py.in106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in
new file mode 100644
index 000000000..c7698a3ce
--- /dev/null
+++ b/src/arm/test_gnunet_arm.py.in
@@ -0,0 +1,106 @@
1#!@PYTHON@
2from __future__ import print_function
3import os
4import sys
5import shutil
6import re
7import subprocess
8import time
9
10if os.name == "nt":
11 tmp = os.getenv ("TEMP")
12else:
13 tmp = "/tmp"
14
15if os.name == 'nt':
16 st = 'gnunet-statistics.exe'
17 arm = 'gnunet-arm.exe'
18else:
19 st = 'gnunet-statistics'
20 arm = 'gnunet-arm'
21
22run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
23debug = os.getenv ('DEBUG')
24if debug:
25 run_arm += [debug.split (' ')]
26
27def cleanup ():
28 shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True)
29
30def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
31 if want_stdo:
32 stdo = subprocess.PIPE
33 else:
34 stdo = None
35 if want_stde:
36 stde = subprocess.PIPE
37 else:
38 stde = None
39 p = subprocess.Popen (args, stdout = stdo, stderr = stde)
40 stdo, stde = p.communicate ()
41 if not nofail:
42 if p.returncode != 0:
43 sys.exit (p.returncode)
44 return (p.returncode, stdo, stde)
45
46def fail (result):
47 print (result)
48 r_arm (['-e'], want_stdo = False)
49 sys.exit (1)
50
51
52def end_arm_failer (command, rc, stdo, stde, normal):
53 if normal:
54 if rc != 0:
55 fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
56 else:
57 if rc == 0:
58 fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
59
60def print_only_failer (command, rc, stdo, stde, normal):
61 if normal:
62 if rc != 0:
63 print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
64 sys.exit (1)
65 else:
66 if rc == 0:
67 print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
68 sys.exit (1)
69
70
71def r_something (to_run, extra_args, failer = None, normal = True, **kw):
72 rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = True, **kw)
73 if failer is not None:
74 failer (to_run + extra_args, rc, stdo, stde, normal)
75 return (rc, stdo, stde)
76
77def r_arm (extra_args, **kw):
78 return r_something (run_arm, extra_args, **kw)
79
80cleanup ()
81
82print ("TEST: Bad argument checking...", end='')
83r_arm (['-x'], normal = False, failer = print_only_failer)
84print ("PASS")
85
86print ("TEST: Start ARM...", end='')
87r_arm (['-s'], failer = print_only_failer)
88time.sleep (1)
89print ("PASS")
90
91print ("TEST: Start another service...", end='')
92r_arm (['-i', 'resolver'], failer = end_arm_failer)
93time.sleep (1)
94print ("PASS")
95
96print ("TEST: Stop a service...", end='')
97r_arm (['-k', 'resolver'], failer = end_arm_failer)
98time.sleep (1)
99print ("PASS")
100
101print ("TEST: Stop ARM...", end='')
102r_arm (['-e'], failer = print_only_failer)
103time.sleep (1)
104print ("PASS")
105
106cleanup ()