From 2b39b48b09a10e672d9bfd2f255b862cf202da07 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 5 Nov 2025 20:59:30 +0530 Subject: [PATCH] pybind/cephfs: add tests for statxat() Signed-off-by: Rishabh Dave --- src/test/pybind/test_cephfs.py | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index df9311ef9e64..68210442f74b 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -1058,6 +1058,68 @@ class TestMkdirat: cephfs.close(fd) +class TestStatxat: + + def test_statxat_on_file(self, testdir): + cephfs.mkdir('dir1', 0o755) + fd = cephfs.open('dir1/file1', 'w', 0o755) + cephfs.write(fd, b'abcd', 0) + cephfs.close(fd) + + fd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755) + statx_buf = cephfs.statxat(fd, b'file1', libcephfs.CEPH_STATX_MODE, 0) + + mode = statx_buf['mode'] & ~stat.S_IFMT(statx_buf['mode']) + assert_equal(0o755, mode) + cephfs.close(fd) + + def test_statxat_on_dir(self, testdir): + cephfs.mkdir('dir1', 0o755) + cephfs.mkdir('dir1/dir2', 0o755) + + fd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755) + statx_buf = cephfs.statxat(fd, b'dir2', libcephfs.CEPH_STATX_MODE, 0) + + mode = statx_buf['mode'] & ~stat.S_IFMT(statx_buf['mode']) + assert_equal(0o755, mode) + cephfs.close(fd) + + def test_statxat_on_link(self, testdir): + cephfs.mkdir('dir1', 0o755) + fd = cephfs.open('dir1/file1', 'w', 0o644) + cephfs.write(fd, b'abcd', 0) + cephfs.close(fd) + + cephfs.chdir('dir1') + cephfs.symlink('file1', 'slink1') + cephfs.chdir('..') + + fd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755) + statx_buf = cephfs.statxat(fd, b'slink1', libcephfs.CEPH_STATX_MODE, + libcephfs.AT_SYMLINK_NOFOLLOW) + + mode = statx_buf['mode'] & ~stat.S_IFMT(statx_buf['mode']) + assert_equal(0o777, mode) + cephfs.close(fd) + + def test_statxat_on_link_follow_slink(self, testdir): + cephfs.mkdir('dir1', 0o755) + fd = cephfs.open('dir1/file1', 'w', 0o644) + cephfs.write(fd, b'abcd', 0) + cephfs.close(fd) + + cephfs.chdir('dir1') + cephfs.symlink('file1', 'slink1') + cephfs.chdir('..') + + fd = cephfs.open('dir1', os.O_RDONLY | os.O_DIRECTORY, 0o755) + statx_buf = cephfs.statxat(fd, b'slink1', libcephfs.CEPH_STATX_MODE, 0) + + mode = statx_buf['mode'] & ~stat.S_IFMT(statx_buf['mode']) + assert_equal(0o644, mode) + cephfs.close(fd) + + class TestWithRootUser: def setup_method(self): -- 2.47.3