16881f68fSopenharmony_ci#!/usr/bin/env python3 26881f68fSopenharmony_ci 36881f68fSopenharmony_ciif __name__ == '__main__': 46881f68fSopenharmony_ci import pytest 56881f68fSopenharmony_ci import sys 66881f68fSopenharmony_ci sys.exit(pytest.main([__file__] + sys.argv[1:])) 76881f68fSopenharmony_ci 86881f68fSopenharmony_ciimport subprocess 96881f68fSopenharmony_ciimport pytest 106881f68fSopenharmony_ciimport platform 116881f68fSopenharmony_ciimport sys 126881f68fSopenharmony_cifrom looseversion import LooseVersion 136881f68fSopenharmony_cifrom util import (wait_for_mount, umount, cleanup, base_cmdline, 146881f68fSopenharmony_ci safe_sleep, basename, fuse_test_marker, fuse_caps, 156881f68fSopenharmony_ci fuse_proto) 166881f68fSopenharmony_cifrom os.path import join as pjoin 176881f68fSopenharmony_ciimport os.path 186881f68fSopenharmony_ci 196881f68fSopenharmony_cipytestmark = fuse_test_marker() 206881f68fSopenharmony_ci 216881f68fSopenharmony_ci@pytest.mark.skipif('FUSE_CAP_WRITEBACK_CACHE' not in fuse_caps, 226881f68fSopenharmony_ci reason='not supported by running kernel') 236881f68fSopenharmony_ci@pytest.mark.parametrize("writeback", (False, True)) 246881f68fSopenharmony_cidef test_write_cache(tmpdir, writeback, output_checker): 256881f68fSopenharmony_ci if writeback and LooseVersion(platform.release()) < '3.14': 266881f68fSopenharmony_ci pytest.skip('Requires kernel 3.14 or newer') 276881f68fSopenharmony_ci # This test hangs under Valgrind when running close(fd) 286881f68fSopenharmony_ci # test_write_cache.c:test_fs(). Most likely this is because of an internal 296881f68fSopenharmony_ci # deadlock in valgrind, it probably assumes that until close() returns, 306881f68fSopenharmony_ci # control does not come to the program. 316881f68fSopenharmony_ci mnt_dir = str(tmpdir) 326881f68fSopenharmony_ci cmdline = [ pjoin(basename, 'test', 'test_write_cache'), 336881f68fSopenharmony_ci mnt_dir ] 346881f68fSopenharmony_ci if writeback: 356881f68fSopenharmony_ci cmdline.append('-owriteback_cache') 366881f68fSopenharmony_ci elif LooseVersion(platform.release()) >= '5.16': 376881f68fSopenharmony_ci # Test that close(rofd) does not block waiting for pending writes. 386881f68fSopenharmony_ci # This test requires kernel commit a390ccb316be ("fuse: add FOPEN_NOFLUSH") 396881f68fSopenharmony_ci # so opt-in for this test from kernel 5.16. 406881f68fSopenharmony_ci cmdline.append('--delay_ms=200') 416881f68fSopenharmony_ci subprocess.check_call(cmdline, stdout=output_checker.fd, stderr=output_checker.fd) 426881f68fSopenharmony_ci 436881f68fSopenharmony_ci 446881f68fSopenharmony_cinames = [ 'notify_inval_inode', 'invalidate_path' ] 456881f68fSopenharmony_ciif fuse_proto >= (7,15): 466881f68fSopenharmony_ci names.append('notify_store_retrieve') 476881f68fSopenharmony_ci@pytest.mark.skipif(fuse_proto < (7,12), 486881f68fSopenharmony_ci reason='not supported by running kernel') 496881f68fSopenharmony_ci@pytest.mark.parametrize("name", names) 506881f68fSopenharmony_ci@pytest.mark.parametrize("notify", (True, False)) 516881f68fSopenharmony_cidef test_notify1(tmpdir, name, notify, output_checker): 526881f68fSopenharmony_ci mnt_dir = str(tmpdir) 536881f68fSopenharmony_ci cmdline = base_cmdline + \ 546881f68fSopenharmony_ci [ pjoin(basename, 'example', name), 556881f68fSopenharmony_ci '-f', '--update-interval=1', mnt_dir ] 566881f68fSopenharmony_ci if not notify: 576881f68fSopenharmony_ci cmdline.append('--no-notify') 586881f68fSopenharmony_ci mount_process = subprocess.Popen(cmdline, stdout=output_checker.fd, 596881f68fSopenharmony_ci stderr=output_checker.fd) 606881f68fSopenharmony_ci try: 616881f68fSopenharmony_ci wait_for_mount(mount_process, mnt_dir) 626881f68fSopenharmony_ci filename = pjoin(mnt_dir, 'current_time') 636881f68fSopenharmony_ci with open(filename, 'r') as fh: 646881f68fSopenharmony_ci read1 = fh.read() 656881f68fSopenharmony_ci safe_sleep(2) 666881f68fSopenharmony_ci with open(filename, 'r') as fh: 676881f68fSopenharmony_ci read2 = fh.read() 686881f68fSopenharmony_ci if notify: 696881f68fSopenharmony_ci assert read1 != read2 706881f68fSopenharmony_ci else: 716881f68fSopenharmony_ci assert read1 == read2 726881f68fSopenharmony_ci except: 736881f68fSopenharmony_ci cleanup(mount_process, mnt_dir) 746881f68fSopenharmony_ci raise 756881f68fSopenharmony_ci else: 766881f68fSopenharmony_ci umount(mount_process, mnt_dir) 776881f68fSopenharmony_ci 786881f68fSopenharmony_ci@pytest.mark.skipif(fuse_proto < (7,12), 796881f68fSopenharmony_ci reason='not supported by running kernel') 806881f68fSopenharmony_ci@pytest.mark.parametrize("notify", (True, False)) 816881f68fSopenharmony_cidef test_notify_file_size(tmpdir, notify, output_checker): 826881f68fSopenharmony_ci mnt_dir = str(tmpdir) 836881f68fSopenharmony_ci cmdline = base_cmdline + \ 846881f68fSopenharmony_ci [ pjoin(basename, 'example', 'invalidate_path'), 856881f68fSopenharmony_ci '-f', '--update-interval=1', mnt_dir ] 866881f68fSopenharmony_ci if not notify: 876881f68fSopenharmony_ci cmdline.append('--no-notify') 886881f68fSopenharmony_ci mount_process = subprocess.Popen(cmdline, stdout=output_checker.fd, 896881f68fSopenharmony_ci stderr=output_checker.fd) 906881f68fSopenharmony_ci try: 916881f68fSopenharmony_ci wait_for_mount(mount_process, mnt_dir) 926881f68fSopenharmony_ci filename = pjoin(mnt_dir, 'growing') 936881f68fSopenharmony_ci size = os.path.getsize(filename) 946881f68fSopenharmony_ci safe_sleep(2) 956881f68fSopenharmony_ci new_size = os.path.getsize(filename) 966881f68fSopenharmony_ci if notify: 976881f68fSopenharmony_ci assert new_size > size 986881f68fSopenharmony_ci else: 996881f68fSopenharmony_ci assert new_size == size 1006881f68fSopenharmony_ci except: 1016881f68fSopenharmony_ci cleanup(mount_process, mnt_dir) 1026881f68fSopenharmony_ci raise 1036881f68fSopenharmony_ci else: 1046881f68fSopenharmony_ci umount(mount_process, mnt_dir) 105