]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add test/rados-api/aio: SimpleWrite
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 9 Aug 2011 18:06:02 +0000 (11:06 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 9 Aug 2011 23:02:53 +0000 (16:02 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/Makefile.am
src/test/rados-api/aio.cc [new file with mode: 0644]

index 23ab5effbe10beb10067171867cec12b0a00e245..a8aa8a72078f5a2ca1cf073b58fb9fd7fc51448a 100644 (file)
@@ -575,6 +575,12 @@ test_rados_api_io_LDADD =  librados.la ${UNITTEST_LDADD}
 test_rados_api_io_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
 bin_DEBUGPROGRAMS += test_rados_api_io
 
+test_rados_api_aio_SOURCES = test/rados-api/aio.cc test/rados-api/test.cc
+test_rados_api_aio_LDFLAGS = ${AM_LDFLAGS}
+test_rados_api_aio_LDADD =  librados.la ${UNITTEST_LDADD}
+test_rados_api_aio_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+bin_DEBUGPROGRAMS += test_rados_api_aio
+
 # shell scripts
 editpaths = sed \
        -e 's|@bindir[@]|$(bindir)|g' \
diff --git a/src/test/rados-api/aio.cc b/src/test/rados-api/aio.cc
new file mode 100644 (file)
index 0000000..36425f8
--- /dev/null
@@ -0,0 +1,100 @@
+#include "include/rados/librados.h"
+#include "test/rados-api/test.h"
+
+#include "gtest/gtest.h"
+#include <errno.h>
+#include <semaphore.h>
+#include <string>
+
+class AioTestData
+{
+public:
+  AioTestData()
+    : m_init(false),
+      m_complete(false),
+      m_safe(false)
+  {
+  }
+
+  ~AioTestData()
+  {
+    if (m_init) {
+      rados_ioctx_destroy(m_ioctx);
+      destroy_one_pool(m_pool_name, &m_cluster);
+      sem_destroy(&m_sem);
+    }
+  }
+
+  int init()
+  {
+    int ret;
+    if (sem_init(&m_sem, 0, 0)) {
+      int err = errno;
+      sem_destroy(&m_sem);
+      return err;
+    }
+    std::string m_pool_name = get_temp_pool_name();
+    ret = create_one_pool(m_pool_name, &m_cluster);
+    if (ret) {
+      sem_destroy(&m_sem);
+      return ret;
+    }
+    ret = rados_ioctx_create(m_cluster, m_pool_name.c_str(), &m_ioctx);
+    if (ret) {
+      sem_destroy(&m_sem);
+      destroy_one_pool(m_pool_name, &m_cluster);
+      return ret;
+    }
+    m_init = true;
+    return 0;
+  }
+
+  sem_t m_sem;
+  rados_t m_cluster;
+  rados_ioctx_t m_ioctx;
+  rados_completion_t m_completion;
+  std::string m_pool_name;
+  bool m_init;
+  bool m_complete;
+  bool m_safe;
+};
+
+class TestAlarm
+{
+public:
+  TestAlarm() {
+    alarm(360);
+  }
+  ~TestAlarm() {
+    alarm(0);
+  }
+};
+
+void set_completion_complete(rados_completion_t cb, void *arg)
+{
+  AioTestData *test = (AioTestData*)arg;
+  test->m_complete = true;
+  sem_post(&test->m_sem);
+}
+
+void set_completion_safe(rados_completion_t cb, void *arg)
+{
+  AioTestData *test = (AioTestData*)arg;
+  test->m_safe = true;
+  sem_post(&test->m_sem);
+}
+
+TEST(LibRadosAio, SimpleWrite) {
+  AioTestData test_data;
+  rados_completion_t my_completion;
+  ASSERT_EQ(0, test_data.init());
+  ASSERT_EQ(0, rados_aio_create_completion((void*)&test_data,
+             set_completion_complete, set_completion_safe, &my_completion));
+  char buf[128];
+  memset(buf, 0xcc, sizeof(buf));
+  ASSERT_EQ(0, rados_aio_write(test_data.m_ioctx, "foo",
+                              my_completion, buf, sizeof(buf), 0));
+  TestAlarm alarm;
+  sem_wait(&test_data.m_sem);
+  sem_wait(&test_data.m_sem);
+}