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
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)
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
ValgrindFailedError if there's a problem.
"""
cmds = [cmd] + list(args)
+ valgrind = valgrind and ENABLE_VALGRIND
if valgrind:
vout = tempfile.NamedTemporaryFile()
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))
self.proc.kill()
self.join()
- check_valgrind(self.vout)
+ if self.vout:
+ check_valgrind(self.vout)
def verify(self):
assert self.returncode == 0