use NULL value in load_path_suffix to NOT load any files
[oweals/gnunet.git] / src / arm / test_gnunet_arm.py.in
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_failer(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_failer(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, failer=None, normal=True, **kw):
91     rc, stdo, stde = sub_run(
92         to_run + extra_args, nofail=True, want_stde=True, **kw
93     )
94     if failer is not None:
95         failer(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, failer=print_only_failer)
107 print("PASS")
108
109 print("TEST: Start ARM...", end='')
110 r_arm(['-s'], failer=print_only_failer)
111 time.sleep(1)
112 print("PASS")
113
114 print("TEST: Start another service...", end='')
115 r_arm(['-i', 'resolver'], failer=end_arm_failer)
116 time.sleep(1)
117 print("PASS")
118
119 print("TEST: Stop a service...", end='')
120 r_arm(['-k', 'resolver'], failer=end_arm_failer)
121 time.sleep(1)
122 print("PASS")
123
124 print("TEST: Stop ARM...", end='')
125 r_arm(['-e'], failer=print_only_failer)
126 time.sleep(1)
127 print("PASS")
128
129 cleanup()