summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lang <sam.lang@inktank.com>2012-11-29 12:14:19 -0600
committerSage Weil <sage@inktank.com>2012-11-29 15:04:06 -0800
commitf9056f5bd7b2027b74269db169852dd7b915475c (patch)
treecb4b81a1089c3deef5d0244c798138ce00c09f91
parente58008e0c0444e2a9e5a794dec1166db4691db02 (diff)
downloadceph-f9056f5bd7b2027b74269db169852dd7b915475c.tar.gz
test/libcephfs: Test reading an empty file
This tests a bug (#3490) in the Client::_read_sync codepath, and should be run with conf->client_read_sync_always set to true. Signed-off-by: Sam Lang <sam.lang@inktank.com>
-rw-r--r--src/test/libcephfs/test.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc
index 42fb411362d..644873b1a46 100644
--- a/src/test/libcephfs/test.cc
+++ b/src/test/libcephfs/test.cc
@@ -754,3 +754,31 @@ TEST(LibCephFS, BadFileDesc) {
ASSERT_EQ(ceph_get_file_pool(cmount, -1), -EBADF);
ASSERT_EQ(ceph_get_file_replication(cmount, -1), -EBADF);
}
+
+TEST(LibCephFS, ReadEmptyFile) {
+ struct ceph_mount_info *cmount;
+ ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+ ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+ ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+ // test the read_sync path in the client for zero files
+ ASSERT_EQ(ceph_conf_set(cmount, "client_debug_force_sync_read", "true"), 0);
+
+ int mypid = getpid();
+ char testf[256];
+
+ sprintf(testf, "test_reademptyfile%d", mypid);
+ int fd = ceph_open(cmount, testf, O_CREAT|O_TRUNC|O_WRONLY, 0644);
+ ASSERT_GT(fd, 0);
+
+ ceph_close(cmount, fd);
+
+ fd = ceph_open(cmount, testf, O_RDONLY, 0);
+ ASSERT_GT(fd, 0);
+
+ char buf[4096];
+ ASSERT_EQ(ceph_read(cmount, fd, buf, 4096, 0), 0);
+
+ ceph_close(cmount, fd);
+ ceph_shutdown(cmount);
+}