]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Put all libcephfs gtest tests into one bin
authorSam Lang <sam.lang@inktank.com>
Wed, 26 Sep 2012 01:14:12 +0000 (18:14 -0700)
committerSam Lang <sam.lang@inktank.com>
Wed, 26 Sep 2012 01:14:12 +0000 (18:14 -0700)
* Modify the Makefile.am to run all gtest libcephfs tests through
a single binary: test_libcephfs.

* Add tests for #2285, #3186, and #2778

Signed-off-by: Sam Lang <sam.lang@inktank.com>
src/Makefile.am
src/test/libcephfs/test.cc [new file with mode: 0644]

index cd8e23322ecb4ea569de2c2934a3fad69cf12c51..9d338eb59e0fd890bc9bfe1df606ee70b31827c8 100644 (file)
@@ -854,11 +854,11 @@ test_rados_api_misc_LDADD =  librados.la ${UNITTEST_STATIC_LDADD}
 test_rados_api_misc_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
 bin_DEBUGPROGRAMS += test_rados_api_misc
 
-test_libcephfs_readdir_SOURCES = test/libcephfs/readdir_r_cb.cc
-test_libcephfs_readdir_LDFLAGS = $(PTHREAD_CFLAGS) ${AM_LDFLAGS}
-test_libcephfs_readdir_LDADD =  ${UNITTEST_STATIC_LDADD} libcephfs.la
-test_libcephfs_readdir_CXXFLAGS = $(AM_CXXFLAGS) ${UNITTEST_CXXFLAGS}
-bin_DEBUGPROGRAMS += test_libcephfs_readdir
+test_libcephfs_SOURCES = test/libcephfs/test.cc test/libcephfs/readdir_r_cb.cc
+test_libcephfs_LDFLAGS = $(PTHREAD_CFLAGS) ${AM_LDFLAGS}
+test_libcephfs_LDADD =  ${UNITTEST_STATIC_LDADD} libcephfs.la
+test_libcephfs_CXXFLAGS = $(AM_CXXFLAGS) ${UNITTEST_CXXFLAGS}
+bin_DEBUGPROGRAMS += test_libcephfs
 
 test_filestore_SOURCES = test/filestore/store_test.cc
 test_filestore_LDFLAGS = ${AM_LDFLAGS}
diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc
new file mode 100644 (file)
index 0000000..af79b72
--- /dev/null
@@ -0,0 +1,67 @@
+// -*- 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 "gtest/gtest.h"
+#include "include/cephfs/libcephfs.h"
+#include <errno.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+TEST(LibCephFS, Open_empty_component) {
+
+  pid_t 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, "/"));
+
+  char c_dir[1024];
+  sprintf(c_dir, "/open_test_%d", mypid);
+  struct ceph_dir_result *dirp;
+
+  ASSERT_EQ(0, ceph_mkdirs(cmount, c_dir, 0777));
+
+  ASSERT_EQ(0, ceph_opendir(cmount, c_dir, &dirp));
+
+  char c_path[1024];
+  sprintf(c_path, "/open_test_%d//created_file_%d", mypid, mypid);
+  int fd = ceph_open(cmount, c_path, O_RDONLY|O_CREAT, 0666);
+  ASSERT_LT(0, fd);
+
+  ASSERT_EQ(0, ceph_close(cmount, fd));
+  ASSERT_EQ(0, ceph_closedir(cmount, dirp));
+  ceph_shutdown(cmount);
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+
+  fd = ceph_open(cmount, c_path, O_RDONLY, 0666);
+  ASSERT_LT(0, fd);
+
+  ASSERT_EQ(0, ceph_close(cmount, fd));
+  ASSERT_EQ(0, ceph_closedir(cmount, dirp));
+  ceph_shutdown(cmount);
+}
+
+TEST(LibCephFS, Mount_non_exist) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_NE(0, ceph_mount(cmount, "/non-exist"));
+}