]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/test: add testcase file for low level sync io code paths 57576/head
authorDhairya Parmar <dparmar@redhat.com>
Mon, 20 May 2024 19:04:54 +0000 (00:34 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Tue, 21 May 2024 09:45:59 +0000 (15:15 +0530)
and test that providing null or invalid file handle returns an error as expected

Fixes: https://tracker.ceph.com/issues/66156
Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
src/test/client/CMakeLists.txt
src/test/client/syncio.cc [new file with mode: 0644]

index 718c52cb95a45fab0a6b9bba883b8f151042ef11..b085a954fb7a884a3a762c756c4b7f570c940a26 100644 (file)
@@ -5,6 +5,7 @@ if(${WITH_CEPHFS})
     ops.cc
     nonblocking.cc
     commands.cc
+    syncio.cc
     )
   target_link_libraries(ceph_test_client
     client
diff --git a/src/test/client/syncio.cc b/src/test/client/syncio.cc
new file mode 100644 (file)
index 0000000..f40503a
--- /dev/null
@@ -0,0 +1,79 @@
+// -*- 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) 2024 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, LlreadvLlwritevInvalidFileHandleSync) {
+    /* Test provding null or invalid file handle returns an error
+    as expected*/
+    Fh *fh_null = NULL;
+    char out_buf_0[] = "hello ";
+    char out_buf_1[] = "world\n";
+    struct iovec iov_out[2] = {
+        {out_buf_0, sizeof(out_buf_0)},
+        {out_buf_1, sizeof(out_buf_1)},
+    };
+
+    char in_buf_0[sizeof(out_buf_0)];
+    char in_buf_1[sizeof(out_buf_1)];
+    struct iovec iov_in[2] = {
+        {in_buf_0, sizeof(in_buf_0)},
+        {in_buf_1, sizeof(in_buf_1)},
+    };
+
+    int64_t rc;
+
+    rc = client->ll_writev(fh_null, iov_out, 2, 0);
+    ASSERT_EQ(rc, -CEPHFS_EBADF);
+
+    rc = client->ll_readv(fh_null, iov_in, 2, 0);
+    ASSERT_EQ(rc, -CEPHFS_EBADF);
+
+    // test after closing the file handle
+    int mypid = getpid();
+    char filename[256];
+
+    client->unmount();
+    TearDown();
+    SetUp();
+
+    sprintf(filename, "test_llreadvllwritevinvalidfhfile%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));
+
+    client->ll_release(fh);
+    ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
+
+    rc = client->ll_writev(fh, iov_out, 2, 0);
+    ASSERT_EQ(rc, -CEPHFS_EBADF);
+
+    rc = client->ll_readv(fh, iov_in, 2, 0);
+    ASSERT_EQ(rc, -CEPHFS_EBADF);
+}