diff options
author | Nils Gillmann <ng0@n0.is> | 2018-05-22 09:26:21 +0000 |
---|---|---|
committer | Nils Gillmann <ng0@n0.is> | 2018-05-22 09:26:21 +0000 |
commit | 067f31e6e330b5348f0979364de7e4038d4594e7 (patch) | |
tree | 5953a77446772ca996c35d82afd5d7edfecf9b88 /src/dht | |
parent | 043b52f76c21d5e74707c9dc4d379c8fed252dde (diff) | |
download | gnunet-067f31e6e330b5348f0979364de7e4038d4594e7.tar.gz gnunet-067f31e6e330b5348f0979364de7e4038d4594e7.zip |
++
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/test_dht_tools.py.in | 184 |
1 files changed, 96 insertions, 88 deletions
diff --git a/src/dht/test_dht_tools.py.in b/src/dht/test_dht_tools.py.in index 2d4ab9adc..05582cbd0 100644 --- a/src/dht/test_dht_tools.py.in +++ b/src/dht/test_dht_tools.py.in | |||
@@ -21,105 +21,113 @@ import subprocess | |||
21 | import time | 21 | import time |
22 | import tempfile | 22 | import tempfile |
23 | 23 | ||
24 | os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]; | 24 | os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"] |
25 | 25 | ||
26 | if os.name == "nt": | 26 | if os.name == "nt": |
27 | tmp = os.getenv ("TEMP") | 27 | tmp = os.getenv("TEMP") |
28 | else: | 28 | else: |
29 | tmp = "/tmp" | 29 | tmp = "/tmp" |
30 | 30 | ||
31 | if os.name == 'nt': | 31 | if os.name == 'nt': |
32 | get = './gnunet-dht-get.exe' | 32 | get = './gnunet-dht-get.exe' |
33 | put = './gnunet-dht-put.exe' | 33 | put = './gnunet-dht-put.exe' |
34 | arm = 'gnunet-arm.exe' | 34 | arm = 'gnunet-arm.exe' |
35 | else: | 35 | else: |
36 | get = './gnunet-dht-get' | 36 | get = './gnunet-dht-get' |
37 | put = './gnunet-dht-put' | 37 | put = './gnunet-dht-put' |
38 | arm = 'gnunet-arm' | 38 | arm = 'gnunet-arm' |
39 | 39 | ||
40 | cfgfile = 'test_dht_api_peer1.conf' | 40 | cfgfile = 'test_dht_api_peer1.conf' |
41 | |||
42 | run_get = [get, '-c', cfgfile] | 41 | run_get = [get, '-c', cfgfile] |
43 | run_put = [put, '-c', cfgfile] | 42 | run_put = [put, '-c', cfgfile] |
44 | run_arm = [arm, '-c', cfgfile] | 43 | run_arm = [arm, '-c', cfgfile] |
45 | debug = os.getenv ('DEBUG') | 44 | debug = os.getenv('DEBUG') |
46 | if debug: | 45 | if debug: |
47 | run_arm += [debug.split (' ')] | 46 | run_arm += [debug.split(' ')] |
48 | 47 | ||
49 | def cleanup (exitcode): | 48 | |
50 | sys.exit (exitcode) | 49 | def cleanup(exitcode): |
51 | 50 | sys.exit(exitcode) | |
52 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | 51 | |
53 | if want_stdo: | 52 | |
54 | stdo = subprocess.PIPE | 53 | def sub_run(args, want_stdo=True, want_stde=False, nofail=False): |
55 | else: | 54 | if want_stdo: |
56 | stdo = None | 55 | stdo = subprocess.PIPE |
57 | if want_stde: | 56 | else: |
58 | stde = subprocess.PIPE | 57 | stdo = None |
59 | else: | 58 | if want_stde: |
60 | stde = None | 59 | stde = subprocess.PIPE |
61 | p = subprocess.Popen (args, stdout = stdo, stderr = stde) | 60 | else: |
62 | stdo, stde = p.communicate () | 61 | stde = None |
63 | if not nofail: | 62 | p = subprocess.Popen(args, stdout=stdo, stderr=stde) |
64 | if p.returncode != 0: | 63 | stdo, stde = p.communicate() |
65 | sys.exit (p.returncode) | 64 | if not nofail: |
66 | return (p.returncode, stdo, stde) | 65 | if p.returncode != 0: |
67 | 66 | sys.exit(p.returncode) | |
68 | def fail (result): | 67 | return (p.returncode, stdo, stde) |
69 | print (result) | 68 | |
70 | r_arm (['-e'], want_stdo = False) | 69 | |
71 | cleanup (1) | 70 | def fail(result): |
72 | 71 | print(result) | |
73 | def r_something (to_run, extra_args, failer = None, normal = True, **kw): | 72 | r_arm(['-e'], want_stdo=False) |
74 | rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, **kw) | 73 | cleanup(1) |
75 | if failer is not None: | 74 | |
76 | failer (to_run + extra_args, rc, stdo, stde, normal) | 75 | |
77 | return (rc, stdo, stde) | 76 | def r_something(to_run, extra_args, failer=None, normal=True, **kw): |
78 | 77 | rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, **kw) | |
79 | def r_arm (extra_args, **kw): | 78 | if failer is not None: |
80 | return r_something (run_arm, extra_args, **kw) | 79 | failer(to_run + extra_args, rc, stdo, stde, normal) |
81 | 80 | return (rc, stdo, stde) | |
82 | def r_get (extra_args, **kw): | 81 | |
83 | return r_something (run_get, extra_args, **kw) | 82 | |
84 | 83 | def r_arm(extra_args, **kw): | |
85 | def r_put (extra_args, **kw): | 84 | return r_something(run_arm, extra_args, **kw) |
86 | return r_something (run_put, extra_args, **kw) | 85 | |
87 | 86 | ||
88 | def end_arm_failer (command, rc, stdo, stde, normal): | 87 | def r_get(extra_args, **kw): |
89 | if normal: | 88 | return r_something(run_get, extra_args, **kw) |
90 | if rc != 0: | 89 | |
91 | fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 90 | |
92 | else: | 91 | def r_put(extra_args, **kw): |
93 | if rc == 0: | 92 | return r_something(run_put, extra_args, **kw) |
94 | fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 93 | |
95 | 94 | ||
96 | def print_only_failer (command, rc, stdo, stde, normal): | 95 | def end_arm_failer(command, rc, stdo, stde, normal): |
97 | if normal: | 96 | if normal: |
98 | if rc != 0: | 97 | if rc != 0: |
99 | print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 98 | fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
100 | cleanup (1) | 99 | else: |
101 | else: | 100 | if rc == 0: |
102 | if rc == 0: | 101 | fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
103 | print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 102 | |
104 | cleanup (1) | 103 | |
105 | 104 | def print_only_failer(command, rc, stdo, stde, normal): | |
106 | 105 | if normal: | |
107 | print ("TEST: Starting ARM...", end='') | 106 | if rc != 0: |
108 | r_arm (['-s'], failer = end_arm_failer, want_stdo = False, want_stde = False) | 107 | print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
109 | print ("PASS") | 108 | cleanup(1) |
110 | time.sleep (1) | 109 | else: |
111 | 110 | if rc == 0: | |
112 | print ("TEST: Testing put...", end='') | 111 | print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
113 | r_put (['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer = end_arm_failer) | 112 | cleanup(1) |
114 | print ("PASS") | 113 | |
115 | time.sleep (1) | 114 | |
116 | 115 | print("TEST: Starting ARM...", end='') | |
117 | print ("TEST: Testing get...", end='') | 116 | r_arm(['-s'], failer=end_arm_failer, want_stdo=False, want_stde=False) |
118 | rc, stdo, stde = r_get (['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo = True, failer = end_arm_failer) | 117 | print("PASS") |
119 | stdo = stdo.replace ('\r', '').splitlines () | 118 | time.sleep(1) |
119 | |||
120 | print("TEST: Testing put...", end='') | ||
121 | r_put(['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer=end_arm_failer) | ||
122 | print("PASS") | ||
123 | time.sleep(1) | ||
124 | |||
125 | print("TEST: Testing get...", end='') | ||
126 | rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer) | ||
127 | stdo = stdo.replace('\r', '').splitlines() | ||
120 | expect = "Result 0, type 8:\ntestdata".splitlines() | 128 | expect = "Result 0, type 8:\ntestdata".splitlines() |
121 | if len (stdo) != 2 or len (expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: | 129 | if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: |
122 | fail ("output `{}' differs from expected `{}'".format (stdo, expect)) | 130 | fail("output `{}' differs from expected `{}'".format(stdo, expect)) |
123 | print ("PASS") | 131 | print("PASS") |
124 | 132 | ||
125 | r_arm (['-e', '-d'], failer = print_only_failer) | 133 | r_arm(['-e', '-d'], failer=print_only_failer) |