From 339b09dc5921f81621f76faa55c56c31c16d4937 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Fri, 21 Feb 2020 15:13:10 -0500 Subject: [PATCH] test: add new ceph_lseek test Signed-off-by: Jeff Layton --- src/test/libcephfs/test.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 5bb0c77b2ef..f8c4b2bdcac 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -2273,3 +2273,40 @@ TEST(LibCephFS, SnapXattrs) { ceph_shutdown(cmount); } + +TEST(LibCephFS, Lseek) { + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + char c_path[1024]; + sprintf(c_path, "test_lseek_%d", getpid()); + int fd = ceph_open(cmount, c_path, O_RDWR|O_CREAT|O_TRUNC, 0666); + ASSERT_LT(0, fd); + + const char *out_buf = "hello world"; + size_t size = strlen(out_buf); + ASSERT_EQ(ceph_write(cmount, fd, out_buf, size, 0), (int)size); + + /* basic SEEK_SET/END/CUR tests */ + ASSERT_EQ(0, ceph_lseek(cmount, fd, 0, SEEK_SET)); + ASSERT_EQ(size, ceph_lseek(cmount, fd, 0, SEEK_END)); + ASSERT_EQ(0, ceph_lseek(cmount, fd, -size, SEEK_CUR)); + + /* Test basic functionality and out of bounds conditions for SEEK_HOLE/DATA */ +#ifdef SEEK_HOLE + ASSERT_EQ(size, ceph_lseek(cmount, fd, 0, SEEK_HOLE)); + ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, -1, SEEK_HOLE)); + ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, size + 1, SEEK_HOLE)); +#endif +#ifdef SEEK_DATA + ASSERT_EQ(0, ceph_lseek(cmount, fd, 0, SEEK_DATA)); + ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, -1, SEEK_DATA)); + ASSERT_EQ(-ENXIO, ceph_lseek(cmount, fd, size + 1, SEEK_DATA)); +#endif + + ASSERT_EQ(0, ceph_close(cmount, fd)); + ceph_shutdown(cmount); +} -- 2.47.3