Tests: detect alerts and Sanitizer errors.

This commit is contained in:
Andrey Zelenkov
2018-03-06 16:58:47 +03:00
parent 912a49c609
commit 30a32c2f09
2 changed files with 56 additions and 0 deletions

View File

@@ -62,6 +62,12 @@ class TestUnitConfiguration(unit.TestUnitControl):
self.assertIn('error', self.conf('"{}"', '/applications'), 'string') self.assertIn('error', self.conf('"{}"', '/applications'), 'string')
def test_applications_type_only(self): def test_applications_type_only(self):
self.skip_alerts.extend([
r'python module is empty',
r'failed to apply new conf',
r'process \d+ exited on signal'
])
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"app": { "app": {
"type": "python" "type": "python"
@@ -120,6 +126,13 @@ class TestUnitConfiguration(unit.TestUnitControl):
@unittest.expectedFailure @unittest.expectedFailure
def test_listeners_empty(self): def test_listeners_empty(self):
self.skip_sanitizer = True
self.skip_alerts.extend([
r'nxt_lvlhsh_is_empty\(&port->rpc_streams\)',
r'sendmsg.+failed',
r'process \d+ exited on signal'
])
self.assertIn('error', self.conf({"*:7080":{}}, '/listeners'), self.assertIn('error', self.conf({"*:7080":{}}, '/listeners'),
'listener empty') 'listener empty')
@@ -179,6 +192,12 @@ class TestUnitConfiguration(unit.TestUnitControl):
}), 'explicit ipv6') }), 'explicit ipv6')
def test_listeners_no_port(self): def test_listeners_no_port(self):
self.skip_alerts.extend([
r'invalid listener "127\.0\.0\.1"',
r'failed to apply new conf',
r'process \d+ exited on signal'
])
self.assertIn('error', self.conf({ self.assertIn('error', self.conf({
"listeners": { "listeners": {
"127.0.0.1": { "127.0.0.1": {

View File

@@ -6,6 +6,7 @@ import time
import shutil import shutil
import socket import socket
import select import select
import platform
import tempfile import tempfile
import unittest import unittest
from subprocess import call from subprocess import call
@@ -14,6 +15,7 @@ from multiprocessing import Process
class TestUnit(unittest.TestCase): class TestUnit(unittest.TestCase):
pardir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) pardir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
architecture = platform.architecture()[0]
def setUp(self): def setUp(self):
self._run() self._run()
@@ -21,6 +23,10 @@ class TestUnit(unittest.TestCase):
def tearDown(self): def tearDown(self):
self._stop() self._stop()
with open(self.testdir + '/unit.log', 'r', encoding='utf-8',
errors='ignore') as f:
self._check_alerts(f.read())
if '--leave' not in sys.argv: if '--leave' not in sys.argv:
shutil.rmtree(self.testdir) shutil.rmtree(self.testdir)
@@ -41,6 +47,8 @@ class TestUnit(unittest.TestCase):
self._stop() self._stop()
exit("Unit is writing log too long") exit("Unit is writing log too long")
self._check_alerts(log)
missed_module = '' missed_module = ''
for module in modules: for module in modules:
m = re.search('module: ' + module, log) m = re.search('module: ' + module, log)
@@ -77,6 +85,12 @@ class TestUnit(unittest.TestCase):
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'): self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit") exit("Could not start unit")
self.skip_alerts = [r'read signalfd\(4\) failed']
self.skip_sanitizer = False
if self.architecture == '32bit':
self.skip_alerts.append(r'freed pointer points to non-freeble page')
def _stop(self): def _stop(self):
with open(self.testdir + '/unit.pid', 'r') as f: with open(self.testdir + '/unit.pid', 'r') as f:
pid = f.read().rstrip() pid = f.read().rstrip()
@@ -105,6 +119,29 @@ class TestUnit(unittest.TestCase):
if process.exitcode: if process.exitcode:
exit("Child process terminated with code " + str(process.exitcode)) exit("Child process terminated with code " + str(process.exitcode))
def _check_alerts(self, log):
found = False
alerts = re.findall('.+\[alert\].+', log)
if alerts:
print('All alerts/sanitizer errors found in log:')
[print(alert) for alert in alerts]
found = True
if self.skip_alerts:
for skip in self.skip_alerts:
alerts = [al for al in alerts if re.search(skip, al) is None]
self.assertFalse(alerts, 'alert(s)')
if not self.skip_sanitizer:
self.assertFalse(re.findall('.+Sanitizer.+', log),
'sanitizer error(s)')
if found:
print('skipped.')
def _waitforfiles(self, *files): def _waitforfiles(self, *files):
for i in range(50): for i in range(50):
wait = False wait = False