2017-05-26 04:22:43 +08:00
|
|
|
#!/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
|
2017-08-12 02:15:27 +08:00
|
|
|
import sys
|
2023-04-11 19:08:40 +08:00
|
|
|
from looseversion import LooseVersion
|
2017-05-26 04:22:43 +08:00
|
|
|
from util import (wait_for_mount, umount, cleanup, base_cmdline,
|
2017-08-24 23:00:15 +08:00
|
|
|
safe_sleep, basename, fuse_test_marker, fuse_caps,
|
|
|
|
fuse_proto)
|
2017-05-26 04:22:43 +08:00
|
|
|
from os.path import join as pjoin
|
2017-08-07 18:41:33 +08:00
|
|
|
import os.path
|
2017-05-26 04:22:43 +08:00
|
|
|
|
|
|
|
pytestmark = fuse_test_marker()
|
|
|
|
|
2017-08-25 15:49:23 +08:00
|
|
|
@pytest.mark.skipif('FUSE_CAP_WRITEBACK_CACHE' not in fuse_caps,
|
2017-08-24 23:00:15 +08:00
|
|
|
reason='not supported by running kernel')
|
2017-05-26 04:22:43 +08:00
|
|
|
@pytest.mark.parametrize("writeback", (False, True))
|
2019-07-05 04:20:41 +08:00
|
|
|
def test_write_cache(tmpdir, writeback, output_checker):
|
2017-05-26 04:22:43 +08:00
|
|
|
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')
|
2022-01-03 16:49:46 +08:00
|
|
|
elif LooseVersion(platform.release()) >= '5.16':
|
|
|
|
# Test that close(rofd) does not block waiting for pending writes.
|
|
|
|
# This test requires kernel commit a390ccb316be ("fuse: add FOPEN_NOFLUSH")
|
|
|
|
# so opt-in for this test from kernel 5.16.
|
|
|
|
cmdline.append('--delay_ms=200')
|
2019-07-05 04:20:41 +08:00
|
|
|
subprocess.check_call(cmdline, stdout=output_checker.fd, stderr=output_checker.fd)
|
2017-05-26 04:22:43 +08:00
|
|
|
|
|
|
|
|
2017-08-24 20:23:13 +08:00
|
|
|
names = [ 'notify_inval_inode', 'invalidate_path' ]
|
2017-08-24 23:00:15 +08:00
|
|
|
if fuse_proto >= (7,15):
|
2017-08-12 02:15:27 +08:00
|
|
|
names.append('notify_store_retrieve')
|
2017-08-24 23:00:15 +08:00
|
|
|
@pytest.mark.skipif(fuse_proto < (7,12),
|
|
|
|
reason='not supported by running kernel')
|
2017-08-12 02:15:27 +08:00
|
|
|
@pytest.mark.parametrize("name", names)
|
2017-05-26 04:22:43 +08:00
|
|
|
@pytest.mark.parametrize("notify", (True, False))
|
2019-07-05 04:20:41 +08:00
|
|
|
def test_notify1(tmpdir, name, notify, output_checker):
|
2017-05-26 04:22:43 +08:00
|
|
|
mnt_dir = str(tmpdir)
|
|
|
|
cmdline = base_cmdline + \
|
|
|
|
[ pjoin(basename, 'example', name),
|
|
|
|
'-f', '--update-interval=1', mnt_dir ]
|
|
|
|
if not notify:
|
|
|
|
cmdline.append('--no-notify')
|
2019-07-05 04:20:41 +08:00
|
|
|
mount_process = subprocess.Popen(cmdline, stdout=output_checker.fd,
|
|
|
|
stderr=output_checker.fd)
|
2017-05-26 04:22:43 +08:00
|
|
|
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:
|
2018-11-19 01:11:13 +08:00
|
|
|
cleanup(mount_process, mnt_dir)
|
2017-05-26 04:22:43 +08:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
umount(mount_process, mnt_dir)
|
|
|
|
|
2017-08-24 23:00:15 +08:00
|
|
|
@pytest.mark.skipif(fuse_proto < (7,12),
|
|
|
|
reason='not supported by running kernel')
|
2017-08-07 18:41:33 +08:00
|
|
|
@pytest.mark.parametrize("notify", (True, False))
|
2019-07-05 04:20:41 +08:00
|
|
|
def test_notify_file_size(tmpdir, notify, output_checker):
|
2017-08-07 18:41:33 +08:00
|
|
|
mnt_dir = str(tmpdir)
|
|
|
|
cmdline = base_cmdline + \
|
2017-08-24 20:23:13 +08:00
|
|
|
[ pjoin(basename, 'example', 'invalidate_path'),
|
2017-08-07 18:41:33 +08:00
|
|
|
'-f', '--update-interval=1', mnt_dir ]
|
|
|
|
if not notify:
|
|
|
|
cmdline.append('--no-notify')
|
2019-07-05 04:20:41 +08:00
|
|
|
mount_process = subprocess.Popen(cmdline, stdout=output_checker.fd,
|
|
|
|
stderr=output_checker.fd)
|
2017-08-07 18:41:33 +08:00
|
|
|
try:
|
|
|
|
wait_for_mount(mount_process, mnt_dir)
|
|
|
|
filename = pjoin(mnt_dir, 'growing')
|
|
|
|
size = os.path.getsize(filename)
|
|
|
|
safe_sleep(2)
|
|
|
|
new_size = os.path.getsize(filename)
|
|
|
|
if notify:
|
|
|
|
assert new_size > size
|
|
|
|
else:
|
|
|
|
assert new_size == size
|
|
|
|
except:
|
2019-11-20 19:38:33 +08:00
|
|
|
cleanup(mount_process, mnt_dir)
|
2017-08-07 18:41:33 +08:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
umount(mount_process, mnt_dir)
|