]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Make valgrind optional in tests.
authorJustin Husted <sigstop@gmail.com>
Mon, 18 Nov 2019 21:51:31 +0000 (13:51 -0800)
committerJustin Husted <sigstop@gmail.com>
Mon, 18 Nov 2019 21:51:31 +0000 (13:51 -0800)
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>
INSTALL
tests/test_fixture.py
tests/util.py

diff --git a/INSTALL b/INSTALL
index e344c53c5086410206bb3b86daa6a176c02d9670..0c37c4a07e42bd00549cfaa0d92b263449be6ceb 100644 (file)
--- 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
index 74a896bace4122597c8007f6662dceba317420f8..d8d3819e814427473b4f171a75c09f79d1650312 100644 (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)
index b6e05e3a97d2696f1f06369fc64bd1746bc37f4f..d8376158a038bd4746e77160c42fc0e0c7cf486a 100644 (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