From 855d995e1eb1be0ee9291ac1d117f96ad16c4d65 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 3 Nov 2017 09:33:11 +0100 Subject: [PATCH] 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/` --- .../Arrangement_on_surface_2/cgal_test.cmake | 10 +- .../cmake/modules/CGAL_add_test.cmake | 94 ++++++++++++------- Sweep_line_2/test/Sweep_line_2/CMakeLists.txt | 42 ++++++++- 3 files changed, 99 insertions(+), 47 deletions(-) diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake index 9bff34826c6..a4e1696e28c 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test.cmake @@ -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() diff --git a/Installation/cmake/modules/CGAL_add_test.cmake b/Installation/cmake/modules/CGAL_add_test.cmake index c16d2a10e2c..e6579a4d960 100644 --- a/Installation/cmake/modules/CGAL_add_test.cmake +++ b/Installation/cmake/modules/CGAL_add_test.cmake @@ -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=$ -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} $ ${ARGS}) + add_test(NAME ${test_name} COMMAND ${TIME_COMMAND} $ ${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} $ ${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() diff --git a/Sweep_line_2/test/Sweep_line_2/CMakeLists.txt b/Sweep_line_2/test/Sweep_line_2/CMakeLists.txt index 206e6717f2f..41ccb765255 100644 --- a/Sweep_line_2/test/Sweep_line_2/CMakeLists.txt +++ b/Sweep_line_2/test/Sweep_line_2/CMakeLists.txt @@ -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()