3 # This testcase simply checks that the DHT command-line tools work.
4 # It launches a single peer, stores a value "testdata" under "testkey",
5 # and then gives the system 50 ms to fetch it.
8 # - command line tool interfaces fail
9 # - DHT plugins for storage are not installed / working
10 # - block plugins for verification (the test plugin) is not installed
12 # The code does NOT depend on DHT routing or any actual P2P functionality.
23 os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]
26 tmp = os.getenv("TEMP")
31 get = './gnunet-dht-get.exe'
32 put = './gnunet-dht-put.exe'
33 arm = 'gnunet-arm.exe'
35 get = './gnunet-dht-get'
36 put = './gnunet-dht-put'
39 cfgfile = 'test_dht_api_peer1.conf'
40 run_get = [get, '-c', cfgfile]
41 run_put = [put, '-c', cfgfile]
42 run_arm = [arm, '-c', cfgfile]
43 debug = os.getenv('DEBUG')
45 run_arm += [debug.split(' ')]
48 def cleanup(exitcode):
52 def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
54 stdo = subprocess.PIPE
58 stde = subprocess.PIPE
61 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
62 stdo, stde = p.communicate()
65 sys.exit(p.returncode)
66 return (p.returncode, stdo, stde)
71 r_arm(['-e'], want_stdo=False)
75 def r_something(to_run, extra_args, failer=None, normal=True, **kw):
76 rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, **kw)
77 if failer is not None:
78 failer(to_run + extra_args, rc, stdo, stde, normal)
79 return (rc, stdo, stde)
82 def r_arm(extra_args, **kw):
83 return r_something(run_arm, extra_args, **kw)
86 def r_get(extra_args, **kw):
87 return r_something(run_get, extra_args, **kw)
90 def r_put(extra_args, **kw):
91 return r_something(run_put, extra_args, **kw)
94 def end_arm_failer(command, rc, stdo, stde, normal):
97 fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
100 fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
103 def print_only_failer(command, rc, stdo, stde, normal):
106 print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
110 print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde))
114 print("TEST: Starting ARM...", end='')
115 r_arm(['-s'], failer=end_arm_failer, want_stdo=False, want_stde=False)
119 print("TEST: Testing put...", end='')
120 r_put(['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer=end_arm_failer)
124 print("TEST: Testing get...", end='')
125 rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer)
126 stdo = stdo.decode('utf-8').replace('\r', '').splitlines()
127 expect = "Result 0, type 8:\ntestdata".splitlines()
128 if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]:
129 fail("output `{}' differs from expected `{}'".format(stdo, expect))
132 r_arm(['-e', '-d'], failer=print_only_failer)