aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_tools.py.in
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-22 09:26:21 +0000
committerNils Gillmann <ng0@n0.is>2018-05-22 09:26:21 +0000
commit067f31e6e330b5348f0979364de7e4038d4594e7 (patch)
tree5953a77446772ca996c35d82afd5d7edfecf9b88 /src/dht/test_dht_tools.py.in
parent043b52f76c21d5e74707c9dc4d379c8fed252dde (diff)
downloadgnunet-067f31e6e330b5348f0979364de7e4038d4594e7.tar.gz
gnunet-067f31e6e330b5348f0979364de7e4038d4594e7.zip
++
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'src/dht/test_dht_tools.py.in')
-rw-r--r--src/dht/test_dht_tools.py.in184
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
21import time 21import time
22import tempfile 22import tempfile
23 23
24os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]; 24os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]
25 25
26if os.name == "nt": 26if os.name == "nt":
27 tmp = os.getenv ("TEMP") 27 tmp = os.getenv("TEMP")
28else: 28else:
29 tmp = "/tmp" 29 tmp = "/tmp"
30 30
31if os.name == 'nt': 31if 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'
35else: 35else:
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
40cfgfile = 'test_dht_api_peer1.conf' 40cfgfile = 'test_dht_api_peer1.conf'
41
42run_get = [get, '-c', cfgfile] 41run_get = [get, '-c', cfgfile]
43run_put = [put, '-c', cfgfile] 42run_put = [put, '-c', cfgfile]
44run_arm = [arm, '-c', cfgfile] 43run_arm = [arm, '-c', cfgfile]
45debug = os.getenv ('DEBUG') 44debug = os.getenv('DEBUG')
46if debug: 45if debug:
47 run_arm += [debug.split (' ')] 46 run_arm += [debug.split(' ')]
48 47
49def cleanup (exitcode): 48
50 sys.exit (exitcode) 49def cleanup(exitcode):
51 50 sys.exit(exitcode)
52def sub_run (args, want_stdo = True, want_stde = False, nofail = False): 51
53 if want_stdo: 52
54 stdo = subprocess.PIPE 53def 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)
68def fail (result): 67 return (p.returncode, stdo, stde)
69 print (result) 68
70 r_arm (['-e'], want_stdo = False) 69
71 cleanup (1) 70def fail(result):
72 71 print(result)
73def 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) 76def 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)
79def 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)
82def r_get (extra_args, **kw): 81
83 return r_something (run_get, extra_args, **kw) 82
84 83def r_arm(extra_args, **kw):
85def 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
88def end_arm_failer (command, rc, stdo, stde, normal): 87def 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: 91def 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
96def print_only_failer (command, rc, stdo, stde, normal): 95def 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 104def print_only_failer(command, rc, stdo, stde, normal):
106 105 if normal:
107print ("TEST: Starting ARM...", end='') 106 if rc != 0:
108r_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))
109print ("PASS") 108 cleanup(1)
110time.sleep (1) 109 else:
111 110 if rc == 0:
112print ("TEST: Testing put...", end='') 111 print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
113r_put (['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer = end_arm_failer) 112 cleanup(1)
114print ("PASS") 113
115time.sleep (1) 114
116 115print("TEST: Starting ARM...", end='')
117print ("TEST: Testing get...", end='') 116r_arm(['-s'], failer=end_arm_failer, want_stdo=False, want_stde=False)
118rc, stdo, stde = r_get (['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo = True, failer = end_arm_failer) 117print("PASS")
119stdo = stdo.replace ('\r', '').splitlines () 118time.sleep(1)
119
120print("TEST: Testing put...", end='')
121r_put(['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer=end_arm_failer)
122print("PASS")
123time.sleep(1)
124
125print("TEST: Testing get...", end='')
126rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer)
127stdo = stdo.replace('\r', '').splitlines()
120expect = "Result 0, type 8:\ntestdata".splitlines() 128expect = "Result 0, type 8:\ntestdata".splitlines()
121if len (stdo) != 2 or len (expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: 129if 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))
123print ("PASS") 131print("PASS")
124 132
125r_arm (['-e', '-d'], failer = print_only_failer) 133r_arm(['-e', '-d'], failer=print_only_failer)