aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_gnunet_statistics.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_gnunet_statistics.py.in')
-rw-r--r--src/statistics/test_gnunet_statistics.py.in268
1 files changed, 139 insertions, 129 deletions
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
index 86d0258f4..64e66f238 100644
--- a/src/statistics/test_gnunet_statistics.py.in
+++ b/src/statistics/test_gnunet_statistics.py.in
@@ -8,141 +8,151 @@ import subprocess
8import time 8import time
9 9
10if os.name == "nt": 10if os.name == "nt":
11 tmp = os.getenv ("TEMP") 11 tmp = os.getenv("TEMP")
12elif None != os.environ.get("TMPDIR"):
13 tmp = os.getenv("TMPDIR")
14elif None != os.environ.get("TMP"):
15 tmp = os.getenv("TMP")
12else: 16else:
13 tmp = "/tmp" 17 tmp = "/tmp"
14 18
15if os.name == 'nt': 19if os.name == 'nt':
16 st = './gnunet-statistics.exe' 20 st = './gnunet-statistics.exe'
17 arm = 'gnunet-arm.exe' 21 arm = 'gnunet-arm.exe'
18else: 22else:
19 st = './gnunet-statistics' 23 st = './gnunet-statistics'
20 arm = 'gnunet-arm' 24 arm = 'gnunet-arm'
21 25
22run_st = [st, '-c', 'test_statistics_api_data.conf'] 26run_st = [st, '-c', 'test_statistics_api_data.conf']
23run_arm = [arm, '-c', 'test_statistics_api_data.conf'] 27run_arm = [arm, '-c', 'test_statistics_api_data.conf']
24debug = os.getenv ('DEBUG') 28debug = os.getenv('DEBUG')
25if debug: 29if debug:
26 run_arm += [debug.split (' ')] 30 run_arm += [debug.split(' ')]
27 31
28def cleanup (): 32
29 shutil.rmtree (os.path.join (tmp, "test-gnunet-statistics"), True) 33def cleanup():
30 34 shutil.rmtree(os.path.join(tmp, "gnunet/test-gnunet-statistics"), True)
31def sub_run (args, want_stdo = True, want_stde = False, nofail = False): 35
32 if want_stdo: 36
33 stdo = subprocess.PIPE 37def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
34 else: 38 if want_stdo:
35 stdo = None 39 stdo = subprocess.PIPE
36 if want_stde: 40 else:
37 stde = subprocess.PIPE 41 stdo = None
38 else: 42 if want_stde:
39 stde = None 43 stde = subprocess.PIPE
40 p = subprocess.Popen (args, stdout = stdo, stderr = stde) 44 else:
41 stdo, stde = p.communicate () 45 stde = None
42 if not nofail: 46 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
43 if p.returncode != 0: 47 stdo, stde = p.communicate()
44 sys.exit (p.returncode) 48 if not nofail:
45 return (p.returncode, stdo, stde) 49 if p.returncode != 0:
46 50 sys.exit(p.returncode)
47def fail (result): 51 return (p.returncode, stdo, stde)
48 print (result) 52
49 r_arm (['-e'], want_stdo = False) 53
50 sys.exit (1) 54def fail(result):
51 55 print(result)
52def r_arm (extra_args, **kw): 56 r_arm(['-e'], want_stdo=False)
53 rc, stdo, stde = sub_run (run_arm + extra_args, **kw) 57 sys.exit(1)
54 if rc != 0: 58
55 fail ("FAIL: error running {}".format (run_arm)) 59
56 return (rc, stdo, stde) 60def r_arm(extra_args, **kw):
57 61 rc, stdo, stde = sub_run(run_arm + extra_args, **kw)
58def r_st (extra_args, normal = True, **kw):
59 rc, stdo, stde = sub_run (run_st + extra_args, **kw)
60 if normal:
61 if rc != 0: 62 if rc != 0:
62 fail ("FAIL: error running {}".format (run_st)) 63 fail("FAIL: error running {}".format(run_arm))
63 else: 64 return (rc, stdo, stde)
64 if rc == 0: 65
65 fail ("FAIL: expected error while running {}".format (run_st)) 66
66 return (rc, stdo, stde) 67def r_st(extra_args, normal=True, **kw):
67 68 rc, stdo, stde = sub_run(run_st + extra_args, **kw)
68def restart (): 69 if normal:
69 print ("Restarting service...") 70 if rc != 0:
70 t = r_arm (['-k', 'statistics']) 71 fail("FAIL: error running {}".format(run_st))
71 time.sleep (1) 72 else:
72 t = r_arm (['-i', 'statistics']) 73 if rc == 0:
73 time.sleep (1) 74 fail("FAIL: expected error while running {}".format(run_st))
74 75 return (rc, stdo, stde)
75 76
76cleanup () 77
77 78def restart():
78print ("Preparing: Starting service...") 79 print("Restarting service...")
79t = r_arm (['-s'], want_stdo = False) 80 t = r_arm(['-k', 'statistics'])
80time.sleep (1) 81 time.sleep(1)
81t = r_arm (['-i', 'statistics'], want_stdo = False) 82 t = r_arm(['-i', 'statistics'])
82time.sleep (1) 83 time.sleep(1)
83 84
84print ("TEST: Bad argument checking...", end='') 85
85r_st (['-x'], normal = False, nofail = True, want_stdo = False, want_stde = True) 86cleanup()
86print ("PASS") 87
87 88print("Preparing: Starting service...")
88print ("TEST: Set value...", end='') 89t = r_arm(['-s'], want_stdo=False)
89r_st (['-n', 'test', '-s', 'subsystem', b'42'], nofail = True, want_stdo = False) 90time.sleep(1)
90print ("PASS") 91t = r_arm(['-i', 'statistics'], want_stdo=False)
91 92time.sleep(1)
92print ("TEST: Set another value...", end='') 93
93r_st (['-n', 'other', '-s', 'osystem', b'43'], nofail = True, want_stdo = False) 94print("TEST: Bad argument checking...", end='')
94print ("PASS") 95r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True)
95 96print("PASS")
96print ("TEST: Viewing all stats...", end='') 97
97rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 98print("TEST: Set value...", end='')
98if len (stdo.splitlines ()) != 2: 99r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False)
99 fail ("FAIL: unexpected output:\n{}".format (stdo)) 100print("PASS")
100print ("PASS") 101
101 102print("TEST: Set another value...", end='')
102print ("TEST: Viewing stats by name...", end='') 103r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False)
103rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True) 104print("PASS")
104if len ([x for x in stdo.splitlines () if re.search (b'43', x)]) != 1: 105
105 fail ("FAIL: unexpected output:\n{}".format (stdo)) 106print("TEST: Viewing all stats...", end='')
106print ("PASS") 107rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
107 108if len(stdo.splitlines()) != 2:
108print ("TEST: Viewing stats by subsystem...", end='') 109 fail("FAIL: unexpected output:\n{}".format(stdo))
109rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True) 110print("PASS")
110if len ([x for x in stdo.splitlines () if re.search (b'42', x)]) != 1: 111
111 fail ("FAIL: unexpected output:\n{}".format (stdo)) 112print("TEST: Viewing stats by name...", end='')
112print ("PASS") 113rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True)
113 114if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1:
114print ("TEST: Set persistent value...", end='') 115 fail("FAIL: unexpected output:\n{}".format(stdo))
115rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False) 116print("PASS")
116rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 117
117if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: 118print("TEST: Viewing stats by subsystem...", end='')
118 fail ("FAIL: unexpected output:\n{}".format (stdo)) 119rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True)
119print ("PASS") 120if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1:
120 121 fail("FAIL: unexpected output:\n{}".format(stdo))
121restart () 122print("PASS")
122 123
123print ("TEST: Checking persistence...", end='') 124print("TEST: Set persistent value...", end='')
124rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 125rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail=True, want_stdo=False)
125if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: 126rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
126 fail ("FAIL: unexpected output:\n{}".format (stdo)) 127if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
127print ("PASS") 128 fail("FAIL: unexpected output:\n{}".format(stdo))
128 129print("PASS")
129print ("TEST: Removing persistence...", end='') 130
130rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False) 131restart()
131rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 132
132if len ([x for x in stdo.splitlines () if re.search (b'!', x)]) != 0: 133print("TEST: Checking persistence...", end='')
133 fail ("FAIL: unexpected output:\n{}".format (stdo)) 134rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
134print ("PASS") 135if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
135 136 fail("FAIL: unexpected output:\n{}".format(stdo))
136restart () 137print("PASS")
137 138
138print ("TEST: Checking removed persistence...", end='') 139print("TEST: Removing persistence...", end='')
139rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 140rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], nofail=True, want_stdo=False)
140if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 0: 141rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
141 fail ("FAIL: unexpected output:\n{}".format (stdo)) 142if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0:
142print ("PASS") 143 fail("FAIL: unexpected output:\n{}".format(stdo))
143 144print("PASS")
144print ("Stopping service...") 145
145t = r_arm (['-e'], want_stdo = False) 146restart()
146time.sleep (1) 147
147 148print("TEST: Checking removed persistence...", end='')
148cleanup () 149rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
150if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0:
151 fail("FAIL: unexpected output:\n{}".format(stdo))
152print("PASS")
153
154print("Stopping service...")
155t = r_arm(['-e'], want_stdo=False)
156time.sleep(1)
157
158cleanup()