From: Jeff Layton Date: Fri, 21 Feb 2020 20:13:10 +0000 (-0500) Subject: test: add new ceph_lseek test X-Git-Tag: v15.1.1~261^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33480%2Fhead;p=ceph.git test: add new ceph_lseek test Signed-off-by: Jeff Layton --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 5bb0c77b2efb..f8c4b2bdcac7 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); +}