Use printcap() to control test execution
authorNikolaus Rath <Nikolaus@rath.org>
Thu, 24 Aug 2017 15:00:15 +0000 (17:00 +0200)
committerNikolaus Rath <Nikolaus@rath.org>
Thu, 24 Aug 2017 15:19:07 +0000 (17:19 +0200)
That way, we run only tests that are supported by the running kernel.

test/test_ctests.py
test/test_examples.py
test/util.py

index 469c86777fcbbe9b772f1b77e01c5e15da2d0b36..fa21090348560031f834ce12629877ea2e7ac041 100644 (file)
@@ -11,14 +11,15 @@ import platform
 import sys
 from distutils.version import LooseVersion
 from util import (wait_for_mount, umount, cleanup, base_cmdline,
-                  safe_sleep, basename, fuse_test_marker)
+                  safe_sleep, basename, fuse_test_marker, fuse_caps,
+                  fuse_proto)
 from os.path import join as pjoin
 import os.path
 
 pytestmark = fuse_test_marker()
 
-@pytest.mark.skipif('bsd' in sys.platform,
-                    reason='writeback requires Linux')
+@pytest.mark.skipif('FUSE_CAP_WRITEBACK' not in fuse_caps,
+                    reason='not supported by running kernel')
 @pytest.mark.parametrize("writeback", (False, True))
 def test_write_cache(tmpdir, writeback):
     if writeback and LooseVersion(platform.release()) < '3.14':
@@ -36,8 +37,10 @@ def test_write_cache(tmpdir, writeback):
 
 
 names = [ 'notify_inval_inode', 'invalidate_path' ]
-if sys.platform == 'linux':
+if fuse_proto >= (7,15):
     names.append('notify_store_retrieve')
+@pytest.mark.skipif(fuse_proto < (7,12),
+                    reason='not supported by running kernel')
 @pytest.mark.parametrize("name", names)
 @pytest.mark.parametrize("notify", (True, False))
 def test_notify1(tmpdir, name, notify):
@@ -66,6 +69,8 @@ def test_notify1(tmpdir, name, notify):
     else:
         umount(mount_process, mnt_dir)
 
+@pytest.mark.skipif(fuse_proto < (7,12),
+                    reason='not supported by running kernel')
 @pytest.mark.parametrize("notify", (True, False))
 def test_notify_file_size(tmpdir, notify):
     mnt_dir = str(tmpdir)
index 599726b193172f5ecd20257369e8ee93b786ff62..5c7cddfebe09e5ec0b12394f637b93320cbb6661 100755 (executable)
@@ -18,19 +18,14 @@ import sys
 from tempfile import NamedTemporaryFile
 from contextlib import contextmanager
 from util import (wait_for_mount, umount, cleanup, base_cmdline,
-                  safe_sleep, basename, fuse_test_marker)
+                  safe_sleep, basename, fuse_test_marker, test_printcap,
+                  fuse_caps, fuse_proto)
 from os.path import join as pjoin
 
-TEST_FILE = __file__
-
 pytestmark = fuse_test_marker()
 
-def test_printcap():
-    cmdline = base_cmdline + [ pjoin(basename, 'example', 'printcap') ]
-    proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
-                            universal_newlines=True)
-    (stdout, _) = proc.communicate(30)
-    assert proc.returncode == 0
+TEST_FILE = __file__
+
 with open(TEST_FILE, 'rb') as fh:
     TEST_DATA = fh.read()
 
@@ -70,8 +65,10 @@ def test_hello(tmpdir, name, options):
     else:
         umount(mount_process, mnt_dir)
 
-@pytest.mark.skipif('bsd' in sys.platform,
-                    reason='not supported under BSD')
+
+@pytest.mark.skipif(not os.path.exists(
+    pjoin(basename, 'example', 'passthrough_ll')),
+    reason='not built')
 @pytest.mark.parametrize("writeback", (False, True))
 @pytest.mark.parametrize("debug", (False, True))
 def test_passthrough_ll(tmpdir, writeback, debug, capfd):
@@ -233,6 +230,8 @@ def test_null(tmpdir):
         umount(mount_process, mnt_file)
 
 
+@pytest.mark.skipif(fuse_proto < (7,12),
+                    reason='not supported by running kernel')
 @pytest.mark.parametrize("notify", (True, False))
 def test_notify_inval_entry(tmpdir, notify):
     mnt_dir = str(tmpdir)
@@ -615,3 +614,8 @@ def tst_passthrough(src_dir, mnt_dir):
     assert name in os.listdir(src_dir)
     assert name in os.listdir(mnt_dir)
     assert os.stat(src_name) == os.stat(mnt_name)
+
+# avoid warning about unused import
+test_printcap
+
+    
index 1cd09a1c9f95c191da59212d9cdecca36b3278a5..c15476bcf7d5bf2104ad6d2f24e975627f02f52c 100644 (file)
@@ -6,9 +6,31 @@ import stat
 import time
 from os.path import join as pjoin
 import sys
+import re
 
 basename = pjoin(os.path.dirname(__file__), '..')
 
+def test_printcap():
+    cmdline = base_cmdline + [ pjoin(basename, 'example', 'printcap') ]
+    proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
+                            universal_newlines=True)
+    (stdout, _) = proc.communicate(30)
+    assert proc.returncode == 0
+
+    proto = None
+    caps = set()
+    for line in stdout.split('\n'):
+        if line.startswith('\t'):
+            caps.add(line.strip())
+            continue
+
+        hit = re.match(r'Protocol version: (\d+)\.(\d+)$', line) 
+        if hit:
+            proto = (int(hit.group(1)), int(hit.group(2)))
+
+    return (proto, caps)
+
+
 def wait_for_mount(mount_process, mnt_dir,
                    test_fn=os.path.ismount):
     elapsed = 0
@@ -125,3 +147,11 @@ else:
 
 # Try to use local fusermount3
 os.environ['PATH'] = '%s:%s' % (pjoin(basename, 'util'), os.environ['PATH'])
+
+try:
+    (fuse_proto, fuse_caps) = test_printcap()
+except:
+    # Rely on test to raise error
+    fuse_proto = (0,0)
+    fuse_caps = set()
+