1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "include/int_types.h"
16 #include "gtest/gtest.h"
17 #include "include/ceph_fs.h"
18 #include "include/cephfs/libcephfs.h"
22 #include <sys/types.h>
25 #include <sys/xattr.h>
28 TEST(Caps, ReadZero) {
31 struct ceph_mount_info *cmount;
32 ASSERT_EQ(0, ceph_create(&cmount, NULL));
33 ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
34 ASSERT_EQ(0, ceph_mount(cmount, "/"));
40 sprintf(c_path, "/caps_rzfile_%d_%d", mypid, i);
41 int fd = ceph_open(cmount, c_path, O_CREAT|O_TRUNC|O_WRONLY, 0644);
44 int expect = CEPH_CAP_FILE_EXCL | CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER;
45 int caps = ceph_debug_get_fd_caps(cmount, fd);
47 ASSERT_EQ(expect, caps & expect);
48 ASSERT_EQ(0, ceph_close(cmount, fd));
50 caps = ceph_debug_get_file_caps(cmount, c_path);
51 ASSERT_EQ(expect, caps & expect);
54 sprintf(cw_path, "/caps_wzfile_%d_%d", mypid, i);
55 int wfd = ceph_open(cmount, cw_path, O_CREAT|O_TRUNC|O_WRONLY, 0644);
59 ASSERT_EQ(4096, ceph_write(cmount, wfd, wbuf, 4096, 0));
61 ASSERT_EQ(0, ceph_close(cmount, wfd));
63 struct ceph_statx stx;
64 ASSERT_EQ(0, ceph_statx(cmount, c_path, &stx, CEPH_STATX_MTIME, 0));
66 caps = ceph_debug_get_file_caps(cmount, c_path);
67 ASSERT_EQ(expect, caps & expect);
70 ASSERT_EQ(0, ceph_conf_set(cmount, "client_debug_inject_tick_delay", "20"));
72 for(i = 0; i < 30; ++i) {
75 sprintf(c_path, "/caps_rzfile_%d_%d", mypid, i);
77 int fd = ceph_open(cmount, c_path, O_RDONLY, 0);
81 int expect = CEPH_CAP_FILE_RD | CEPH_STAT_CAP_SIZE | CEPH_CAP_FILE_CACHE;
82 int caps = ceph_debug_get_fd_caps(cmount, fd);
83 ASSERT_EQ(expect, caps & expect);
84 ASSERT_EQ(0, ceph_read(cmount, fd, buf, 256, 0));
86 caps = ceph_debug_get_fd_caps(cmount, fd);
87 ASSERT_EQ(expect, caps & expect);
88 ASSERT_EQ(0, ceph_close(cmount, fd));
91 ceph_shutdown(cmount);