diff options
author | Nils Gillmann <ng0@n0.is> | 2018-05-22 09:15:34 +0000 |
---|---|---|
committer | Nils Gillmann <ng0@n0.is> | 2018-05-22 09:15:34 +0000 |
commit | 043b52f76c21d5e74707c9dc4d379c8fed252dde (patch) | |
tree | 96b1e6800741e034cc0761fddec9e7781ae08077 /src/arm | |
parent | f2773a77de96ab405ac340973d915a50c2d5d98c (diff) | |
download | gnunet-043b52f76c21d5e74707c9dc4d379c8fed252dde.tar.gz gnunet-043b52f76c21d5e74707c9dc4d379c8fed252dde.zip |
More flakes
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/test_gnunet_arm.py.in | 185 |
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 | |||
7 | import subprocess | 7 | import subprocess |
8 | import time | 8 | import time |
9 | 9 | ||
10 | # FIXME: There's too much repetition, move generally used parts into reusable modules. | ||
10 | if os.name == "nt": | 11 | if os.name == "nt": |
11 | tmp = os.getenv ("TEMP") | 12 | tmp = os.getenv("TEMP") |
12 | else: | 13 | else: |
13 | tmp = "/tmp" | 14 | tmp = "/tmp" |
14 | 15 | ||
15 | if os.name == 'nt': | 16 | if os.name == 'nt': |
16 | st = 'gnunet-statistics.exe' | 17 | st = 'gnunet-statistics.exe' |
17 | arm = './gnunet-arm.exe' | 18 | arm = './gnunet-arm.exe' |
18 | else: | 19 | else: |
19 | st = 'gnunet-statistics' | 20 | st = 'gnunet-statistics' |
20 | arm = './gnunet-arm' | 21 | arm = './gnunet-arm' |
21 | 22 | ||
22 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] | 23 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] |
23 | debug = os.getenv ('DEBUG') | 24 | debug = os.getenv('DEBUG') |
24 | if debug: | 25 | if debug: |
25 | run_arm += [debug.split (' ')] | 26 | run_arm += [debug.split(' ')] |
26 | 27 | ||
27 | def cleanup (): | 28 | |
28 | shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True) | 29 | def cleanup(): |
29 | 30 | shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True) | |
30 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | 31 | |
31 | if want_stdo: | 32 | |
32 | stdo = subprocess.PIPE | 33 | def 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) | |
46 | def fail (result): | 47 | return (p.returncode, stdo, stde) |
47 | print (result) | 48 | |
48 | r_arm (['-e'], want_stdo = False) | 49 | |
49 | sys.exit (1) | 50 | def fail(result): |
50 | 51 | print(result) | |
51 | 52 | r_arm(['-e'], want_stdo=False) | |
52 | def 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)) | 56 | def 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: | |
60 | def 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) | 65 | def 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: | |
71 | def 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) | 76 | def 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) | |
77 | def 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) | |
80 | cleanup () | 81 | |
81 | 82 | ||
82 | print ("TEST: Bad argument checking...", end='') | 83 | def r_arm(extra_args, **kw): |
83 | r_arm (['-x'], normal = False, failer = print_only_failer) | 84 | return r_something(run_arm, extra_args, **kw) |
84 | print ("PASS") | 85 | |
85 | 86 | ||
86 | print ("TEST: Start ARM...", end='') | 87 | cleanup() |
87 | r_arm (['-s'], failer = print_only_failer) | 88 | |
88 | time.sleep (1) | 89 | print("TEST: Bad argument checking...", end='') |
89 | print ("PASS") | 90 | r_arm(['-x'], normal=False, failer=print_only_failer) |
90 | 91 | print("PASS") | |
91 | print ("TEST: Start another service...", end='') | 92 | |
92 | r_arm (['-i', 'resolver'], failer = end_arm_failer) | 93 | print("TEST: Start ARM...", end='') |
93 | time.sleep (1) | 94 | r_arm(['-s'], failer=print_only_failer) |
94 | print ("PASS") | 95 | time.sleep(1) |
95 | 96 | print("PASS") | |
96 | print ("TEST: Stop a service...", end='') | 97 | |
97 | r_arm (['-k', 'resolver'], failer = end_arm_failer) | 98 | print("TEST: Start another service...", end='') |
98 | time.sleep (1) | 99 | r_arm(['-i', 'resolver'], failer=end_arm_failer) |
99 | print ("PASS") | 100 | time.sleep(1) |
100 | 101 | print("PASS") | |
101 | print ("TEST: Stop ARM...", end='') | 102 | |
102 | r_arm (['-e'], failer = print_only_failer) | 103 | print("TEST: Stop a service...", end='') |
103 | time.sleep (1) | 104 | r_arm(['-k', 'resolver'], failer=end_arm_failer) |
104 | print ("PASS") | 105 | time.sleep(1) |
105 | 106 | print("PASS") | |
106 | cleanup () | 107 | |
108 | print("TEST: Stop ARM...", end='') | ||
109 | r_arm(['-e'], failer=print_only_failer) | ||
110 | time.sleep(1) | ||
111 | print("PASS") | ||
112 | |||
113 | cleanup() | ||