From efd46d10fe08e63049ee349c3e619f07e5e78d66 Mon Sep 17 00:00:00 2001 From: Jevon Qiao Date: Mon, 15 Jun 2015 19:16:27 +0800 Subject: [PATCH] libcephfs: add test for ceph_p{read,write}v Add test in src/test/libcephfs/test.cc for ceph_preadv and ceph_pwritev interfaces. Signed-off-by: Jevon Qiao --- src/test/libcephfs/test.cc | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 33e531efd42df..9899e58cf6e5d 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __linux__ #include @@ -964,6 +965,44 @@ TEST(LibCephFS, ReadEmptyFile) { ceph_shutdown(cmount); } +TEST(LibCephFS, PreadvPwritev) { + struct ceph_mount_info *cmount; + ASSERT_EQ(ceph_create(&cmount, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); + ASSERT_EQ(ceph_mount(cmount, NULL), 0); + + int mypid = getpid(); + char testf[256]; + + sprintf(testf, "test_preadvpwritevfile%d", mypid); + int fd = ceph_open(cmount, testf, O_CREAT|O_RDWR, 0666); + ASSERT_GT(fd, 0); + + std::string str0("hello "); + std::string str1("world\n"); + struct iovec iovin[2]; + struct iovec iovout[2]; + ssize_t nwritten, nread; + + strcpy((char*)iovout[0].iov_base, str0.c_str()); + iovout[0].iov_len = str0.size(); + strcpy((char*)iovout[1].iov_base, str1.c_str()); + iovout[1].iov_len = str1.size(); + iovin[0].iov_len = str0.size(); + iovin[1].iov_len = str1.size(); + nwritten = iovout[0].iov_len + iovout[1].iov_len; + nread = iovin[0].iov_len + iovin[1].iov_len; + + ASSERT_EQ(ceph_pwritev(cmount, fd, iovout, 2, 0), nwritten); + ASSERT_EQ(ceph_preadv(cmount, fd, iovin, 2, 0), nread); + ASSERT_EQ(0, strncmp((const char*)iovin[0].iov_base, (const char*)iovout[0].iov_base, iovout[0].iov_len)); + ASSERT_EQ(0, strncmp((const char*)iovin[1].iov_base, (const char*)iovout[1].iov_base, iovout[1].iov_len)); + + ceph_close(cmount, fd); + ceph_shutdown(cmount); +} + TEST(LibCephFS, StripeUnitGran) { struct ceph_mount_info *cmount; ASSERT_EQ(ceph_create(&cmount, NULL), 0); -- 2.39.5