2 from __future__ import print_function
11 tmp = os.getenv ("TEMP")
16 st = 'gnunet-statistics.exe'
17 arm = 'gnunet-arm.exe'
19 st = 'gnunet-statistics'
22 run_st = [st, '-c', 'test_statistics_api_data.conf']
23 run_arm = [arm, '-c', 'test_statistics_api_data.conf']
24 debug = os.getenv ('DEBUG')
26 run_arm += [debug.split (' ')]
29 shutil.rmtree (os.path.join (tmp, "test-gnunetd-statistics"), True)
31 def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
33 stdo = subprocess.PIPE
37 stde = subprocess.PIPE
40 p = subprocess.Popen (args, stdout = stdo, stderr = stde)
41 stdo, stde = p.communicate ()
44 sys.exit (p.returncode)
45 return (p.returncode, stdo, stde)
49 r_arm (['-e'], want_stdo = False)
52 def r_arm (extra_args, **kw):
53 rc, stdo, stde = sub_run (run_arm + extra_args, **kw)
55 fail ("FAIL: error running {}".format (run_arm))
56 return (rc, stdo, stde)
58 def r_st (extra_args, normal = True, **kw):
59 rc, stdo, stde = sub_run (run_st + extra_args, **kw)
62 fail ("FAIL: error running {}".format (run_st))
65 fail ("FAIL: expected error while running {}".format (run_st))
66 return (rc, stdo, stde)
69 print ("Restarting service...")
70 t = r_arm (['-k', 'statistics'])
72 t = r_arm (['-i', 'statistics'])
79 print ("Preparing: Starting service...")
80 t = r_arm (['-s'], want_stdo = False)
82 t = r_arm (['-i', 'statistics'], want_stdo = False)
86 print ("TEST: Bad argument checking...", end='')
87 r_st (['-x'], normal = False, nofail = True, want_stdo = False)
90 print ("TEST: Set value...", end='')
91 r_st (['-n', 'test', '-s', 'subsystem', '42'], nofail = True, want_stdo = False)
94 print ("TEST: Set another value...", end='')
95 r_st (['-n', 'other', '-s', 'osystem', '43'], nofail = True, want_stdo = False)
98 print ("TEST: Viewing all stats...", end='')
99 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
100 if len (stdo.splitlines ()) != 2:
101 fail ("FAIL: unexpected output:\n{}".format (stdo))
104 print ("TEST: Viewing stats by name...", end='')
105 rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True)
106 if len ([x for x in stdo.splitlines () if re.search ('43', x)]) != 1:
107 fail ("FAIL: unexpected output:\n{}".format (stdo))
110 print ("TEST: Viewing stats by subsystem...", end='')
111 rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True)
112 if len ([x for x in stdo.splitlines () if re.search ('42', x)]) != 1:
113 fail ("FAIL: unexpected output:\n{}".format (stdo))
116 print ("TEST: Set persistent value...", end='')
117 rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False)
118 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
119 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
120 fail ("FAIL: unexpected output:\n{}".format (stdo))
125 print ("TEST: Checking persistence...", end='')
126 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
127 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
128 fail ("FAIL: unexpected output:\n{}".format (stdo))
131 print ("TEST: Removing persistence...", end='')
132 rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False)
133 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
134 if len ([x for x in stdo.splitlines () if re.search ('!', x)]) != 0:
135 fail ("FAIL: unexpected output:\n{}".format (stdo))
140 print ("TEST: Checking removed persistence...", end='')
141 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
142 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 0:
143 fail ("FAIL: unexpected output:\n{}".format (stdo))
146 print ("Stopping service...")
147 t = r_arm (['-e'], want_stdo = False)