Skip to content

Commit

Permalink
[XrdCeph] Migrate tests to GoogleTest and run with ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Jun 18, 2024
1 parent d3165b3 commit df1471f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 356 deletions.
8 changes: 3 additions & 5 deletions src/XrdCeph/src/XrdCeph.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
include_directories( ${XROOTD_INCLUDE_DIR} )
include_directories( ${RADOS_INCLUDE_DIR} )
include_directories( ${CMAKE_SOURCE_DIR}/src )


#-------------------------------------------------------------------------------
# XrdCephPosix library version
#-------------------------------------------------------------------------------
Expand All @@ -28,6 +23,9 @@ target_link_libraries(
${XROOTD_LIBRARIES}
${RADOS_LIBS} )

target_include_directories(
XrdCephPosix PUBLIC ${RADOS_INCLUDE_DIR} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

set_target_properties(
XrdCephPosix
PROPERTIES
Expand Down
11 changes: 10 additions & 1 deletion src/XrdCeph/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
add_subdirectory( XrdCephTests )
find_package(GTest REQUIRED)

include(GoogleTest)

add_executable(xrdceph-unit-tests XrdCeph.cc)

target_link_libraries(xrdceph-unit-tests
XrdCephPosix GTest::GTest GTest::Main)

gtest_discover_tests(xrdceph-unit-tests TEST_PREFIX XrdCeph::)
111 changes: 111 additions & 0 deletions src/XrdCeph/tests/XrdCeph.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#undef NDEBUG

#include <XrdCeph/XrdCephPosix.hh>
#include <XrdOuc/XrdOucEnv.hh>

#include <gtest/gtest.h>

#define MB 1024 * 1024

struct CephFile {
std::string name;
std::string pool;
std::string userId;
unsigned int nbStripes;
unsigned long long stripeUnit;
unsigned long long objectSize;
};

void fillCephFile(const char *path, XrdOucEnv *env, CephFile &file);
void fillCephFileParams(const std::string &params, XrdOucEnv *env,
CephFile &file);

using namespace testing;

class ParsingTest : public ::testing::Test {};

static CephFile parseParam(std::string param, XrdOucEnv *env = NULL)
{
CephFile cf;
fillCephFileParams(param, env, cf);
return cf;
}

static CephFile parseFile(std::string param, XrdOucEnv *env = NULL)
{
CephFile cf;
fillCephFile(param.c_str(), env, cf);
return cf;
}

static void checkResult(CephFile a, CephFile b)
{
EXPECT_STREQ(a.name.c_str(), b.name.c_str());
EXPECT_STREQ(a.pool.c_str(), b.pool.c_str());
EXPECT_STREQ(a.userId.c_str(), b.userId.c_str());
EXPECT_EQ(a.nbStripes, b.nbStripes);
EXPECT_EQ(a.stripeUnit, b.stripeUnit);
EXPECT_EQ(a.objectSize, b.objectSize);
}

TEST(ParsingTest, Parameters)
{
std::map<std::string, CephFile> inputs;

inputs[""] = (CephFile){"", "default", "admin", 1, 4 * MB, 4 * MB};
inputs["pool"] = (CephFile){"", "pool", "admin", 1, 4 * MB, 4 * MB};
inputs["@"] = (CephFile){"", "default", "", 1, 4 * MB, 4 * MB};
inputs["@pool"] = (CephFile){"", "pool", "", 1, 4 * MB, 4 * MB};
inputs["user@"] = (CephFile){"", "default", "user", 1, 4 * MB, 4 * MB};
inputs["user@pool"] = (CephFile){"", "pool", "user", 1, 4 * MB, 4 * MB};
inputs["pool,1"] = (CephFile){"", "pool", "admin", 1, 4 * MB, 4 * MB};
inputs["user@pool,1"] = (CephFile){"", "pool", "user", 1, 4 * MB, 4 * MB};
inputs["pool,5"] = (CephFile){"", "pool", "admin", 5, 4 * MB, 4 * MB};
inputs["user@pool,5"] = (CephFile){"", "pool", "user", 5, 4 * MB, 4 * MB};
inputs["pool,5,200"] = (CephFile){"", "pool", "admin", 5, 200, 4 * MB};
inputs["user@pool,5,200"] = (CephFile){"", "pool", "user", 5, 200, 4 * MB};
inputs["pool,5,200,800"] = (CephFile){"", "pool", "admin", 5, 200, 800};
inputs["user@pool,5,200,800"] = (CephFile){"", "pool", "user", 5, 200, 800};

for (auto it = inputs.begin(); it != inputs.end(); it++)
checkResult(parseParam(it->first), it->second);
}

TEST(ParsingTest, File)
{
std::vector<std::string> filenames;
std::map<std::string, CephFile> inputs;

filenames.push_back("");
filenames.push_back("foo");
filenames.push_back("/foo/bar");
filenames.push_back("foo@bar");
filenames.push_back("foo@bar,1");
filenames.push_back("foo@bar,1,2");
filenames.push_back("foo@bar,1,2,3");
filenames.push_back("foo:bar");
filenames.push_back(":foo");

for (auto it = filenames.begin(); it != filenames.end(); it++) {
if (std::string::npos == it->find(':'))
inputs[*it] = (CephFile){*it, "default", "admin", 1, 4 * MB, 4 * MB};

inputs[":" + *it] = (CephFile){*it, "default", "admin", 1, 4 * MB, 4 * MB};
inputs["pool:" + *it] = (CephFile){*it, "pool", "admin", 1, 4 * MB, 4 * MB};
inputs["@:" + *it] = (CephFile){*it, "default", "", 1, 4 * MB, 4 * MB};
inputs["@pool:" + *it] = (CephFile){*it, "pool", "", 1, 4 * MB, 4 * MB};
inputs["user@:" + *it] = (CephFile){*it, "default", "user", 1, 4 * MB, 4 * MB};
inputs["user@pool:" + *it] = (CephFile){*it, "pool", "user", 1, 4 * MB, 4 * MB};
inputs["pool,1:" + *it] = (CephFile){*it, "pool", "admin", 1, 4 * MB, 4 * MB};
inputs["user@pool,1:" + *it] = (CephFile){*it, "pool", "user", 1, 4 * MB, 4 * MB};
inputs["pool,5:" + *it] = (CephFile){*it, "pool", "admin", 5, 4 * MB, 4 * MB};
inputs["user@pool,5:" + *it] = (CephFile){*it, "pool", "user", 5, 4 * MB, 4 * MB};
inputs["pool,5,200:" + *it] = (CephFile){*it, "pool", "admin", 5, 200, 4 * MB};
inputs["user@pool,5,200:" + *it] = (CephFile){*it, "pool", "user", 5, 200, 4 * MB};
inputs["pool,5,200,800:" + *it] = (CephFile){*it, "pool", "admin", 5, 200, 800};
inputs["user@pool,5,200,800:" + *it] = (CephFile){*it, "pool", "user", 5, 200, 800};
}

for (auto it = inputs.begin(); it != inputs.end(); it++)
checkResult(parseFile(it->first), it->second);
}
27 changes: 0 additions & 27 deletions src/XrdCeph/tests/XrdCephTests/CMakeLists.txt

This file was deleted.

149 changes: 0 additions & 149 deletions src/XrdCeph/tests/XrdCephTests/CephParsingTest.cc

This file was deleted.

4 changes: 0 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ if( BUILD_XRDEC )
add_subdirectory( XrdEc ) # new tests with GTest
endif()

if( BUILD_CEPH )
add_subdirectory( XrdCephTests )
endif()

add_subdirectory( XRootD )
add_subdirectory( cluster )
21 changes: 0 additions & 21 deletions tests/XrdCephTests/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit df1471f

Please sign in to comment.