Factored out C-based tests
authorNikolaus Rath <Nikolaus@rath.org>
Thu, 25 May 2017 20:22:43 +0000 (13:22 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Thu, 25 May 2017 20:23:56 +0000 (13:23 -0700)
test/meson.build
test/test_ctests.py [new file with mode: 0644]
test/test_examples.py

index c5b940f28c822c4e88147a9e6d2d40413bce8280..cf36405dae599db09021410f892d53f34ceaa7a0 100644 (file)
@@ -15,7 +15,7 @@ td += executable('test_syscalls', 'test_syscalls.c',
                  install: false)
 
 test_scripts = [ 'conftest.py', 'pytest.ini', 'test_examples.py',
-                 'util.py' ]
+                 'util.py', 'test_ctests.py' ]
 td += custom_target('test_scripts', input: test_scripts,
                       output: test_scripts, build_by_default: true,
                       command: ['cp', '-fPu', '--preserve=mode',
diff --git a/test/test_ctests.py b/test/test_ctests.py
new file mode 100644 (file)
index 0000000..ef643ef
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+if __name__ == '__main__':
+    import pytest
+    import sys
+    sys.exit(pytest.main([__file__] + sys.argv[1:]))
+
+import subprocess
+import pytest
+import platform
+from distutils.version import LooseVersion
+from util import (wait_for_mount, umount, cleanup, base_cmdline,
+                  safe_sleep, basename, fuse_test_marker)
+from os.path import join as pjoin
+
+pytestmark = fuse_test_marker()
+
+@pytest.mark.parametrize("writeback", (False, True))
+def test_write_cache(tmpdir, writeback):
+    if writeback and LooseVersion(platform.release()) < '3.14':
+        pytest.skip('Requires kernel 3.14 or newer')
+    # This test hangs under Valgrind when running close(fd)
+    # test_write_cache.c:test_fs(). Most likely this is because of an internal
+    # deadlock in valgrind, it probably assumes that until close() returns,
+    # control does not come to the program.
+    mnt_dir = str(tmpdir)
+    cmdline = [ pjoin(basename, 'test', 'test_write_cache'),
+                mnt_dir ]
+    if writeback:
+        cmdline.append('-owriteback_cache')
+    subprocess.check_call(cmdline)
+
+
+@pytest.mark.parametrize("name",
+                         ('notify_inval_inode',
+                          'notify_store_retrieve'))
+@pytest.mark.parametrize("notify", (True, False))
+def test_notify1(tmpdir, name, notify):
+    mnt_dir = str(tmpdir)
+    cmdline = base_cmdline + \
+              [ pjoin(basename, 'example', name),
+                '-f', '--update-interval=1', mnt_dir ]
+    if not notify:
+        cmdline.append('--no-notify')
+    mount_process = subprocess.Popen(cmdline)
+    try:
+        wait_for_mount(mount_process, mnt_dir)
+        filename = pjoin(mnt_dir, 'current_time')
+        with open(filename, 'r') as fh:
+            read1 = fh.read()
+        safe_sleep(2)
+        with open(filename, 'r') as fh:
+            read2 = fh.read()
+        if notify:
+            assert read1 != read2
+        else:
+            assert read1 == read2
+    except:
+        cleanup(mnt_dir)
+        raise
+    else:
+        umount(mount_process, mnt_dir)
+
+    
index 2c71a43dbe7ee3dafa1c8a7ec5a741d0d627f553..000859a4e10aa8f2f9bdd2bd9324fc415a3753d0 100755 (executable)
@@ -13,8 +13,6 @@ import stat
 import shutil
 import filecmp
 import errno
-import platform
-from distutils.version import LooseVersion
 from tempfile import NamedTemporaryFile
 from util import (wait_for_mount, umount, cleanup, base_cmdline,
                   safe_sleep, basename, fuse_test_marker)
@@ -177,36 +175,6 @@ def test_null(tmpdir):
         umount(mount_process, mnt_file)
 
 
-@pytest.mark.parametrize("name",
-                         ('notify_inval_inode',
-                          'notify_store_retrieve'))
-@pytest.mark.parametrize("notify", (True, False))
-def test_notify1(tmpdir, name, notify):
-    mnt_dir = str(tmpdir)
-    cmdline = base_cmdline + \
-              [ pjoin(basename, 'example', name),
-                '-f', '--update-interval=1', mnt_dir ]
-    if not notify:
-        cmdline.append('--no-notify')
-    mount_process = subprocess.Popen(cmdline)
-    try:
-        wait_for_mount(mount_process, mnt_dir)
-        filename = pjoin(mnt_dir, 'current_time')
-        with open(filename, 'r') as fh:
-            read1 = fh.read()
-        safe_sleep(2)
-        with open(filename, 'r') as fh:
-            read2 = fh.read()
-        if notify:
-            assert read1 != read2
-        else:
-            assert read1 == read2
-    except:
-        cleanup(mnt_dir)
-        raise
-    else:
-        umount(mount_process, mnt_dir)
-
 @pytest.mark.parametrize("notify", (True, False))
 def test_notify_inval_entry(tmpdir, notify):
     mnt_dir = str(tmpdir)
@@ -240,21 +208,6 @@ def test_notify_inval_entry(tmpdir, notify):
     else:
         umount(mount_process, mnt_dir)
 
-@pytest.mark.parametrize("writeback", (False, True))
-def test_write_cache(tmpdir, writeback):
-    if writeback and LooseVersion(platform.release()) < '3.14':
-        pytest.skip('Requires kernel 3.14 or newer')
-    # This test hangs under Valgrind when running close(fd)
-    # test_write_cache.c:test_fs(). Most likely this is because of an internal
-    # deadlock in valgrind, it probably assumes that until close() returns,
-    # control does not come to the program.
-    mnt_dir = str(tmpdir)
-    cmdline = [ pjoin(basename, 'test', 'test_write_cache'),
-                mnt_dir ]
-    if writeback:
-        cmdline.append('-owriteback_cache')
-    subprocess.check_call(cmdline)
-
 @pytest.mark.skipif(os.getuid() != 0,
                     reason='needs to run as root')
 def test_cuse(capfd):