Skip to content

Commit

Permalink
cmake: test: do not overwrite function add_test()
Browse files Browse the repository at this point in the history
CMake provides its own add_test() that registers tests with ctest so
that they can be executed by invoking `ctest` in the build directory.

Drop custom targets 'all_tests' and 'all_tests.run' that have become
superfluous. Tests are always being build. Alternatives to `make` may
support virtual targets, i.e. with `ninja` one can say `ninja
tests/all` to build all targets below the `tests` directory.
  • Loading branch information
obruns committed Dec 18, 2016
1 parent 7d796b1 commit 047579f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ before_script:
tests:
script:
- cd bluetoe
- mkdir build && cd build && cmake .. && make all_tests.run
- mkdir build && cd build && cmake .. && make && ctest
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ script:
- cd build
- cmake --version
- cmake -DCMAKE_CXX_COMPILER=$COMPILER -DBLUETOE_EXCLUDE_SLOW_TESTS=1 ..
- make all_tests.run
- make
- make build_examples
- ctest

after_success:
- cd $TRAVIS_BUILD_DIR
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 2.8.7)

enable_testing()

include_directories(${CMAKE_SOURCE_DIR})

if (DEFINED NDEBUG)
Expand Down
36 changes: 14 additions & 22 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,36 @@ if (Boost_FOUND)
include_directories(BEFORE ${Boost_INCLUDE_DIR})
endif()

add_custom_target(all_tests)
add_custom_target(all_tests.run)

add_library(test_tools
${CMAKE_SOURCE_DIR}/bluetoe/link_layer/delta_time.cpp
${CMAKE_SOURCE_DIR}/tests/test_uuid.cpp
${CMAKE_SOURCE_DIR}/tests/hexdump.cpp
${CMAKE_SOURCE_DIR}/tests/link_layer/test_radio.cpp
${CMAKE_SOURCE_DIR}/tests/link_layer/buffer_io.cpp)

function(add_test TARGETNAME)
function(add_and_register_test TARGETNAME)
add_executable(${TARGETNAME} ${TARGETNAME}.cpp ${ARGV1} ${ARGV2} ${ARGV3} ${ARGV4})
target_link_libraries(${TARGETNAME} bluetoe test_tools)
add_custom_target(
${TARGETNAME}.run
COMMAND ${TARGETNAME})

add_dependencies(all_tests ${TARGETNAME})
add_dependencies(all_tests.run ${TARGETNAME}.run)
add_test(${TARGETNAME} ${TARGETNAME})
endfunction()

if (BLUETOE_EXCLUDE_SLOW_TESTS)
add_definitions(-DBLUETOE_EXCLUDE_SLOW_TESTS)
message(WARNING "excluding slow tests from test set!")
endif()

add_test(write_queue_tests)
add_test(service_tests)
add_test(options_tests)
add_test(characteristic_tests)
add_test(characteristic_value_tests)
add_test(advertising_tests)
add_test(filter_tests)
add_test(server_tests)
add_test(auto_uuid_tests)
add_test(scattered_access_tests)
add_test(gap_service_tests)
add_test(read_write_handler_tests)
add_and_register_test(write_queue_tests)
add_and_register_test(service_tests)
add_and_register_test(options_tests)
add_and_register_test(characteristic_tests)
add_and_register_test(characteristic_value_tests)
add_and_register_test(advertising_tests)
add_and_register_test(filter_tests)
add_and_register_test(server_tests)
add_and_register_test(auto_uuid_tests)
add_and_register_test(scattered_access_tests)
add_and_register_test(gap_service_tests)
add_and_register_test(read_write_handler_tests)

add_subdirectory(att)
add_subdirectory(link_layer)
Expand Down
30 changes: 15 additions & 15 deletions tests/att/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
include_directories(${CMAKE_SOURCE_DIR}/tests)

add_test(find_information_tests)
add_test(find_by_type_value_tests)
add_test(read_tests)
add_test(read_by_group_type_tests)
add_test(read_by_type_tests)
add_test(write_tests)
add_test(mtu_exchange_tests)
add_test(read_blob_tests)
add_test(notification_tests)
add_test(read_multiple_tests)
add_test(write_command_tests)
add_test(prepare_write_tests)
add_test(execute_write_tests)
add_test(request_not_supported_tests)
add_test(indication_tests)
add_and_register_test(find_information_tests)
add_and_register_test(find_by_type_value_tests)
add_and_register_test(read_tests)
add_and_register_test(read_by_group_type_tests)
add_and_register_test(read_by_type_tests)
add_and_register_test(write_tests)
add_and_register_test(mtu_exchange_tests)
add_and_register_test(read_blob_tests)
add_and_register_test(notification_tests)
add_and_register_test(read_multiple_tests)
add_and_register_test(write_command_tests)
add_and_register_test(prepare_write_tests)
add_and_register_test(execute_write_tests)
add_and_register_test(request_not_supported_tests)
add_and_register_test(indication_tests)
30 changes: 15 additions & 15 deletions tests/link_layer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
add_test(ll_advertising_tests)
add_test(address_tests)
add_test(channel_map_tests)
add_test(delta_time_tests)
add_test(ll_data_pdu_buffer_tests)
add_test(ll_connection_tests)
add_test(ll_control_tests)
add_test(ll_data_tests)
add_test(ring_buffer_tests)
add_test(notification_queue_tests)
add_test(connection_callbacks_tests)
add_test(signaling_channel_tests)
add_test(white_list_tests)
add_test(connection_parameter_update_procedure_tests)
add_test(test_radio_tests)
add_and_register_test(ll_advertising_tests)
add_and_register_test(address_tests)
add_and_register_test(channel_map_tests)
add_and_register_test(delta_time_tests)
add_and_register_test(ll_data_pdu_buffer_tests)
add_and_register_test(ll_connection_tests)
add_and_register_test(ll_control_tests)
add_and_register_test(ll_data_tests)
add_and_register_test(ring_buffer_tests)
add_and_register_test(notification_queue_tests)
add_and_register_test(connection_callbacks_tests)
add_and_register_test(signaling_channel_tests)
add_and_register_test(white_list_tests)
add_and_register_test(connection_parameter_update_procedure_tests)
add_and_register_test(test_radio_tests)
2 changes: 1 addition & 1 deletion tests/security_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_test(pairing_tests)
add_and_register_test(pairing_tests)
4 changes: 2 additions & 2 deletions tests/services/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_test(cscs_tests)
add_test(bootloader_tests test_gatt)
add_and_register_test(cscs_tests)
add_and_register_test(bootloader_tests test_gatt)

0 comments on commit 047579f

Please sign in to comment.