11 tmp = os.getenv("TEMP")
12 elif None != os.environ.get("TMPDIR"):
13 tmp = os.getenv("TMPDIR")
14 elif None != os.environ.get("TMP"):
15 tmp = os.getenv("TMP")
20 st = './gnunet-statistics.exe'
21 arm = 'gnunet-arm.exe'
23 st = './gnunet-statistics'
26 run_st = [st, '-c', 'test_statistics_api_data.conf']
27 run_arm = [arm, '-c', 'test_statistics_api_data.conf']
28 debug = os.getenv('DEBUG')
30 run_arm += [debug.split(' ')]
34 shutil.rmtree(os.path.join(tmp, "gnunet/test-gnunet-statistics"), True)
37 def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
39 stdo = subprocess.PIPE
43 stde = subprocess.PIPE
46 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
47 stdo, stde = p.communicate()
50 sys.exit(p.returncode)
51 return (p.returncode, stdo, stde)
56 r_arm(['-e'], want_stdo=False)
60 def r_arm(extra_args, **kw):
61 rc, stdo, stde = sub_run(run_arm + extra_args, **kw)
63 fail("FAIL: error running {}".format(run_arm))
64 return (rc, stdo, stde)
67 def r_st(extra_args, normal=True, **kw):
68 rc, stdo, stde = sub_run(run_st + extra_args, **kw)
71 fail("FAIL: error running {}".format(run_st))
74 fail("FAIL: expected error while running {}".format(run_st))
75 return (rc, stdo, stde)
79 print("Restarting service...")
80 t = r_arm(['-k', 'statistics'])
82 t = r_arm(['-i', 'statistics'])
88 print("Preparing: Starting service...")
89 t = r_arm(['-s'], want_stdo=False)
91 t = r_arm(['-i', 'statistics'], want_stdo=False)
94 print("TEST: Bad argument checking...", end='')
95 r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True)
98 print("TEST: Set value...", end='')
99 r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False)
102 print("TEST: Set another value...", end='')
103 r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False)
106 print("TEST: Viewing all stats...", end='')
107 rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
108 if len(stdo.splitlines()) != 2:
109 fail("FAIL: unexpected output:\n{}".format(stdo))
112 print("TEST: Viewing stats by name...", end='')
113 rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True)
114 if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1:
115 fail("FAIL: unexpected output:\n{}".format(stdo))
118 print("TEST: Viewing stats by subsystem...", end='')
119 rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True)
120 if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1:
121 fail("FAIL: unexpected output:\n{}".format(stdo))
124 print("TEST: Set persistent value...", end='')
125 rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'],
128 rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
129 if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
130 fail("FAIL: unexpected output:\n{}".format(stdo))
135 print("TEST: Checking persistence...", end='')
136 rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
137 if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
138 fail("FAIL: unexpected output:\n{}".format(stdo))
141 print("TEST: Removing persistence...", end='')
142 rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'],
145 rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
146 if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0:
147 fail("FAIL: unexpected output:\n{}".format(stdo))
152 print("TEST: Checking removed persistence...", end='')
153 rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
154 if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0:
155 fail("FAIL: unexpected output:\n{}".format(stdo))
158 print("Stopping service...")
159 t = r_arm(['-e'], want_stdo=False)