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-gnunet-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'])
78 print ("Preparing: Starting service...")
79 t = r_arm (['-s'], want_stdo = False)
81 t = r_arm (['-i', 'statistics'], want_stdo = False)
84 print ("TEST: Bad argument checking...", end='')
85 r_st (['-x'], normal = False, nofail = True, want_stdo = False, want_stde = True)
88 print ("TEST: Set value...", end='')
89 r_st (['-n', 'test', '-s', 'subsystem', '42'], nofail = True, want_stdo = False)
92 print ("TEST: Set another value...", end='')
93 r_st (['-n', 'other', '-s', 'osystem', '43'], nofail = True, want_stdo = False)
96 print ("TEST: Viewing all stats...", end='')
97 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
98 if len (stdo.splitlines ()) != 2:
99 fail ("FAIL: unexpected output:\n{}".format (stdo))
102 print ("TEST: Viewing stats by name...", end='')
103 rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True)
104 if len ([x for x in stdo.splitlines () if re.search ('43', x)]) != 1:
105 fail ("FAIL: unexpected output:\n{}".format (stdo))
108 print ("TEST: Viewing stats by subsystem...", end='')
109 rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True)
110 if len ([x for x in stdo.splitlines () if re.search ('42', x)]) != 1:
111 fail ("FAIL: unexpected output:\n{}".format (stdo))
114 print ("TEST: Set persistent value...", end='')
115 rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False)
116 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
117 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
118 fail ("FAIL: unexpected output:\n{}".format (stdo))
123 print ("TEST: Checking persistence...", end='')
124 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
125 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
126 fail ("FAIL: unexpected output:\n{}".format (stdo))
129 print ("TEST: Removing persistence...", end='')
130 rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False)
131 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
132 if len ([x for x in stdo.splitlines () if re.search ('!', x)]) != 0:
133 fail ("FAIL: unexpected output:\n{}".format (stdo))
138 print ("TEST: Checking removed persistence...", end='')
139 rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
140 if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 0:
141 fail ("FAIL: unexpected output:\n{}".format (stdo))
144 print ("Stopping service...")
145 t = r_arm (['-e'], want_stdo = False)