summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2012-11-28 16:25:22 -0800
committerNoah Watkins <noahwatkins@gmail.com>2013-01-05 11:42:44 -0800
commit8464e1c68372794241723d9c32df5ec7991b5f3d (patch)
tree833302213de045c9d4833fb90066b3124388d199
parente1112f9ae1c29165656c6540c6b36be712a92f7f (diff)
downloadceph-8464e1c68372794241723d9c32df5ec7991b5f3d.tar.gz
test: run w/ and w/o read from replica enabled
This patch does two things. First, it uses value-parameterized version of the test fixture which allows us to pass in a boolean flag that enables/disable read from replica feature. We create two instances of the fixture (true and false), so we run all the tests twice, once for each state. Existing tests use getpid() to create unique file names, but often don't clean up after themselves. Since each tests is run in the same process more than once, the names are no longer unique to the test instance. To handle this case we change the fixture to construct a unique directory that the mount is rooted in to create a clean room directory for each test. Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r--src/test/libcephfs/test.cc106
1 files changed, 80 insertions, 26 deletions
diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc
index 9cd6541a0a6..4217badd6cf 100644
--- a/src/test/libcephfs/test.cc
+++ b/src/test/libcephfs/test.cc
@@ -21,8 +21,16 @@
#include <sys/stat.h>
#include <dirent.h>
#include <sys/xattr.h>
+#include <sstream>
+#include <string>
+#include <algorithm>
-class ConfiguredMountTest : public ::testing::Test {
+/*
+ * The bool parameter to control localized reads isn't used in
+ * ConfiguredMountTest, and is only really needed in MountedTest. This is
+ * possible with gtest 1.6, but not 1.5 Maybe time to upgrade.
+ */
+class ConfiguredMountTest : public ::testing::TestWithParam<bool> {
protected:
struct ceph_mount_info *cmount;
@@ -43,8 +51,26 @@ class ConfiguredMountTest : public ::testing::Test {
};
class MountedTest : public ConfiguredMountTest {
+
+ std::string root;
+
protected:
virtual void SetUp() {
+ /* Grab test names to build clean room directory name */
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+
+ /* Create unique string using test/testname/pid */
+ std::stringstream ss_unique;
+ ss_unique << test_info->test_case_name() << "_" << test_info->name() << "_" << getpid();
+ std::string unique_path = ss_unique.str();
+ std::replace(unique_path.begin(), unique_path.end(), '/', '_');
+
+ /* Make absolute directory for mount root point */
+ root = unique_path;
+ root.insert(0, 1, '/');
+
+ /* Now mount */
ConfiguredMountTest::SetUp();
Mount();
}
@@ -63,11 +89,32 @@ class MountedTest : public ConfiguredMountTest {
private:
void Mount() {
- ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+ /* Setup clean room root directory */
+ ASSERT_EQ(ceph_mount(cmount, "/"), 0);
+
+ struct stat st;
+ int ret = ceph_stat(cmount, root.c_str(), &st);
+ if (ret == -ENOENT)
+ ASSERT_EQ(ceph_mkdir(cmount, root.c_str(), 0700), 0);
+ else {
+ ASSERT_EQ(ret, 0);
+ ASSERT_TRUE(S_ISDIR(st.st_mode));
+ }
+
+ /* Create completely fresh mount context */
+ ASSERT_EQ(ceph_unmount(cmount), 0);
+ ConfiguredMountTest::RefreshMount();
+
+ /* Mount with new root directory */
+ ASSERT_EQ(ceph_mount(cmount, root.c_str()), 0);
+
+ /* Use localized reads for this mount? */
+ bool localize = GetParam();
+ ASSERT_EQ(ceph_localize_reads(cmount, localize), 0);
}
};
-TEST_F(MountedTest, OpenEmptyComponent) {
+TEST_P(MountedTest, OpenEmptyComponent) {
pid_t mypid = getpid();
@@ -95,37 +142,37 @@ TEST_F(MountedTest, OpenEmptyComponent) {
ASSERT_EQ(0, ceph_close(cmount, fd));
}
-TEST_F(ConfiguredMountTest, MountNonExist) {
+TEST_P(ConfiguredMountTest, MountNonExist) {
ASSERT_NE(0, ceph_mount(cmount, "/non-exist"));
}
-TEST_F(MountedTest, MountDouble) {
+TEST_P(MountedTest, MountDouble) {
ASSERT_EQ(-EISCONN, ceph_mount(cmount, "/"));
}
-TEST_F(MountedTest, MountRemount) {
+TEST_P(MountedTest, MountRemount) {
CephContext *cct = ceph_get_mount_context(cmount);
Remount();
ASSERT_EQ(cct, ceph_get_mount_context(cmount));
}
-TEST_F(ConfiguredMountTest, UnmountUnmounted) {
+TEST_P(ConfiguredMountTest, UnmountUnmounted) {
ASSERT_EQ(-ENOTCONN, ceph_unmount(cmount));
}
-TEST_F(ConfiguredMountTest, ReleaseUnmounted) {
+TEST_P(ConfiguredMountTest, ReleaseUnmounted) {
// Default behavior of ConfiguredMountTest
}
-TEST_F(MountedTest, ReleaseMounted) {
+TEST_P(MountedTest, ReleaseMounted) {
ASSERT_EQ(-EISCONN, ceph_release(cmount));
}
-TEST_F(MountedTest, UnmountRelease) {
+TEST_P(MountedTest, UnmountRelease) {
// Default behavior of ConfiguredMountTest
}
-TEST_F(MountedTest, Mount) {
+TEST_P(MountedTest, Mount) {
/*
* Remount(true) will reproduce the following. The first mount operation is
* taken care of by the fixture.
@@ -144,7 +191,7 @@ TEST_F(MountedTest, Mount) {
Remount(true);
}
-TEST_F(MountedTest, OpenLayout) {
+TEST_P(MountedTest, OpenLayout) {
/* valid layout */
char test_layout_file[256];
sprintf(test_layout_file, "test_layout_%d_b", getpid());
@@ -180,7 +227,7 @@ TEST_F(MountedTest, OpenLayout) {
ASSERT_EQ(fd, -EINVAL);
}
-TEST_F(MountedTest, DirLs) {
+TEST_P(MountedTest, DirLs) {
pid_t mypid = getpid();
@@ -334,7 +381,7 @@ TEST_F(MountedTest, DirLs) {
ASSERT_EQ(ceph_closedir(cmount, ls_dir), 0);
}
-TEST_F(MountedTest, ManyNestedDirs) {
+TEST_P(MountedTest, ManyNestedDirs) {
const char *many_path = "a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a";
ASSERT_EQ(ceph_mkdirs(cmount, many_path, 0755), 0);
@@ -371,7 +418,7 @@ TEST_F(MountedTest, ManyNestedDirs) {
ASSERT_EQ(ceph_rmdir(cmount, "a/a/a"), 0);
}
-TEST_F(MountedTest, Xattrs) {
+TEST_P(MountedTest, Xattrs) {
char test_xattr_file[256];
sprintf(test_xattr_file, "test_xattr_%d", getpid());
int fd = ceph_open(cmount, test_xattr_file, O_CREAT, 0666);
@@ -416,13 +463,13 @@ TEST_F(MountedTest, Xattrs) {
ceph_close(cmount, fd);
}
-TEST_F(MountedTest, LstatSlashdot) {
+TEST_P(MountedTest, LstatSlashdot) {
struct stat stbuf;
ASSERT_EQ(ceph_lstat(cmount, "/.", &stbuf), 0);
ASSERT_EQ(ceph_lstat(cmount, ".", &stbuf), 0);
}
-TEST_F(MountedTest, DoubleChmod) {
+TEST_P(MountedTest, DoubleChmod) {
char test_file[256];
sprintf(test_file, "test_perms_%d", getpid());
@@ -470,7 +517,7 @@ TEST_F(MountedTest, DoubleChmod) {
ceph_close(cmount, fd);
}
-TEST_F(MountedTest, Fchmod) {
+TEST_P(MountedTest, Fchmod) {
char test_file[256];
sprintf(test_file, "test_perms_%d", getpid());
@@ -506,7 +553,7 @@ TEST_F(MountedTest, Fchmod) {
ceph_close(cmount, fd);
}
-TEST_F(MountedTest, Fchown) {
+TEST_P(MountedTest, Fchown) {
char test_file[256];
sprintf(test_file, "test_fchown_%d", getpid());
@@ -525,7 +572,7 @@ TEST_F(MountedTest, Fchown) {
ASSERT_EQ(fd, -EACCES);
}
-TEST_F(MountedTest, Symlinks) {
+TEST_P(MountedTest, Symlinks) {
char test_file[256];
sprintf(test_file, "test_symlinks_%d", getpid());
@@ -572,7 +619,7 @@ TEST_F(MountedTest, Symlinks) {
ASSERT_TRUE(S_ISLNK(stbuf_symlink.st_mode));
}
-TEST_F(MountedTest, DirSyms) {
+TEST_P(MountedTest, DirSyms) {
char test_dir1[256];
sprintf(test_dir1, "dir1_symlinks_%d", getpid());
@@ -596,7 +643,7 @@ TEST_F(MountedTest, DirSyms) {
ASSERT_TRUE(S_ISREG(stbuf.st_mode));
}
-TEST_F(MountedTest, LoopSyms) {
+TEST_P(MountedTest, LoopSyms) {
char test_dir1[256];
sprintf(test_dir1, "dir1_loopsym_%d", getpid());
@@ -629,7 +676,7 @@ TEST_F(MountedTest, LoopSyms) {
ASSERT_EQ(ceph_open(cmount, a, O_RDWR, 0), -ELOOP);
}
-TEST_F(MountedTest, HardlinkNoOriginal) {
+TEST_P(MountedTest, HardlinkNoOriginal) {
int mypid = getpid();
@@ -659,7 +706,7 @@ TEST_F(MountedTest, HardlinkNoOriginal) {
ASSERT_EQ(ceph_rmdir(cmount, dir), 0);
}
-TEST_F(MountedTest, BadFileDesc) {
+TEST_P(MountedTest, BadFileDesc) {
ASSERT_EQ(ceph_fchmod(cmount, -1, 0655), -EBADF);
ASSERT_EQ(ceph_close(cmount, -1), -EBADF);
ASSERT_EQ(ceph_lseek(cmount, -1, 0, SEEK_SET), -EBADF);
@@ -682,7 +729,7 @@ TEST_F(MountedTest, BadFileDesc) {
ASSERT_EQ(ceph_get_file_replication(cmount, -1), -EBADF);
}
-TEST_F(MountedTest, ReadEmptyFile) {
+TEST_P(MountedTest, ReadEmptyFile) {
// test the read_sync path in the client for zero files
ASSERT_EQ(ceph_conf_set(cmount, "client_debug_force_sync_read", "true"), 0);
@@ -704,7 +751,7 @@ TEST_F(MountedTest, ReadEmptyFile) {
ceph_close(cmount, fd);
}
-TEST_F(MountedTest, ReaddirRCB) {
+TEST_P(MountedTest, ReaddirRCB) {
char c_dir[256];
sprintf(c_dir, "/readdir_r_cb_tests_%d", getpid());
struct ceph_dir_result *dirp;
@@ -738,3 +785,10 @@ TEST_F(MountedTest, ReaddirRCB) {
ASSERT_EQ(4, ceph_getdnames(cmount, dirp, buf, 6));
ASSERT_LE(0, ceph_closedir(cmount, dirp));
}
+
+INSTANTIATE_TEST_CASE_P(ParamMount, MountedTest,
+ ::testing::Values(false, true));
+
+/* false parameter ignored. fix this when gtest upgraded to 1.6 */
+INSTANTIATE_TEST_CASE_P(ParamConfiguredMount, ConfiguredMountTest,
+ ::testing::Values(false));