diff options
author | Noah Watkins <noahwatkins@gmail.com> | 2012-12-09 11:19:04 -0800 |
---|---|---|
committer | Noah Watkins <noahwatkins@gmail.com> | 2013-01-05 11:40:41 -0800 |
commit | 8548a88d476adffdf7e01d2fee38a67d7675bd54 (patch) | |
tree | 50161e62fb4e8dc1e8932e5031a2454831b0a4b7 | |
parent | a90cce410e625b9d0bd00759f245c75c749d1c3f (diff) | |
download | ceph-8548a88d476adffdf7e01d2fee38a67d7675bd54.tar.gz |
test: consolidate tests into single file
This will avoid having to construct a new header file to be shared
between files with tests when the test fixture is added.
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/test/libcephfs/readdir_r_cb.cc | 60 | ||||
-rw-r--r-- | src/test/libcephfs/test.cc | 42 |
3 files changed, 43 insertions, 61 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 50267c3b188..babec35581f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -922,7 +922,7 @@ 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_SOURCES = test/libcephfs/test.cc test/libcephfs/readdir_r_cb.cc test/libcephfs/caps.cc +test_libcephfs_SOURCES = test/libcephfs/test.cc test/libcephfs/caps.cc test_libcephfs_LDFLAGS = $(PTHREAD_CFLAGS) ${AM_LDFLAGS} test_libcephfs_LDADD = ${UNITTEST_STATIC_LDADD} libcephfs.la test_libcephfs_CXXFLAGS = $(AM_CXXFLAGS) ${UNITTEST_CXXFLAGS} diff --git a/src/test/libcephfs/readdir_r_cb.cc b/src/test/libcephfs/readdir_r_cb.cc deleted file mode 100644 index 5afcd94f0f8..00000000000 --- a/src/test/libcephfs/readdir_r_cb.cc +++ /dev/null @@ -1,60 +0,0 @@ -// -*- 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> - -TEST(LibCephFS, ReaddirRCB) { - 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[256]; - sprintf(c_dir, "/readdir_r_cb_tests_%d", getpid()); - struct ceph_dir_result *dirp; - ASSERT_EQ(0, ceph_mkdirs(cmount, c_dir, 0777)); - ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); - - // dir is empty, check that it only contains . and .. - int buflen = 100; - char *buf = new char[buflen]; - // . is 2, .. is 3 (for null terminators) - ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, buflen)); - char c_file[256]; - sprintf(c_file, "/readdir_r_cb_tests_%d/foo", getpid()); - int fd = ceph_open(cmount, c_file, O_CREAT, 0777); - ASSERT_LT(0, fd); - - // check correctness with one entry - ASSERT_LE(0, ceph_closedir(cmount, dirp)); - ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); - ASSERT_EQ(9, ceph_getdnames(cmount, dirp, buf, buflen)); // ., .., foo - - // check correctness if buffer is too small - ASSERT_LE(0, ceph_closedir(cmount, dirp)); - ASSERT_GE(0, ceph_opendir(cmount, c_dir, &dirp)); - ASSERT_EQ(-ERANGE, ceph_getdnames(cmount, dirp, buf, 1)); - - //check correctness if it needs to split listing - ASSERT_LE(0, ceph_closedir(cmount, dirp)); - ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); - ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, 6)); - ASSERT_EQ(4, ceph_getdnames(cmount, dirp, buf, 6)); - ASSERT_LE(0, ceph_closedir(cmount, dirp)); - - ceph_shutdown(cmount); -} diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index f576fefd164..b8c62dff23e 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -803,3 +803,45 @@ TEST(LibCephFS, ReadEmptyFile) { ceph_close(cmount, fd); ceph_shutdown(cmount); } + +TEST(LibCephFS, ReaddirRCB) { + 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[256]; + sprintf(c_dir, "/readdir_r_cb_tests_%d", getpid()); + struct ceph_dir_result *dirp; + ASSERT_EQ(0, ceph_mkdirs(cmount, c_dir, 0777)); + ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); + + // dir is empty, check that it only contains . and .. + int buflen = 100; + char *buf = new char[buflen]; + // . is 2, .. is 3 (for null terminators) + ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, buflen)); + char c_file[256]; + sprintf(c_file, "/readdir_r_cb_tests_%d/foo", getpid()); + int fd = ceph_open(cmount, c_file, O_CREAT, 0777); + ASSERT_LT(0, fd); + + // check correctness with one entry + ASSERT_LE(0, ceph_closedir(cmount, dirp)); + ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); + ASSERT_EQ(9, ceph_getdnames(cmount, dirp, buf, buflen)); // ., .., foo + + // check correctness if buffer is too small + ASSERT_LE(0, ceph_closedir(cmount, dirp)); + ASSERT_GE(0, ceph_opendir(cmount, c_dir, &dirp)); + ASSERT_EQ(-ERANGE, ceph_getdnames(cmount, dirp, buf, 1)); + + //check correctness if it needs to split listing + ASSERT_LE(0, ceph_closedir(cmount, dirp)); + ASSERT_LE(0, ceph_opendir(cmount, c_dir, &dirp)); + ASSERT_EQ(5, ceph_getdnames(cmount, dirp, buf, 6)); + ASSERT_EQ(4, ceph_getdnames(cmount, dirp, buf, 6)); + ASSERT_LE(0, ceph_closedir(cmount, dirp)); + + ceph_shutdown(cmount); +} |