Make valgrind optional in tests.

Add an option to disable valgrind in the test suite, via the variable:

BCACHEFS_TEST_USE_VALGRIND=no

Additionally, note how to run tests in parallel in the INSTALL documentation.

Signed-off-by: Justin Husted <sigstop@gmail.com>
This commit is contained in:
Justin Husted 2019-11-18 13:51:31 -08:00
parent a00998c4cd
commit 049dd7b79e
3 changed files with 28 additions and 9 deletions

View File

@ -45,8 +45,12 @@ Some tests are available to validate the "bcachefs" binary. The tests depend
on python3 pytest.
On debian:
apt install -u python3-pytest
apt install -u python3-pytest
Then, you can run the tests via:
make check
make check
Optionally, you may wish to run tests in parallel using python3-pytest-xdist:
cd tests; pytest-3 -n4

View File

@ -29,26 +29,32 @@ def test_segfault():
ret = util.run(helper, 'segfault')
assert ret.returncode == -signal.SIGSEGV
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_check():
with pytest.raises(subprocess.CalledProcessError):
ret = util.run(helper, 'abort', check=True)
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_leak():
with pytest.raises(util.ValgrindFailedError):
ret = util.run(helper, 'leak', valgrind=True)
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_undefined():
with pytest.raises(util.ValgrindFailedError):
ret = util.run(helper, 'undefined', valgrind=True)
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_undefined_branch():
with pytest.raises(util.ValgrindFailedError):
ret = util.run(helper, 'undefined_branch', valgrind=True)
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_read_after_free():
with pytest.raises(util.ValgrindFailedError):
ret = util.run(helper, 'read_after_free', valgrind=True)
@pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
def test_write_after_free():
with pytest.raises(util.ValgrindFailedError):
ret = util.run(helper, 'write_after_free', valgrind=True)

View File

@ -16,6 +16,8 @@ BCH_PATH = DIR / 'bcachefs'
VPAT = re.compile(r'ERROR SUMMARY: (\d+) errors from (\d+) contexts')
ENABLE_VALGRIND = os.getenv('BCACHEFS_TEST_USE_VALGRIND', 'yes') == 'yes'
class ValgrindFailedError(Exception):
def __init__(self, log):
self.log = log
@ -37,6 +39,7 @@ def run(cmd, *args, valgrind=False, check=False):
ValgrindFailedError if there's a problem.
"""
cmds = [cmd] + list(args)
valgrind = valgrind and ENABLE_VALGRIND
if valgrind:
vout = tempfile.NamedTemporaryFile()
@ -147,12 +150,17 @@ class BFuse(threading.Thread):
def run(self):
"""Background thread which runs "bcachefs fusemount" under valgrind"""
vout = tempfile.NamedTemporaryFile()
cmd = [ 'valgrind',
'--leak-check=full',
'--log-file={}'.format(vout.name),
BCH_PATH,
'fusemount', '-f', self.dev, self.mnt]
vout = None
cmd = []
if ENABLE_VALGRIND:
vout = tempfile.NamedTemporaryFile()
cmd += [ 'valgrind',
'--leak-check=full',
'--log-file={}'.format(vout.name) ]
cmd += [ BCH_PATH,
'fusemount', '-f', self.dev, self.mnt]
print("Running {}".format(cmd))
@ -203,7 +211,8 @@ class BFuse(threading.Thread):
self.proc.kill()
self.join()
check_valgrind(self.vout)
if self.vout:
check_valgrind(self.vout)
def verify(self):
assert self.returncode == 0