Skip to content

Commit

Permalink
[Tests] Remove CppUnit code from common tests
Browse files Browse the repository at this point in the history
Convert also the common test code into shared library and link
tests against it instead of recompiling the code into each binary.
  • Loading branch information
amadio committed Feb 14, 2024
1 parent 74ab004 commit bf577fa
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 422 deletions.
3 changes: 0 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ add_subdirectory(common)

add_subdirectory(XrdCl)
add_subdirectory(XrdCeph)

if(BUILD_XRDEC)
add_subdirectory(XrdEc)
endif()

add_subdirectory(XrdHttpTests)

Expand Down
51 changes: 4 additions & 47 deletions tests/XrdCl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@ add_executable(xrdcl-unit-tests
XrdClPoller.cc
XrdClSocket.cc
XrdClUtilsTest.cc
../common/Server.cc
../common/Utils.cc
../common/TestEnv.cc
)

target_link_libraries(xrdcl-unit-tests
XrdCl
XrdXml
XrdUtils
ZLIB::ZLIB
GTest::GTest
GTest::Main
)

target_include_directories(xrdcl-unit-tests
PRIVATE ${CMAKE_SOURCE_DIR}/src ../common
)
XrdTestUtils GTest::GTest GTest::Main)

gtest_discover_tests(xrdcl-unit-tests TEST_PREFIX XrdCl::)

Expand All @@ -45,23 +32,10 @@ add_executable(xrdcl-cluster-tests
XrdClPostMasterTest.cc
XrdClThreadingTest.cc
XrdClZip.cc
../common/Server.cc
../common/Utils.cc
../common/TestEnv.cc
)

target_link_libraries(xrdcl-cluster-tests
XrdCl
XrdXml
XrdUtils
ZLIB::ZLIB
GTest::GTest
GTest::Main
)

target_include_directories(xrdcl-cluster-tests
PRIVATE ${CMAKE_SOURCE_DIR}/src ../common
)
XrdTestUtils GTest::GTest GTest::Main)

gtest_discover_tests(xrdcl-cluster-tests TEST_PREFIX XrdCl::
PROPERTIES DEPENDS XRootD_Cluster FIXTURES_REQUIRED XRootD_Cluster)
Expand All @@ -76,28 +50,11 @@ set(SERIAL_TESTS_FILES

# create a separate executable target for each "problematic" test suite
foreach(i ${SERIAL_TESTS_FILES})
add_executable(${i}-tests
${i}
IdentityPlugIn.cc
../common/Server.cc
../common/Utils.cc
../common/TestEnv.cc
)
add_executable(${i}-tests ${i} IdentityPlugIn.cc)

target_link_libraries(${i}-tests
XrdCl
XrdXml
XrdUtils
ZLIB::ZLIB
GTest::GTest
GTest::Main
)

target_include_directories(${i}-tests
PRIVATE ${CMAKE_SOURCE_DIR}/src ../common
)
XrdTestUtils GTest::GTest GTest::Main)

gtest_discover_tests(${i}-tests TEST_PREFIX XrdCl::
PROPERTIES DEPENDS XRootD_Cluster FIXTURES_REQUIRED XRootD_Cluster RUN_SERIAL 1)

endforeach()
24 changes: 4 additions & 20 deletions tests/XrdCl/GTestXrdHelpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,27 @@
#include <cerrno>
#include <cstring>

/** @brief Equivalent of CPPUNIT_ASSERT_XRDST
*
* Shows the code that we are asserting and its value
* in the final evaluation.
*/
/** Shows the code that we are asserting and its value in the final evaluation. */
#define GTEST_ASSERT_XRDST( x ) \
{ \
XrdCl::XRootDStatus _st = x; \
EXPECT_TRUE(_st.IsOK()) << "[" << #x << "]: " << _st.ToStr() << std::endl; \
}

/** @brief Equivalent of CPPUNIT_ASSERT_XRDST_NOTOK
*
* Shows the code that we are asserting and asserts that its
* execution is throwing an error.
*/
/** Shows the code that we are asserting and asserts that its execution is throwing an error. */
#define GTEST_ASSERT_XRDST_NOTOK( x, err ) \
{ \
XrdCl::XRootDStatus _st = x; \
EXPECT_TRUE(!_st.IsOK() && _st.code == err) << "[" << #x << "]: " << _st.ToStr() << std::endl; \
}

/** @brief Equivalent of CPPUNIT_ASSERT_ERRNO
*
* Shows the code that we are asserting and its error
* number.
*/
/** Shows the code that we are asserting and its error number. */
#define GTEST_ASSERT_ERRNO( x ) \
{ \
EXPECT_TRUE(x) << "[" << #x << "]: " << strerror(errno) << std::endl; \
}

/** @brief Equivalent of GTEST_ASSERT_PTHREAD
*
* Shows the code that we are asserting and its error
* number, in a thread-safe manner.
*/
/** Shows the code that we are asserting and its error number, in a thread-safe manner. */
#define GTEST_ASSERT_PTHREAD( x ) \
{ \
errno = x; \
Expand Down
29 changes: 8 additions & 21 deletions tests/XrdEc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
add_executable(xrdec-unit-tests
MicroTest.cc
../common/Server.cc
../common/Utils.cc
../common/TestEnv.cc
)
if(NOT BUILD_XRDEC)
return()
endif()

add_executable(xrdec-unit-tests XrdEcTests.cc)

target_link_libraries(xrdec-unit-tests
XrdEc
XrdCl
XrdXml
XrdUtils
ZLIB::ZLIB
GTest::GTest
GTest::Main
${ISAL_LIBRARIES}
)
XrdEc XrdTestUtils GTest::GTest GTest::Main ${ISAL_LIBRARIES})

target_include_directories(xrdec-unit-tests
PRIVATE ${CMAKE_SOURCE_DIR}/src
PRIVATE ../common
${ISAL_INCLUDE_DIRS}
)
target_include_directories(xrdec-unit-tests PRIVATE ${ISAL_INCLUDE_DIRS})

gtest_discover_tests(xrdec-unit-tests TEST_PREFIX XrdCl::)
gtest_discover_tests(xrdec-unit-tests TEST_PREFIX XrdEc::)
File renamed without changes.
44 changes: 6 additions & 38 deletions tests/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@


add_library(
XrdClTestsHelper SHARED
Server.cc Server.hh
Utils.cc Utils.hh
add_library(XrdTestUtils SHARED
Server.cc Server.hh
TestEnv.cc TestEnv.hh
CppUnitXrdHelpers.hh)

target_link_libraries(
XrdClTestsHelper
${CMAKE_THREAD_LIBS_INIT}
${CPPUNIT_LIBRARIES}
ZLIB::ZLIB
XrdCl
XrdUtils)

target_include_directories(
XrdClTestsHelper PUBLIC ${CPPUNIT_INCLUDE_DIRS})

add_executable(
test-runner
TextRunner.cc
PathProcessor.hh)

target_link_libraries(
test-runner
${CMAKE_DL_LIBS}
${CPPUNIT_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
Utils.cc Utils.hh)

target_include_directories(
test-runner PRIVATE ${CPPUNIT_INCLUDE_DIRS})
target_link_libraries(XrdTestUtils ZLIB::ZLIB XrdCl XrdUtils)

#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------
install(
TARGETS XrdClTestsHelper test-runner
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
target_include_directories(XrdTestUtils
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
57 changes: 0 additions & 57 deletions tests/common/CppUnitXrdHelpers.hh

This file was deleted.

83 changes: 0 additions & 83 deletions tests/common/PathProcessor.hh

This file was deleted.

0 comments on commit bf577fa

Please sign in to comment.