conftest.py (1611:c0d16f2f6d33) conftest.py (1621:275b26bbd3ae)
1import fcntl
2import os
3import platform
4import pytest
1import fcntl
2import os
3import platform
4import pytest
5import shutil
5import signal
6import stat
7import subprocess
8import sys
9import re
10import tempfile
11import time
12
6import signal
7import stat
8import subprocess
9import sys
10import re
11import tempfile
12import time
13
14from unit.check.go import check_go
15from unit.check.node import check_node
16from unit.check.tls import check_openssl
13
17
18
14def pytest_addoption(parser):
15 parser.addoption(
16 "--detailed",
17 default=False,
18 action="store_true",
19 help="Detailed output for tests",
20 )
21 parser.addoption(

--- 105 unchanged lines hidden (view full) ---

127 # discover available modules from unit.log
128
129 for module in re.findall(r'module: ([a-zA-Z]+) (.*) ".*"$', log, re.M):
130 if module[0] not in option.available['modules']:
131 option.available['modules'][module[0]] = [module[1]]
132 else:
133 option.available['modules'][module[0]].append(module[1])
134
19def pytest_addoption(parser):
20 parser.addoption(
21 "--detailed",
22 default=False,
23 action="store_true",
24 help="Detailed output for tests",
25 )
26 parser.addoption(

--- 105 unchanged lines hidden (view full) ---

132 # discover available modules from unit.log
133
134 for module in re.findall(r'module: ([a-zA-Z]+) (.*) ".*"$', log, re.M):
135 if module[0] not in option.available['modules']:
136 option.available['modules'][module[0]] = [module[1]]
137 else:
138 option.available['modules'][module[0]].append(module[1])
139
140 # discover modules from check
141
142 option.available['modules']['openssl'] = check_openssl(unit['unitd'])
143 option.available['modules']['go'] = check_go(
144 option.current_dir, unit['temp_dir'], option.test_dir
145 )
146 option.available['modules']['node'] = check_node(option.current_dir)
147
148 # remove None values
149
150 option.available['modules'] = {
151 k: v for k, v in option.available['modules'].items() if v is not None
152 }
153
135 unit_stop()
136
137
138def setup_method(self):
139 option.skip_alerts = [
140 r'read signalfd\(4\) failed',
141 r'sendmsg.+failed',
142 r'recvmsg.+failed',

--- 68 unchanged lines hidden (view full) ---

211 try:
212 retcode = p.wait(15)
213 if retcode:
214 return 'Child process terminated with code ' + str(retcode)
215 except:
216 p.kill()
217 return 'Could not terminate unit'
218
154 unit_stop()
155
156
157def setup_method(self):
158 option.skip_alerts = [
159 r'read signalfd\(4\) failed',
160 r'sendmsg.+failed',
161 r'recvmsg.+failed',

--- 68 unchanged lines hidden (view full) ---

230 try:
231 retcode = p.wait(15)
232 if retcode:
233 return 'Child process terminated with code ' + str(retcode)
234 except:
235 p.kill()
236 return 'Could not terminate unit'
237
238 shutil.rmtree(unit_instance['temp_dir'])
219
220def public_dir(path):
221 os.chmod(path, 0o777)
222
223 for root, dirs, files in os.walk(path):
224 for d in dirs:
225 os.chmod(os.path.join(root, d), 0o777)
226 for f in files:

--- 33 unchanged lines hidden (view full) ---

260 [print(alert) for alert in alerts]
261 found = True
262
263 if option.skip_alerts:
264 for skip in option.skip_alerts:
265 alerts = [al for al in alerts if re.search(skip, al) is None]
266
267 if alerts:
239
240def public_dir(path):
241 os.chmod(path, 0o777)
242
243 for root, dirs, files in os.walk(path):
244 for d in dirs:
245 os.chmod(os.path.join(root, d), 0o777)
246 for f in files:

--- 33 unchanged lines hidden (view full) ---

280 [print(alert) for alert in alerts]
281 found = True
282
283 if option.skip_alerts:
284 for skip in option.skip_alerts:
285 alerts = [al for al in alerts if re.search(skip, al) is None]
286
287 if alerts:
268 _print_log(log)
288 _print_log(data=log)
269 assert not alerts, 'alert(s)'
270
271 if not option.skip_sanitizer:
272 sanitizer_errors = re.findall('.+Sanitizer.+', log)
273
274 if sanitizer_errors:
289 assert not alerts, 'alert(s)'
290
291 if not option.skip_sanitizer:
292 sanitizer_errors = re.findall('.+Sanitizer.+', log)
293
294 if sanitizer_errors:
275 _print_log(log)
295 _print_log(data=log)
276 assert not sanitizer_errors, 'sanitizer error(s)'
277
278 if found:
279 print('skipped.')
280
281
296 assert not sanitizer_errors, 'sanitizer error(s)'
297
298 if found:
299 print('skipped.')
300
301
282def _print_log(data=None):
283 unit_log = unit_instance['log']
302def _print_log(path=None, data=None):
303 if path is None:
304 path = unit_instance['log']
284
305
285 print('Path to unit.log:\n' + unit_log + '\n')
306 print('Path to unit.log:\n' + path + '\n')
286
287 if option.print_log:
288 os.set_blocking(sys.stdout.fileno(), True)
289 sys.stdout.flush()
290
291 if data is None:
307
308 if option.print_log:
309 os.set_blocking(sys.stdout.fileno(), True)
310 sys.stdout.flush()
311
312 if data is None:
292 with open(unit_log, 'r', encoding='utf-8', errors='ignore') as f:
313 with open(path, 'r', encoding='utf-8', errors='ignore') as f:
293 shutil.copyfileobj(f, sys.stdout)
294 else:
295 sys.stdout.write(data)
296
297
298@pytest.fixture
299def is_unsafe(request):
300 return request.config.getoption("--unsafe")
301
302@pytest.fixture
303def is_su(request):
304 return os.geteuid() == 0
305
306def pytest_sessionfinish(session):
307 unit_stop()
314 shutil.copyfileobj(f, sys.stdout)
315 else:
316 sys.stdout.write(data)
317
318
319@pytest.fixture
320def is_unsafe(request):
321 return request.config.getoption("--unsafe")
322
323@pytest.fixture
324def is_su(request):
325 return os.geteuid() == 0
326
327def pytest_sessionfinish(session):
328 unit_stop()