10 # FIXME: There's too much repetition, move generally used parts into reusable modules.
12 tmp = os.getenv("TEMP")
17 st = 'gnunet-statistics.exe'
18 arm = './gnunet-arm.exe'
20 st = 'gnunet-statistics'
23 run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
24 debug = os.getenv('DEBUG')
26 run_arm += [debug.split(' ')]
30 shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True)
33 def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
35 stdo = subprocess.PIPE
39 stde = subprocess.PIPE
42 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
43 stdo, stde = p.communicate()
46 sys.exit(p.returncode)
47 return (p.returncode, stdo, stde)
52 r_arm(['-e'], want_stdo=False)
56 def end_arm_failer(command, rc, stdo, stde, normal):
60 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
67 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
68 .format(command, stdo, stde)
72 def print_only_failer(command, rc, stdo, stde, normal):
76 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
84 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
85 .format(command, stdo, stde)
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
94 if failer is not None:
95 failer(to_run + extra_args, rc, stdo, stde, normal)
96 return (rc, stdo, stde)
99 def r_arm(extra_args, **kw):
100 return r_something(run_arm, extra_args, **kw)
105 print("TEST: Bad argument checking...", end='')
106 r_arm(['-x'], normal=False, failer=print_only_failer)
109 print("TEST: Start ARM...", end='')
110 r_arm(['-s'], failer=print_only_failer)
114 print("TEST: Start another service...", end='')
115 r_arm(['-i', 'resolver'], failer=end_arm_failer)
119 print("TEST: Stop a service...", end='')
120 r_arm(['-k', 'resolver'], failer=end_arm_failer)
124 print("TEST: Stop ARM...", end='')
125 r_arm(['-e'], failer=print_only_failer)