]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - tests/util.py
Fix python test_list
[bcachefs-tools-debian] / tests / util.py
index fd8efd4750082e2ffb539068ce53cb889f1bf377..41b13c05f7760d5da65db48e8190cea9128c0887 100644 (file)
@@ -16,16 +16,20 @@ 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'
+ENABLE_VALGRIND = os.getenv('BCACHEFS_TEST_USE_VALGRIND', 'no') == 'yes'
 
 class ValgrindFailedError(Exception):
     def __init__(self, log):
         self.log = log
 
-def check_valgrind(logfile):
-    log = logfile.read().decode('utf-8')
+def check_valgrind(log):
     m = VPAT.search(log)
-    assert m is not None, 'Internal error: valgrind log did not match.'
+    if m is None:
+        print('Internal error: valgrind log did not match.')
+        print('-- valgrind log:')
+        print(log)
+        print('-- end log --')
+        assert False
 
     errors = int(m.group(1))
     if errors > 0:
@@ -45,6 +49,8 @@ def run(cmd, *args, valgrind=False, check=False):
         vout = tempfile.NamedTemporaryFile()
         vcmd = ['valgrind',
                '--leak-check=full',
+               '--gen-suppressions=all',
+               '--suppressions=valgrind-suppressions.txt',
                '--log-file={}'.format(vout.name)]
         cmds = vcmd + cmds
 
@@ -53,7 +59,7 @@ def run(cmd, *args, valgrind=False, check=False):
                          encoding='utf-8', check=check)
 
     if valgrind:
-        check_valgrind(vout)
+        check_valgrind(vout.read().decode('utf-8'))
 
     return res
 
@@ -150,14 +156,16 @@ class BFuse:
     def run(self):
         """Background thread which runs "bcachefs fusemount" under valgrind"""
 
-        vout = None
+        vlog = None
         cmd = []
 
         if ENABLE_VALGRIND:
-            vout = tempfile.NamedTemporaryFile()
+            vlog = tempfile.NamedTemporaryFile()
             cmd += [ 'valgrind',
                      '--leak-check=full',
-                     '--log-file={}'.format(vout.name) ]
+                     '--gen-suppressions=all',
+                     '--suppressions=valgrind-suppressions.txt',
+                     '--log-file={}'.format(vlog.name) ]
 
         cmd += [ BCH_PATH,
                  'fusemount', '-f', self.dev, self.mnt]
@@ -178,7 +186,7 @@ class BFuse:
         self.stdout = out1 + out2
         self.stderr = err.read()
         self.returncode = self.proc.returncode
-        self.vout = vout
+        self.vout = vlog.read().decode('utf-8')
 
     def expect(self, pipe, regex):
         """Wait for the child process to mount."""
@@ -208,12 +216,15 @@ class BFuse:
     def unmount(self, timeout=None):
         print("Unmounting fuse.")
         run("fusermount3", "-zu", self.mnt)
-        print("Waiting for thread to exit.")
 
-        self.thread.join(timeout)
-        if self.thread.is_alive():
-            self.proc.kill()
-            self.thread.join()
+        if self.thread:
+            print("Waiting for thread to exit.")
+            self.thread.join(timeout)
+            if self.thread.is_alive():
+                self.proc.kill()
+                self.thread.join()
+        else:
+            print("Thread was already done.")
 
         self.thread = None
         self.ready.clear()