"Fossies" - the Fresh Open Source Software Archive

Member "fuse-3.2.3/test/test_ctests.py" (11 May 2018, 3270 Bytes) of package /linux/misc/fuse-3.2.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_ctests.py": 3.1.1_vs_3.2.0.

    1 #!/usr/bin/env python3
    2 
    3 if __name__ == '__main__':
    4     import pytest
    5     import sys
    6     sys.exit(pytest.main([__file__] + sys.argv[1:]))
    7 
    8 import subprocess
    9 import pytest
   10 import platform
   11 import sys
   12 from distutils.version import LooseVersion
   13 from util import (wait_for_mount, umount, cleanup, base_cmdline,
   14                   safe_sleep, basename, fuse_test_marker, fuse_caps,
   15                   fuse_proto)
   16 from os.path import join as pjoin
   17 import os.path
   18 
   19 pytestmark = fuse_test_marker()
   20 
   21 @pytest.mark.skipif('FUSE_CAP_WRITEBACK_CACHE' not in fuse_caps,
   22                     reason='not supported by running kernel')
   23 @pytest.mark.parametrize("writeback", (False, True))
   24 def test_write_cache(tmpdir, writeback):
   25     if writeback and LooseVersion(platform.release()) < '3.14':
   26         pytest.skip('Requires kernel 3.14 or newer')
   27     # This test hangs under Valgrind when running close(fd)
   28     # test_write_cache.c:test_fs(). Most likely this is because of an internal
   29     # deadlock in valgrind, it probably assumes that until close() returns,
   30     # control does not come to the program.
   31     mnt_dir = str(tmpdir)
   32     cmdline = [ pjoin(basename, 'test', 'test_write_cache'),
   33                 mnt_dir ]
   34     if writeback:
   35         cmdline.append('-owriteback_cache')
   36     subprocess.check_call(cmdline)
   37 
   38 
   39 names = [ 'notify_inval_inode', 'invalidate_path' ]
   40 if fuse_proto >= (7,15):
   41     names.append('notify_store_retrieve')
   42 @pytest.mark.skipif(fuse_proto < (7,12),
   43                     reason='not supported by running kernel')
   44 @pytest.mark.parametrize("name", names)
   45 @pytest.mark.parametrize("notify", (True, False))
   46 def test_notify1(tmpdir, name, notify):
   47     mnt_dir = str(tmpdir)
   48     cmdline = base_cmdline + \
   49               [ pjoin(basename, 'example', name),
   50                 '-f', '--update-interval=1', mnt_dir ]
   51     if not notify:
   52         cmdline.append('--no-notify')
   53     mount_process = subprocess.Popen(cmdline)
   54     try:
   55         wait_for_mount(mount_process, mnt_dir)
   56         filename = pjoin(mnt_dir, 'current_time')
   57         with open(filename, 'r') as fh:
   58             read1 = fh.read()
   59         safe_sleep(2)
   60         with open(filename, 'r') as fh:
   61             read2 = fh.read()
   62         if notify:
   63             assert read1 != read2
   64         else:
   65             assert read1 == read2
   66     except:
   67         cleanup(mnt_dir)
   68         raise
   69     else:
   70         umount(mount_process, mnt_dir)
   71 
   72 @pytest.mark.skipif(fuse_proto < (7,12),
   73                     reason='not supported by running kernel')
   74 @pytest.mark.parametrize("notify", (True, False))
   75 def test_notify_file_size(tmpdir, notify):
   76     mnt_dir = str(tmpdir)
   77     cmdline = base_cmdline + \
   78               [ pjoin(basename, 'example', 'invalidate_path'),
   79                 '-f', '--update-interval=1', mnt_dir ]
   80     if not notify:
   81         cmdline.append('--no-notify')
   82     mount_process = subprocess.Popen(cmdline)
   83     try:
   84         wait_for_mount(mount_process, mnt_dir)
   85         filename = pjoin(mnt_dir, 'growing')
   86         size = os.path.getsize(filename)
   87         safe_sleep(2)
   88         new_size = os.path.getsize(filename)
   89         if notify:
   90             assert new_size > size
   91         else:
   92             assert new_size == size
   93     except:
   94         cleanup(mnt_dir)
   95         raise
   96     else:
   97         umount(mount_process, mnt_dir)