]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Clean up smoketest and pytests.
authorBrett Holman <bholman.devel@gmail.com>
Mon, 11 Oct 2021 21:23:09 +0000 (15:23 -0600)
committerBrett Holman <bholman.devel@gmail.com>
Tue, 12 Oct 2021 02:24:12 +0000 (20:24 -0600)
- Replace depreciated tempfile with mktemp in smoketest.
- Remove unused pytest imports and variables.
- Make path lookup less fragile. Allows pytest to run from any cwd.
- Prevent exeptions caused by calling functions/methods on None objects.
- Disable fuse tests in smoketest. These are broken and add noise.
- Add missing travis CI dependency.

Signed-off-by: Brett Holman <bholman.devel@gmail.com>
.travis.yml
Makefile
smoke_test
tests/__init__.py [new file with mode: 0644]
tests/conftest.py
tests/test_basic.py
tests/test_fixture.py
tests/test_fuse.py
tests/util.py

index 3b90b73c27f0c5456c364d211fa431f2c80e0779..947997b3a2a8cc8223eb6abc455a20ac91d9276e 100644 (file)
@@ -9,6 +9,7 @@ addons:
     apt:
         packages:
             - valgrind
+            - python3-docutils
             - python3-pytest
             - python3-pytest-xdist
             - meson
index 23e0508569d8b3856d0a4906d43be01495dda3df..5917a4c2d07732a9f6bd4abff53199a86db5d6df 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -85,7 +85,7 @@ tests: tests/test_helper
 
 .PHONY: check
 check: tests bcachefs
-       cd tests; $(PYTEST)
+       $(PYTEST)
 
 .PHONY: TAGS tags
 TAGS:
index 15a9fcee1ac1c438e898036a667b57955e94a3ff..112280889c63099a912f49d1cbecdca8550cbd24 100755 (executable)
@@ -21,7 +21,7 @@
 set -e
 
 PYTEST="${PYTEST:-pytest-3}"
-spam=$(tempfile)
+spam=$(mktemp)
 unset BCACHEFS_FUSE BCACHEFS_TEST_USE_VALGRIND BCACHEFS_DEBUG
 
 trap "set +x; cat ${spam}; rm -f ${spam} ; echo; echo FAILED." EXIT
@@ -44,7 +44,6 @@ function build() {
 function test() {
     echo Running tests.
     (
-        cd tests
         ${PYTEST} -n${JOBS}
     ) > ${spam} 2>&1
 }
@@ -53,7 +52,6 @@ function test_vg() {
     echo Running tests with valgrind.
     (
         export BCACHEFS_TEST_USE_VALGRIND=yes
-        cd tests
         ${PYTEST} -n${JOBS}
     ) > ${spam} 2>&1
 }
@@ -71,13 +69,13 @@ test
 echo -- Test: debug with valgrind --
 test_vg
 
-echo -- Test: fuse debug --
-export BCACHEFS_FUSE=1
-build
-test
+#echo -- Test: fuse debug --
+#export BCACHEFS_FUSE=1
+#build
+#test
 
-echo -- Test: fuse debug with valgrind --
-test_vg
+#echo -- Test: fuse debug with valgrind --
+#test_vg
 
 rm -f ${spam}
 trap "set +x; echo; echo SUCCESS." EXIT
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 45c62732dd1d9bbe6db3074ceb79132e28bbf1b5..ffc2bad28da7cf6a6d9d03f412697f59806e1103 100644 (file)
@@ -3,7 +3,7 @@
 # pytest fixture definitions.
 
 import pytest
-import util
+from tests import util
 
 @pytest.fixture
 def bfuse(tmpdir):
index 6b3e4741e2d8a6672f316f79cf187071f5910674..a2e95c5972d919bc8cd80ed231e0ad1f6ef2f3db 100644 (file)
@@ -3,7 +3,7 @@
 # Basic bcachefs functionality tests.
 
 import re
-import util
+from tests import util
 
 def test_help():
     ret = util.run_bch(valgrind=True)
index d8d3819e814427473b4f171a75c09f79d1650312..d96ce88d2311563d80f83ee3e494b6fdf80a5cc2 100644 (file)
@@ -2,16 +2,15 @@
 #
 # Tests of the functions in util.py
 
-import pytest
 import signal
 import subprocess
 import time
+import os
+import pytest
 
-import util
-from pathlib import Path
+from tests import util
 
-#helper = Path('.') / 'test_helper'
-helper = './test_helper'
+helper = os.path.abspath(os.path.join(util.BASE_PATH, 'test_helper'))
 
 def test_sparse_file(tmpdir):
     dev = util.sparse_file(tmpdir / '1k', 1024)
@@ -32,32 +31,32 @@ def test_segfault():
 @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)
+        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)
+        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)
+        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)
+        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)
+        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)
+        util.run(helper, 'write_after_free', valgrind=True)
 
 def test_mountpoint(tmpdir):
     path = util.mountpoint(tmpdir)
index 69c512e914fdd95fd30c21752eeb82f523abefd8..48288e6a9f43bf8677e5ef7c41c218eb7ecb5d06 100644 (file)
@@ -4,7 +4,7 @@
 
 import pytest
 import os
-import util
+from tests import util
 
 pytestmark = pytest.mark.skipif(
     not util.have_fuse(), reason="bcachefs not built with fuse support.")
index b5e02c13f9aee1623a5452c7614e8f1ac32dbc57..00314f4c24d6d7749e9def9bd6db29ad0bff4224 100644 (file)
@@ -2,18 +2,18 @@
 
 import errno
 import os
-import pytest
 import re
 import subprocess
-import sys
 import tempfile
 import threading
 import time
 
 from pathlib import Path
 
-DIR = Path('..')
-BCH_PATH = DIR / 'bcachefs'
+BASE_PATH= os.path.dirname(__file__)
+BCH_PATH = os.path.abspath(os.path.join(BASE_PATH, '..', 'bcachefs'))
+VALGRIND_PATH= os.path.abspath(os.path.join(BASE_PATH,
+    'valgrind-suppressions.txt'))
 
 VPAT = re.compile(r'ERROR SUMMARY: (\d+) errors from (\d+) contexts')
 
@@ -46,21 +46,22 @@ def run(cmd, *args, valgrind=False, check=False):
     cmds = [cmd] + list(args)
     valgrind = valgrind and ENABLE_VALGRIND
 
+    print("Running '{}'".format(cmds))
     if valgrind:
         vout = tempfile.NamedTemporaryFile()
         vcmd = ['valgrind',
                '--leak-check=full',
                '--gen-suppressions=all',
-               '--suppressions=valgrind-suppressions.txt',
+               '--suppressions={}'.format(VALGRIND_PATH),
                '--log-file={}'.format(vout.name)]
         cmds = vcmd + cmds
 
-    print("Running '{}'".format(cmds))
-    res = subprocess.run(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                         encoding='utf-8', check=check)
-
-    if valgrind:
+        res = subprocess.run(cmds, stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE, encoding='utf-8', check=check)
         check_valgrind(vout.read().decode('utf-8'))
+    else:
+        res = subprocess.run(cmds, stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE, encoding='utf-8', check=check)
 
     return res
 
@@ -75,7 +76,7 @@ def sparse_file(lpath, size):
     This is typically used to create device files for bcachefs.
     """
     path = Path(lpath)
-    f = path.touch(mode = 0o600, exist_ok = False)
+    path.touch(mode = 0o600, exist_ok = False)
     os.truncate(path, size)
 
     return path
@@ -195,7 +196,8 @@ class BFuse:
 
         self.stdout = out1 + out2
         self.stderr = err.read()
-        self.vout = vlog.read().decode('utf-8')
+        if vlog:
+            self.vout = vlog.read().decode('utf-8')
 
     def expect(self, pipe, regex):
         """Wait for the child process to mount."""
@@ -230,7 +232,8 @@ class BFuse:
             print("Waiting for thread to exit.")
             self.thread.join(timeout)
             if self.thread.is_alive():
-                self.proc.kill()
+                if self.proc:
+                    self.proc.kill()
                 self.thread.join()
         else:
             print("Thread was already done.")
@@ -242,6 +245,9 @@ class BFuse:
             check_valgrind(self.vout)
 
     def verify(self):
+        # avoid throwing exception in assertion
+        assert self.stdout is not None
+        assert self.stderr is not None
         assert self.returncode == 0
         assert len(self.stdout) > 0
         assert len(self.stderr) == 0