From f270ba91215c3f14b1f44da0e5db0221226a5715 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sun, 2 Oct 2016 22:31:13 -0700 Subject: Run tests under valgrind when available. Fixes #50. --- test/conftest.py | 10 +++++++--- test/test_examples.py | 35 ++++++++++++++++++++--------------- test/test_fuse.py | 5 +++-- test/util.py | 13 +++++++++++++ 4 files changed, 43 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/conftest.py b/test/conftest.py index 0da2f4b..70cd0c6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -35,9 +35,13 @@ def check_test_output(capfd): if count == 0 or count - cnt > 0: stderr = cp.sub('', stderr, count=count - cnt) - for pattern in ('exception', 'error', 'warning', 'fatal', 'traceback', - 'fault', 'crash(?:ed)?', 'abort(?:ed)'): - cp = re.compile(r'\b{}\b'.format(pattern), re.IGNORECASE | re.MULTILINE) + patterns = [ r'\b{}\b'.format(x) for x in + ('exception', 'error', 'warning', 'fatal', 'traceback', + 'fault', 'crash(?:ed)?', 'abort(?:ed)', + 'uninitiali[zs]ed') ] + patterns += ['^==[0-9]+== '] + for pattern in patterns: + cp = re.compile(pattern, re.IGNORECASE | re.MULTILINE) hit = cp.search(stderr) if hit: raise AssertionError('Suspicious output to stderr (matched "%s")' % hit.group(0)) diff --git a/test/test_examples.py b/test/test_examples.py index 0acce19..5ddc860 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -14,7 +14,7 @@ import shutil import filecmp import errno from tempfile import NamedTemporaryFile -from util import wait_for_mount, umount, cleanup +from util import wait_for_mount, umount, cleanup, base_cmdline from os.path import join as pjoin basename = pjoin(os.path.dirname(__file__), '..') @@ -30,8 +30,9 @@ def name_generator(__ctr=[0]): @pytest.mark.parametrize("name", ('hello', 'hello_ll')) def test_hello(tmpdir, name): mnt_dir = str(tmpdir) - cmdline = [os.path.join(basename, 'example', name), - '-f', mnt_dir ] + cmdline = base_cmdline + \ + [ pjoin(basename, 'example', name), + '-f', mnt_dir ] if name == 'hello_ll': # supports single-threading only cmdline.append('-s') @@ -58,7 +59,8 @@ def test_fuse_lo_plus(tmpdir): mnt_dir = str(tmpdir.mkdir('mnt')) src_dir = str(tmpdir.mkdir('src')) - cmdline = [pjoin(basename, 'example', 'fuse_lo-plus'), + cmdline = base_cmdline + \ + [ pjoin(basename, 'example', 'fuse_lo-plus'), '-f', '-s', mnt_dir ] mount_process = subprocess.Popen(cmdline) try: @@ -90,8 +92,9 @@ def test_fusexmp_fh(tmpdir, name): mnt_dir = str(tmpdir.mkdir('mnt')) src_dir = str(tmpdir.mkdir('src')) - cmdline = [pjoin(basename, 'example', name), - '-f', '-o' , 'use_ino,readdir_ino,kernel_cache', + cmdline = base_cmdline + \ + [ pjoin(basename, 'example', name), + '-f', '-o', 'use_ino,readdir_ino,kernel_cache', mnt_dir ] mount_process = subprocess.Popen(cmdline) try: @@ -121,19 +124,20 @@ def test_fusexmp_fh(tmpdir, name): def test_fioc(tmpdir): mnt_dir = str(tmpdir) testfile = pjoin(mnt_dir, 'fioc') - cmdline = [pjoin(basename, 'example', 'fioc'), - '-f', mnt_dir ] + cmdline = base_cmdline + \ + [pjoin(basename, 'example', 'fioc'), '-f', mnt_dir ] mount_process = subprocess.Popen(cmdline) try: wait_for_mount(mount_process, mnt_dir) - base_cmd = [ pjoin(basename, 'example', 'fioclient'), - testfile ] - assert subprocess.check_output(base_cmd) == b'0\n' + cmdline = base_cmdline + \ + [ pjoin(basename, 'example', 'fioclient'), + testfile ] + assert subprocess.check_output(cmdline) == b'0\n' with open(testfile, 'wb') as fh: fh.write(b'foobar') - assert subprocess.check_output(base_cmd) == b'6\n' - subprocess.check_call(base_cmd + [ '3' ]) + assert subprocess.check_output(cmdline) == b'6\n' + subprocess.check_call(cmdline + [ '3' ]) with open(testfile, 'rb') as fh: assert fh.read()== b'foo' except: @@ -144,12 +148,13 @@ def test_fioc(tmpdir): def test_fsel(tmpdir): mnt_dir = str(tmpdir) - cmdline = [pjoin(basename, 'example', 'fsel'), + cmdline = base_cmdline + [pjoin(basename, 'example', 'fsel'), '-f', mnt_dir ] mount_process = subprocess.Popen(cmdline) try: wait_for_mount(mount_process, mnt_dir) - cmdline = [ pjoin(basename, 'example', 'fselclient') ] + cmdline = base_cmdline + \ + [ pjoin(basename, 'example', 'fselclient') ] subprocess.check_call(cmdline, cwd=mnt_dir) except: cleanup(mnt_dir) diff --git a/test/test_fuse.py b/test/test_fuse.py index bbba6e0..3c60d80 100755 --- a/test/test_fuse.py +++ b/test/test_fuse.py @@ -7,7 +7,7 @@ if __name__ == '__main__': import subprocess import os -from util import wait_for_mount, umount, cleanup +from util import wait_for_mount, umount, cleanup, base_cmdline basename = os.path.join(os.path.dirname(__file__), '..') @@ -15,7 +15,8 @@ def test_fuse(tmpdir): mnt_dir = str(tmpdir.mkdir('mnt')) src_dir = str(tmpdir.mkdir('src')) - cmdline = [ os.path.join(basename, 'example', 'fusexmp_fh'), + cmdline = base_cmdline + \ + [ os.path.join(basename, 'example', 'fusexmp_fh'), '-f', '-o' , 'use_ino,readdir_ino,kernel_cache', mnt_dir ] mount_process = subprocess.Popen(cmdline) diff --git a/test/util.py b/test/util.py index 48ec995..5f2f3e0 100644 --- a/test/util.py +++ b/test/util.py @@ -36,3 +36,16 @@ def umount(mount_process, mnt_dir): time.sleep(0.1) elapsed += 0.1 pytest.fail('mount process did not terminate') + + +# If valgrind and libtool are available, use them +def has_program(name): + return subprocess.call([name, '--version'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) == 0 + +if has_program('valgrind') and has_program('libtool'): + base_cmdline = [ 'libtool', '--mode=execute', + 'valgrind', '-q', '--' ] +else: + base_cmdline = [] -- cgit v1.2.3