2 from __future__ import print_function
11 tmp = os.getenv ("TEMP")
16 st = 'gnunet-statistics.exe'
17 arm = './gnunet-arm.exe'
19 st = 'gnunet-statistics'
22 run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
23 debug = os.getenv ('DEBUG')
25 run_arm += [debug.split (' ')]
28 shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True)
30 def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
32 stdo = subprocess.PIPE
36 stde = subprocess.PIPE
39 p = subprocess.Popen (args, stdout = stdo, stderr = stde)
40 stdo, stde = p.communicate ()
43 sys.exit (p.returncode)
44 return (p.returncode, stdo, stde)
48 r_arm (['-e'], want_stdo = False)
52 def end_arm_failer (command, rc, stdo, stde, normal):
55 fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
58 fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
60 def print_only_failer (command, rc, stdo, stde, normal):
63 print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
67 print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
71 def 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)
77 def r_arm (extra_args, **kw):
78 return r_something (run_arm, extra_args, **kw)
82 print ("TEST: Bad argument checking...", end='')
83 r_arm (['-x'], normal = False, failer = print_only_failer)
86 print ("TEST: Start ARM...", end='')
87 r_arm (['-s'], failer = print_only_failer)
91 print ("TEST: Start another service...", end='')
92 r_arm (['-i', 'resolver'], failer = end_arm_failer)
96 print ("TEST: Stop a service...", end='')
97 r_arm (['-k', 'resolver'], failer = end_arm_failer)
101 print ("TEST: Stop ARM...", end='')
102 r_arm (['-e'], failer = print_only_failer)