aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_gnunet_arm.py.in
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-22 09:15:34 +0000
committerNils Gillmann <ng0@n0.is>2018-05-22 09:15:34 +0000
commit043b52f76c21d5e74707c9dc4d379c8fed252dde (patch)
tree96b1e6800741e034cc0761fddec9e7781ae08077 /src/arm/test_gnunet_arm.py.in
parentf2773a77de96ab405ac340973d915a50c2d5d98c (diff)
downloadgnunet-043b52f76c21d5e74707c9dc4d379c8fed252dde.tar.gz
gnunet-043b52f76c21d5e74707c9dc4d379c8fed252dde.zip
More flakes
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'src/arm/test_gnunet_arm.py.in')
-rw-r--r--src/arm/test_gnunet_arm.py.in185
1 files changed, 96 insertions, 89 deletions
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in
index cdd69251b..10bb58a9c 100644
--- a/src/arm/test_gnunet_arm.py.in
+++ b/src/arm/test_gnunet_arm.py.in
@@ -7,100 +7,107 @@ import re
7import subprocess 7import subprocess
8import time 8import time
9 9
10# FIXME: There's too much repetition, move generally used parts into reusable modules.
10if os.name == "nt": 11if os.name == "nt":
11 tmp = os.getenv ("TEMP") 12 tmp = os.getenv("TEMP")
12else: 13else:
13 tmp = "/tmp" 14 tmp = "/tmp"
14 15
15if os.name == 'nt': 16if os.name == 'nt':
16 st = 'gnunet-statistics.exe' 17 st = 'gnunet-statistics.exe'
17 arm = './gnunet-arm.exe' 18 arm = './gnunet-arm.exe'
18else: 19else:
19 st = 'gnunet-statistics' 20 st = 'gnunet-statistics'
20 arm = './gnunet-arm' 21 arm = './gnunet-arm'
21 22
22run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] 23run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
23debug = os.getenv ('DEBUG') 24debug = os.getenv('DEBUG')
24if debug: 25if debug:
25 run_arm += [debug.split (' ')] 26 run_arm += [debug.split(' ')]
26 27
27def cleanup (): 28
28 shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True) 29def cleanup():
29 30 shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True)
30def sub_run (args, want_stdo = True, want_stde = False, nofail = False): 31
31 if want_stdo: 32
32 stdo = subprocess.PIPE 33def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
33 else: 34 if want_stdo:
34 stdo = None 35 stdo = subprocess.PIPE
35 if want_stde: 36 else:
36 stde = subprocess.PIPE 37 stdo = None
37 else: 38 if want_stde:
38 stde = None 39 stde = subprocess.PIPE
39 p = subprocess.Popen (args, stdout = stdo, stderr = stde) 40 else:
40 stdo, stde = p.communicate () 41 stde = None
41 if not nofail: 42 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
42 if p.returncode != 0: 43 stdo, stde = p.communicate()
43 sys.exit (p.returncode) 44 if not nofail:
44 return (p.returncode, stdo, stde) 45 if p.returncode != 0:
45 46 sys.exit(p.returncode)
46def fail (result): 47 return (p.returncode, stdo, stde)
47 print (result) 48
48 r_arm (['-e'], want_stdo = False) 49
49 sys.exit (1) 50def fail(result):
50 51 print(result)
51 52 r_arm(['-e'], want_stdo=False)
52def end_arm_failer (command, rc, stdo, stde, normal): 53 sys.exit(1)
53 if normal: 54
54 if rc != 0: 55
55 fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) 56def end_arm_failer(command, rc, stdo, stde, normal):
56 else: 57 if normal:
57 if rc == 0: 58 if rc != 0:
58 fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) 59 fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
59 60 else:
60def print_only_failer (command, rc, stdo, stde, normal): 61 if rc == 0:
61 if normal: 62 fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
62 if rc != 0: 63
63 print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) 64
64 sys.exit (1) 65def print_only_failer(command, rc, stdo, stde, normal):
65 else: 66 if normal:
66 if rc == 0: 67 if rc != 0:
67 print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) 68 print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
68 sys.exit (1) 69 sys.exit(1)
69 70 else:
70 71 if rc == 0:
71def r_something (to_run, extra_args, failer = None, normal = True, **kw): 72 print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
72 rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = True, **kw) 73 sys.exit(1)
73 if failer is not None: 74
74 failer (to_run + extra_args, rc, stdo, stde, normal) 75
75 return (rc, stdo, stde) 76def r_something(to_run, extra_args, failer=None, normal=True, **kw):
76 77 rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, want_stde=True, **kw)
77def r_arm (extra_args, **kw): 78 if failer is not None:
78 return r_something (run_arm, extra_args, **kw) 79 failer(to_run + extra_args, rc, stdo, stde, normal)
79 80 return (rc, stdo, stde)
80cleanup () 81
81 82
82print ("TEST: Bad argument checking...", end='') 83def r_arm(extra_args, **kw):
83r_arm (['-x'], normal = False, failer = print_only_failer) 84 return r_something(run_arm, extra_args, **kw)
84print ("PASS") 85
85 86
86print ("TEST: Start ARM...", end='') 87cleanup()
87r_arm (['-s'], failer = print_only_failer) 88
88time.sleep (1) 89print("TEST: Bad argument checking...", end='')
89print ("PASS") 90r_arm(['-x'], normal=False, failer=print_only_failer)
90 91print("PASS")
91print ("TEST: Start another service...", end='') 92
92r_arm (['-i', 'resolver'], failer = end_arm_failer) 93print("TEST: Start ARM...", end='')
93time.sleep (1) 94r_arm(['-s'], failer=print_only_failer)
94print ("PASS") 95time.sleep(1)
95 96print("PASS")
96print ("TEST: Stop a service...", end='') 97
97r_arm (['-k', 'resolver'], failer = end_arm_failer) 98print("TEST: Start another service...", end='')
98time.sleep (1) 99r_arm(['-i', 'resolver'], failer=end_arm_failer)
99print ("PASS") 100time.sleep(1)
100 101print("PASS")
101print ("TEST: Stop ARM...", end='') 102
102r_arm (['-e'], failer = print_only_failer) 103print("TEST: Stop a service...", end='')
103time.sleep (1) 104r_arm(['-k', 'resolver'], failer=end_arm_failer)
104print ("PASS") 105time.sleep(1)
105 106print("PASS")
106cleanup () 107
108print("TEST: Stop ARM...", end='')
109r_arm(['-e'], failer=print_only_failer)
110time.sleep(1)
111print("PASS")
112
113cleanup()