]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Add nonblocking I/O client test
authorFrank S. Filz <ffilzlnx@mindspring.com>
Wed, 11 May 2022 21:37:15 +0000 (14:37 -0700)
committerFrank S. Filz <ffilzlnx@mindspring.com>
Mon, 24 Jul 2023 18:49:04 +0000 (11:49 -0700)
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
src/test/client/CMakeLists.txt
src/test/client/nonblocking.cc [new file with mode: 0644]

index 1937bdd0b55423d63adcaa39dfeea3f6e39fedbb..63a461d71bfbee7333f20d502b2540d23f3d3668 100644 (file)
@@ -3,11 +3,13 @@ if(${WITH_CEPHFS})
     main.cc
     alternate_name.cc
     ops.cc
+    nonblocking.cc
     )
   target_link_libraries(ceph_test_client
     client
     global
     ceph-common
+    cephfs
     ${UNITTEST_LIBS}
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
diff --git a/src/test/client/nonblocking.cc b/src/test/client/nonblocking.cc
new file mode 100644 (file)
index 0000000..dafff45
--- /dev/null
@@ -0,0 +1,86 @@
+// -*- 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) 2022 Red Hat
+ *
+ * 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 <errno.h>
+
+#include <iostream>
+#include <string>
+
+#include <fmt/format.h>
+
+#include "test/client/TestClient.h"
+
+TEST_F(TestClient, LlreadvLlwritev) {
+  int mypid = getpid();
+  char filename[256];
+
+  client->unmount();
+  TearDown();
+  SetUp();
+
+  sprintf(filename, "test_llreadvllwritevfile%u", mypid);
+
+  Inode *root, *file;
+  root = client->get_root();
+  ASSERT_NE(root, (Inode *)NULL);
+
+  Fh *fh;
+  struct ceph_statx stx;
+
+  ASSERT_EQ(0, client->ll_createx(root, filename, 0666,
+                                 O_RDWR | O_CREAT | O_TRUNC,
+                                 &file, &fh, &stx, 0, 0, myperm));
+
+  /* Reopen read-only */
+  char out0[] = "hello ";
+  char out1[] = "world\n";
+  struct iovec iov_out[2] = {
+       {out0, sizeof(out0)},
+       {out1, sizeof(out1)},
+  };
+  char in0[sizeof(out0)];
+  char in1[sizeof(out1)];
+  struct iovec iov_in[2] = {
+       {in0, sizeof(in0)},
+       {in1, sizeof(in1)},
+  };
+
+  ssize_t nwritten = iov_out[0].iov_len + iov_out[1].iov_len;
+
+  std::unique_ptr<C_SaferCond> writefinish = nullptr;
+  std::unique_ptr<C_SaferCond> readfinish = nullptr;
+
+  writefinish.reset(new C_SaferCond("test-nonblocking"));
+  readfinish.reset(new C_SaferCond("test-nonblocking"));
+
+  int64_t rc;
+  bufferlist bl;
+  rc = client->ll_preadv_pwritev(fh, iov_out, 2, 0, true, writefinish.get(), nullptr);
+  ASSERT_EQ(0, rc);
+  rc = writefinish->wait();
+  ASSERT_EQ(nwritten, rc);
+
+  rc = client->ll_preadv_pwritev(fh, iov_in, 2, 0, false, readfinish.get(), &bl);
+  ASSERT_EQ(0, rc);
+  rc = readfinish.get()->wait();
+  ASSERT_EQ(nwritten, rc);
+  copy_bufferlist_to_iovec(iov_in, 2, &bl, rc);
+
+  ASSERT_EQ(0, strncmp((const char*)iov_in[0].iov_base, (const char*)iov_out[0].iov_base, iov_out[0].iov_len));
+  ASSERT_EQ(0, strncmp((const char*)iov_in[1].iov_base, (const char*)iov_out[1].iov_base, iov_out[1].iov_len));
+
+  client->ll_release(fh);
+  ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
+}
+