Commit 9e74ff4d authored by kraus's avatar kraus
Browse files

cleaning up unit tests; make sure to install gtest somewhere and to export the...

cleaning up unit tests; make sure to install gtest somewhere and to export the corresponding variable first, there is an install script under tests/tools
parent b2ce57bd
......@@ -196,3 +196,13 @@ ENDIF()
ADD_SUBDIRECTORY (ippl)
ADD_SUBDIRECTORY (classic/5.0/src)
ADD_SUBDIRECTORY (src)
IF (BUILD_OPAL_UNIT_TESTS)
FIND_PACKAGE (GTest REQUIRED)
# touch CMakeLists to force cmake to redo the glob for new test source files
# otherwise cmake does not detect new source files
EXECUTE_PROCESS(COMMAND touch ${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt)
ADD_SUBDIRECTORY(tests)
ENDIF (BUILD_OPAL_UNIT_TESTS)
\ No newline at end of file
......@@ -84,13 +84,10 @@ include_directories (Solvers/amr
link_directories (
${IPPL_LIBRARY_DIR}
${CLASSIC_SOURCE_DIR}
${DOOM_SOURCE_DIR}
${Trilinos_LIBRARY_DIRS}
${Trilinos_TPL_LIBRARY_DIRS}
${CCSE_LIBRARY_DIR}
)
# "/opt/parmetis/parmetis-3.1"
# "/opt/intel-mkl/mkl-10.0/lib/em64t"
set (OPAL_LIBS
m
......@@ -109,28 +106,11 @@ set_target_properties( OPALib PROPERTIES OUTPUT_NAME OPAL )
add_executable( opal Main.cpp )
target_link_libraries( opal OPALib CLASSIC ${OPAL_LIBS} ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES} ${CCSE_LIBRARIES} ${OTHER_CMAKE_EXE_LINKER_FLAGS} -lgfortran ${CMAKE_DL_LIBS})
# build unit tests; unit tests are defined in unit_tests directory, we build the
# executable here so that we can use the OPAL src and lib definitions
if (BUILD_OPAL_UNIT_TESTS)
# touch CMakeLists to force cmake to redo the glob for new test source files
# otherwise cmake does not detect new source files
execute_process(COMMAND touch ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/CMakeLists.txt)
add_subdirectory(unit_tests)
# include and link gtest library
# this can be built using the script provided at
# unit_test/gtest/bin/install_gtest.bash
link_directories( ${GTEST_LIB_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../classic/5.0/src ${CMAKE_CURRENT_BINARY_DIR}/../ippl/src)
include_directories(${GTEST_INCLUDE_DIR})
# Check to see if cmake finds the test files
message(STATUS "unit test src files: ${TEST_SRCS}")
# Build the test exe. We don't do an install on the unit test exe as it is
# assumed that this is internal to opal
add_executable(${TEST_EXE} ${TEST_SRCS}) # the opal and classic sources are not needed again if we link agains libOPAL and libCLASSIC!
target_link_libraries(${TEST_EXE} OPALib CLASSIC ippl ${OPAL_LIBS} ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES} ${CCSE_LIBRARIES} -lgfortran ${OTHER_CMAKE_EXE_LINKER_FLAGS} ${GTEST_LINK_TARGETS} )
endif (BUILD_OPAL_UNIT_TESTS)
install (TARGETS ${TEST_EXE} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
install (TARGETS opal RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
install (TARGETS OPALib DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
install (FILES opal.h DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
install (FILES Utilities/OpalException.h DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Utilities")
\ No newline at end of file
install (FILES Utilities/OpalException.h DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Utilities")
set (OPAL_LIBS ${OPAL_LIBS} PARENT_SCOPE)
set (OPAL_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
\ No newline at end of file
cmake_minimum_required(VERSION 2.6)
# find the appropriate gtest includes and lib files; find tests from
# classic_src/*/*.cpp and opal_src/*/*.cpp and fill into the TEST_SRCS variable.
set (GTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gtest/include PARENT_SCOPE)
set (GTEST_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gtest/lib PARENT_SCOPE)
set (GTEST_LINK_TARGETS -lgtest -lgtest_main -lpthread PARENT_SCOPE)
set (TEST_EXE opal_unit_tests PARENT_SCOPE)
set(SRC_DIRS classic_src opal_src)
foreach(DIR ${SRC_DIRS})
file(GLOB TMP_SRC ${DIR}/*/*.cpp)
message(STATUS "In ${DIR}/*/*.cpp found source files ${TMP_SRC}")
set(TEST_SRC_LOCAL ${TMP_SRC} ${TEST_SRC_LOCAL})
endforeach(${DIR})
set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp ${TEST_SRC_LOCAL} PARENT_SCOPE)
cmake_minimum_required(VERSION 2.6)
set (TEST_EXE opal_unit_tests)
set (SRC_DIRS classic_src opal_src)
set (CMAKE_CXX_FLAGS
"${OPAL_CXX_FLAGS}"
)
set (TEST_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
macro (add_sources)
file (RELATIVE_PATH _relPath "${TEST_SRC_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
foreach (_src ${ARGN})
if (_relPath)
list (APPEND TEST_SRCS_LOCAL "${_relPath}/${_src}")
else()
list (APPEND TEST_SRCS_LOCAL "${_src}")
endif()
endforeach()
if (_relPath)
# propagate SRCS to parent directory
set (TEST_SRCS_LOCAL ${TEST_SRCS_LOCAL} PARENT_SCOPE)
endif()
endmacro()
add_subdirectory (opal_src)
add_subdirectory (classic_src)
set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp ${TEST_SRCS_LOCAL})
LINK_DIRECTORIES( ${GTEST_LIB_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${IPPL_LIBRARY_DIR}
${CLASSIC_SOURCE_DIR}
${OPAL_SOURCE_DIR}/src
${Trilinos_LIBRARY_DIRS}
${Trilinos_TPL_LIBRARY_DIRS}
${CCSE_LIBRARY_DIR}
)
INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${IPPL_INCLUDE_DIR}
${H5Hut_INCLUDE_DIR}
${HDF5_INCLUDE_DIR}
${GSL_INCLUDE_DIR}
${CLASSIC_SOURCE_DIR}
${OPAL_SOURCE_DIR}/src
${Trilinos_INCLUDE_DIRS}
${Trilinos_TPL_INCLUDE_DIRS}
${IPPL_SOURCE_DIRS}
${CCSE_INCLUDE_DIRS}
)
# Check to see if cmake finds the test files
# MESSAGE(STATUS "unit test src files: ${TEST_SRCS}")
# Build the test exe. We don't do an install on the unit test exe as it is
# assumed that this is internal to opal
ADD_EXECUTABLE(${TEST_EXE} ${TEST_SRCS}) # the opal and classic sources are not needed again if we link agains libOPAL and libCLASSIC!
TARGET_LINK_LIBRARIES(${TEST_EXE} OPALib CLASSIC ${OPAL_LIBS} ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES} ${CCSE_LIBRARIES} -lgfortran ${OTHER_CMAKE_EXE_LINKER_FLAGS} ${GTEST_BOTH_LIBRARIES} -lpthread)
\ No newline at end of file
set (_SRCS
OffsetTest.cpp
RingTest.cpp
SBend3DTest.cpp
VariableRFCavityTest.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_sources(${_SRCS})
\ No newline at end of file
......@@ -28,7 +28,7 @@
#include "gtest/gtest.h"
#include "AbsBeamline/Offset.h"
#include "unit_tests/opal_src/Utilities/MockComponent.h"
#include "opal_src/Utilities/MockComponent.h"
#include "AbsBeamline/Ring.h"
#include "Utilities/OpalException.h"
......@@ -381,4 +381,4 @@ TEST(RingTest, TestApply3) {
testField(0.1, 0.15, 0.2, Physics::pi/6.,
3.*cos(Physics::pi/6)+1.*sin(Physics::pi/6),
-3.*sin(Physics::pi/6)+1.*cos(Physics::pi/6), 2., 1e-6);
}
}
\ No newline at end of file
set (_SRCS
PolynomialTimeDependenceTest.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_sources(${_SRCS})
\ No newline at end of file
add_subdirectory (AbsBeamline)
add_subdirectory (Algorithms)
add_subdirectory (Utilities)
set (TEST_SRCS_LOCAL ${TEST_SRCS_LOCAL} PARENT_SCOPE)
\ No newline at end of file
set (_SRCS
RingSectionTest.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_sources(${_SRCS})
\ No newline at end of file
......@@ -28,7 +28,7 @@
#include <algorithm>
#include "gtest/gtest.h"
#include "unit_tests/opal_src/Utilities/MockComponent.h"
#include "opal_src/Utilities/MockComponent.h"
#include "Physics/Physics.h"
#include "Utilities/RingSection.h"
......@@ -215,4 +215,4 @@ TEST(RingSectionTest, TestDoesOverlap) {
EXPECT_TRUE(ors3.doesOverlap(f2, f3));
EXPECT_FALSE(ors3.doesOverlap(f1, f1));
EXPECT_FALSE(ors3.doesOverlap(f4, f4));
}
}
\ No newline at end of file
set (_SRCS
Test1.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_sources(${_SRCS})
\ No newline at end of file
add_subdirectory (Elements)
add_subdirectory (Utilities)
set (TEST_SRCS_LOCAL ${TEST_SRCS_LOCAL} PARENT_SCOPE)
\ No newline at end of file
set (_SRCS
OpalOffsetTest.cpp
OpalPolynomialTimeDependenceTest.cpp
OpalVariableRFCavityTest.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_sources(${_SRCS})
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment