Improvements

- split `cgal_add_test()` into `cgal_add_test()` and
  `cgal_add_compilation_test()`

- `cgal_add_test()` have more parameters:
  - an optional custom `TEST_NAME`,
  - extra arguments to use for the test.

- Add CTest support for `test/Sweep_line_2/`
This commit is contained in:
Laurent Rineau 2017-11-03 09:33:11 +01:00
parent 39cb35b134
commit 855d995e1e
3 changed files with 99 additions and 47 deletions

View File

@ -157,20 +157,14 @@ function(cgal_arr_2_add_target exe_name source_file)
cgal_debug_message(STATUS "# -> target ${name} with TESTSUITE_CXXFLAGS: ${flags}")
if(BUILD_TESTING)
add_test(NAME "compilation_of__${name}"
COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${name}")
set_property(TEST "compilation_of__${name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
cgal_add_compilation_test(${name})
endif(BUILD_TESTING)
# Add a compatibility-mode with the shell script `cgal_test_base`
if(NOT TARGET ${exe_name})
create_single_source_cgal_program( "${source_file}" NO_TESTING)
if(BUILD_TESTING)
add_test(NAME "compilation_of__${exe_name}"
COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}")
set_property(TEST "compilation_of__${exe_name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
cgal_add_compilation_test(${exe_name})
endif(BUILD_TESTING)
endif()
endfunction()

View File

@ -7,6 +7,8 @@ if(POLICY CMP0064)
cmake_policy(SET CMP0064 NEW)
endif()
include(CMakeParseArguments)
option(CGAL_CTEST_DISPLAY_MEM_AND_TIME
"Display memory and real time usage at end of CTest test outputs"
FALSE)
@ -58,51 +60,75 @@ function(expand_list_with_globbing list_name)
set(${list_name} ${output_list} PARENT_SCOPE)
endfunction()
function(cgal_add_test exe_name)
if(NOT TEST compilation_of__${exe_name})
add_test(NAME "compilation_of__${exe_name}"
COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}")
function(cgal_add_compilation_test exe_name)
if(TEST compilation_of__${exe_name})
return()
endif()
add_test(NAME "compilation_of__${exe_name}"
COMMAND ${TIME_COMMAND} "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "${exe_name}")
set_property(TEST "compilation_of__${exe_name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
endfunction(cgal_add_compilation_test)
function(cgal_add_test exe_name)
cgal_add_compilation_test(${exe_name})
cmake_parse_arguments("cgal_add_test" # prefix
"" # optional arguments
"TEST_NAME" # single arguments
"" # multivalue arguments
${ARGN})
set(ARGS ${cgal_add_test_UNPARSED_ARGUMENTS})
set(test_name ${cgal_add_test_TEST_NAME})
# message(" test_name: ${test_name}")
if(NOT test_name)
set(test_name "execution___of__${exe_name}")
endif()
# message(" test_name: ${test_name}")
if(TEST ${test_name})
return()
endif()
# message("Add test ${test_name}")
set(cin_file "${CGAL_CURRENT_SOURCE_DIR}/${exe_name}.cin")
if(EXISTS ${cin_file})
add_test(NAME execution___of__${exe_name}
if(NOT ARGS AND EXISTS ${cin_file})
add_test(NAME ${test_name}
COMMAND ${TIME_COMMAND} ${CMAKE_COMMAND}
-DCMD:STRING=$<TARGET_FILE:${exe_name}>
-DCIN:STRING=${cin_file}
-P "${CGAL_MODULES_DIR}/run_test_with_cin.cmake")
# message(STATUS "add test: ${exe_name} < ${cin_file}")
else()
if(ARGC GREATER 2 AND ARGV2)
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${ARGV2}.cmd")
elseif(ARGC GREATER 1 AND ARGV1 AND NOT EXISTS ${cmd_file})
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${ARGV1}.cmd")
elseif(NOT EXISTS ${cmd_file})
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${exe_name}.cmd")
endif()
if(EXISTS ${cmd_file})
file(STRINGS "${cmd_file}" CMD_LINES)
set(ARGS)
# message(STATUS "DEBUG test ${exe_name}")
foreach(CMD_LINE ${CMD_LINES})
# message(STATUS " command line: ${CMD_LINE}")
string(REGEX REPLACE "\#.*" "" CMD_LINE "${CMD_LINE}")
separate_arguments(CMD_LINE_ARGS UNIX_COMMAND ${CMD_LINE})
# message(STATUS " args: ${CMD_LINE_ARGS}")
list(APPEND ARGS ${CMD_LINE_ARGS})
endforeach()
expand_list_with_globbing(ARGS)
if(NOT ARGS)
if(ARGC GREATER 2 AND ARGV2)
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${ARGV2}.cmd")
elseif(ARGC GREATER 1 AND ARGV1 AND NOT EXISTS ${cmd_file})
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${ARGV1}.cmd")
elseif(NOT EXISTS ${cmd_file})
set(cmd_file "${CGAL_CURRENT_SOURCE_DIR}/${exe_name}.cmd")
endif()
if(EXISTS ${cmd_file})
file(STRINGS "${cmd_file}" CMD_LINES)
set(ARGS)
# message(STATUS "DEBUG test ${exe_name}")
foreach(CMD_LINE ${CMD_LINES})
# message(STATUS " command line: ${CMD_LINE}")
string(REGEX REPLACE "\#.*" "" CMD_LINE "${CMD_LINE}")
separate_arguments(CMD_LINE_ARGS UNIX_COMMAND ${CMD_LINE})
# message(STATUS " args: ${CMD_LINE_ARGS}")
list(APPEND ARGS ${CMD_LINE_ARGS})
endforeach()
expand_list_with_globbing(ARGS)
endif()
endif()
# message(STATUS "add test: ${exe_name} ${ARGS}")
add_test(NAME execution___of__${exe_name} COMMAND ${TIME_COMMAND} $<TARGET_FILE:${exe_name}> ${ARGS})
add_test(NAME ${test_name} COMMAND ${TIME_COMMAND} $<TARGET_FILE:${exe_name}> ${ARGS})
endif()
set_property(TEST "execution___of__${exe_name}"
set_property(TEST "${test_name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
# message(STATUS " working dir: ${CGAL_CURRENT_SOURCE_DIR}")
set_property(TEST "execution___of__${exe_name}"
set_property(TEST "${test_name}"
PROPERTY WORKING_DIRECTORY ${CGAL_CURRENT_SOURCE_DIR})
set_property(TEST "compilation_of__${exe_name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
set_property(TEST "execution___of__${exe_name}"
set_property(TEST "${test_name}"
APPEND PROPERTY DEPENDS "compilation_of__${exe_name}")
if(POLICY CMP0066) # CMake 3.7 or later
@ -130,7 +156,7 @@ function(cgal_add_test exe_name)
endif()
set_property(TEST "compilation_of__${exe_name}"
PROPERTY FIXTURES_SETUP "${exe_name}")
set_tests_properties("execution___of__${exe_name}"
set_tests_properties("${test_name}"
PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/__exec_test_dir
FIXTURES_REQUIRED "${PROJECT_NAME};${exe_name}")
@ -152,9 +178,9 @@ function(cgal_add_test exe_name)
# see https://github.com/CGAL/cgal/pull/1295/files/c65d3abe17bb3e677b8077996cdaf8672f9c4c6f#r71705451
endif()
string(REPLACE ";" " " args_str "${ARGS}")
add_test(NAME execution___of__${exe_name}
add_test(NAME ${test_name}
COMMAND ${TIME_COMMAND} $<TARGET_FILE:${exe_name}> ${ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_property(TEST "execution___of__${exe_name}"
set_property(TEST "${test_name}"
APPEND PROPERTY LABELS "${PROJECT_NAME}")
endfunction()

View File

@ -8,6 +8,15 @@ cmake_minimum_required(VERSION 2.8.10)
find_package(CGAL QUIET COMPONENTS Core )
set(CGAL_SEGMENT_TRAITS 1)
set(CGAL_SEGMENT_LEDA_TRAITS 2)
set(CGAL_POLYLINE_TRAITS 11)
set(CGAL_CONIC_TRAITS 21)
set(TRAP 1) # Trapezoidal decomposition
set(NAIVE 2)
set(WALK 3)
if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} )
@ -16,11 +25,34 @@ if ( CGAL_FOUND )
include_directories (BEFORE "../../include")
# create a target per cppfile
file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(cppfile ${cppfiles})
create_single_source_cgal_program( "${cppfile}" )
endforeach()
function(compile name source_file point_location traits)
message(compile ${source_file})
add_executable(${name} ${source_file})
add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${name} )
target_link_libraries(${name} CGAL::CGAL CGAL::CGAL_Core)
target_compile_definitions(${name} PRIVATE
-DCGAL_ARR_TEST_POINT_LOCATION=${point_location}
-DCGAL_ARR_TEST_TRAITS=${traits}
)
endfunction()
function(compile_and_run_sweep name source_file point_location traits data_set)
compile(${ARGV})
if(NOT BUILD_TESTING)
return()
endif()
cgal_add_compilation_test(${name})
file(GLOB files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${data_set}/*")
foreach(file ${files})
message("test ${source_file} ${file}")
string(MAKE_C_IDENTIFIER "${name} ${file}" test_name)
message(" --> ${test_name}")
cgal_add_test(${name} TEST_NAME ${test_name} ${file})
endforeach()
endfunction()
compile_and_run_sweep(test_sweep test_sweep.cpp ${NAIVE} ${CGAL_SEGMENT_TRAITS} "DATA/segments_tight")
compile_and_run_sweep(test_sweep_conic test_sweep_conic.cpp ${NAIVE} ${CGAL_CONIC_TRAITS} "DATA/conics")
else()