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