From: Justin Husted Date: Mon, 18 Nov 2019 21:51:31 +0000 (-0800) Subject: Make valgrind optional in tests. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=049dd7b79e94c0d4a9a290ff6c435401a22b5549;p=bcachefs-tools-debian 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 --- diff --git a/INSTALL b/INSTALL index e344c53..0c37c4a 100644 --- a/INSTALL +++ b/INSTALL @@ -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 diff --git a/tests/test_fixture.py b/tests/test_fixture.py index 74a896b..d8d3819 100644 --- a/tests/test_fixture.py +++ b/tests/test_fixture.py @@ -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) diff --git a/tests/util.py b/tests/util.py index b6e05e3..d837615 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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