From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/test/libcephfs/caps.cc | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/test/libcephfs/caps.cc (limited to 'src/test/libcephfs/caps.cc') diff --git a/src/test/libcephfs/caps.cc b/src/test/libcephfs/caps.cc new file mode 100644 index 000000000..b4976c9c3 --- /dev/null +++ b/src/test/libcephfs/caps.cc @@ -0,0 +1,94 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ +#include "include/int_types.h" + +#include "gtest/gtest.h" +#include "include/ceph_fs.h" +#include "include/cephfs/libcephfs.h" +#include +#include +#include +#include +#include +#include +#ifdef __linux__ +#include +#endif +#include + +TEST(Caps, ReadZero) { + + int mypid = getpid(); + 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_mount(cmount, "/")); + + int i = 0; + for(; i < 30; ++i) { + + char c_path[1024]; + sprintf(c_path, "/caps_rzfile_%d_%d", mypid, i); + int fd = ceph_open(cmount, c_path, O_CREAT|O_TRUNC|O_WRONLY, 0644); + ASSERT_LT(0, fd); + + int expect = CEPH_CAP_FILE_EXCL | CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER; + int caps = ceph_debug_get_fd_caps(cmount, fd); + + ASSERT_EQ(expect, caps & expect); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + caps = ceph_debug_get_file_caps(cmount, c_path); + ASSERT_EQ(expect, caps & expect); + + char cw_path[1024]; + sprintf(cw_path, "/caps_wzfile_%d_%d", mypid, i); + int wfd = ceph_open(cmount, cw_path, O_CREAT|O_TRUNC|O_WRONLY, 0644); + ASSERT_LT(0, wfd); + + char wbuf[4096]; + ASSERT_EQ(4096, ceph_write(cmount, wfd, wbuf, 4096, 0)); + + ASSERT_EQ(0, ceph_close(cmount, wfd)); + + struct ceph_statx stx; + ASSERT_EQ(0, ceph_statx(cmount, c_path, &stx, CEPH_STATX_MTIME, 0)); + + caps = ceph_debug_get_file_caps(cmount, c_path); + ASSERT_EQ(expect, caps & expect); + } + + ASSERT_EQ(0, ceph_conf_set(cmount, "client_debug_inject_tick_delay", "20")); + + for(i = 0; i < 30; ++i) { + + char c_path[1024]; + sprintf(c_path, "/caps_rzfile_%d_%d", mypid, i); + + int fd = ceph_open(cmount, c_path, O_RDONLY, 0); + ASSERT_LT(0, fd); + char buf[256]; + + int expect = CEPH_CAP_FILE_RD | CEPH_STAT_CAP_SIZE | CEPH_CAP_FILE_CACHE; + int caps = ceph_debug_get_fd_caps(cmount, fd); + ASSERT_EQ(expect, caps & expect); + ASSERT_EQ(0, ceph_read(cmount, fd, buf, 256, 0)); + + caps = ceph_debug_get_fd_caps(cmount, fd); + ASSERT_EQ(expect, caps & expect); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + } + ceph_shutdown(cmount); +} -- cgit v1.2.3