Skip to content

Commit

Permalink
Clean up unit tests (#1635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Dec 24, 2021
1 parent 096bc8c commit 8eb7688
Show file tree
Hide file tree
Showing 66 changed files with 305 additions and 195 deletions.
100 changes: 100 additions & 0 deletions cmake/DARTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,103 @@ function(dart_build_tutorial_in_source target)
dart_build_target_in_source(${target} ${ARGN})
dart_add_tutorial(${target})
endfunction()


# ==============================================================================
# dart_build_tests()
#
function(dart_build_tests)
set(prefix _ARG)
set(options
GLOB_SOURCES
)
set(oneValueArgs
COMPONENT_NAME
TARGET_PREFIX
TYPE
)
set(multiValueArgs
INCLUDE_DIRS
LINK_LIBRARIES
SOURCES
)
cmake_parse_arguments(
"${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
)

if(NOT _ARG_TARGET_PREFIX)
set(_ARG_TARGET_PREFIX UNIT)
endif()

if(NOT _ARG_TYPE)
message(FATAL_ERROR "TYPE is not set!")
endif()

foreach(dep ${_ARG_LINK_LIBRARIES})
if(NOT TARGET ${dep})
if(_ARG__ARG_COMPONENT_NAME)
message(WARNING "Skipping tests for component [${_ARG_COMPONENT_NAME}] due to missing component target [${dep}]")
else()
message(WARNING "Skipping tests due to missing component target [${dep}]")
endif()
return()
endif()
endforeach()

# Glob all the test files
if(_ARG_GLOB_SOURCES)
file(GLOB_RECURSE glob_test_files RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "test_*.cpp")
list(APPEND test_files ${glob_test_files})
endif()
list(APPEND test_files ${_ARG_SOURCES})
if(test_files)
list(SORT test_files)
endif()

foreach(source ${test_files})
# Set target name
if(_ARG_TARGET_PREFIX)
set(target_name ${_ARG_TARGET_PREFIX}_)
else()
set(target_name )
endif()
get_filename_component(source_name ${source} NAME_WE)
string(REPLACE "test_" "" source_name ${source_name})
get_filename_component(source_dir ${source} DIRECTORY)
if(source_dir)
string(REPLACE "/" "_" source_prefix ${source_dir})
set(target_name "${target_name}${source_prefix}_${source_name}")
else()
set(target_name "${target_name}${source_name}")
endif()

if(MSVC)
add_executable(${target_name} ${source})
else()
add_executable(${target_name} EXCLUDE_FROM_ALL ${source})
endif()
add_test(NAME ${target_name} COMMAND $<TARGET_FILE:${target_name}>)

# Include directories
target_include_directories(
${target_name} PRIVATE ${_ARG_INCLUDE_DIRS}
)

# Link libraries
target_link_libraries(${target_name} PRIVATE gtest gtest_main)
target_link_libraries(
${target_name} PRIVATE ${_ARG_LINK_LIBRARIES}
)
if(UNIX)
# gtest requies pthread when compiled on a Unix machine
target_link_libraries(${target_name} PRIVATE pthread)
endif()

# Add the test target to the list
dart_property_add(DART_${_ARG_TYPE}_TESTS ${target_name})

endforeach()

dart_format_add(${test_files})

endfunction()
2 changes: 1 addition & 1 deletion python/tests/unit/dynamics/test_meta_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dartpy as dart


# TODO(JS): Move this to comprehensive category once created
# TODO(JS): Move this to integration category once created


def test_basic():
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ endfunction()

#===============================================================================
# Usage:
# dart_get_tests("comprehensive" compreshensive_tests)
# dart_get_tests("integration" compreshensive_tests)
# foreach(test ${compreshensive_tests})
# message(STATUS "Test: ${test})
# endforeach()
Expand All @@ -87,29 +87,29 @@ endfunction()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# We categorize tests as:
# - "comprehensive": high level tests to verify the combination of several
# - "integration": high level tests to verify the combination of several
# components are correctly performs together
# - "regression": issue wise tests to verify that the GitHub issues are still
# fixed even after further changes are made
# - "unit": low level tests for one or few classes and functions to verify that
# they performs correctly as expected
if(NOT MSVC)
# Disabled due to limitied disk space in CI image
add_subdirectory(comprehensive)
add_subdirectory(integration)
add_subdirectory(regression)
endif()
add_subdirectory(unit)

# Print tests
dart_get_tests(comprehensive_tests "comprehensive")
dart_get_tests(integration_tests "integration")
dart_get_tests(regression_tests "regression")
dart_get_tests(unit_tests "unit")

if(DART_VERBOSE)
message(STATUS "")
message(STATUS "[ Tests ]")
foreach(test ${comprehensive_tests})
message(STATUS "Adding test: comprehensive/${test}")
foreach(test ${integration_tests})
message(STATUS "Adding test: integration/${test}")
endforeach()
foreach(test ${regression_tests})
message(STATUS "Adding test: regression/${test}")
Expand All @@ -118,15 +118,15 @@ if(DART_VERBOSE)
message(STATUS "Adding test: unit/${test}")
endforeach()
else()
list(LENGTH comprehensive_tests comprehensive_tests_len)
list(LENGTH integration_tests integration_tests_len)
list(LENGTH regression_tests regression_tests_len)
list(LENGTH unit_tests unit_tests_len)
math(
EXPR tests_len
"${comprehensive_tests_len} + ${regression_tests_len} + ${unit_tests_len}"
"${integration_tests_len} + ${regression_tests_len} + ${unit_tests_len}"
)
message(STATUS "Adding ${tests_len} tests ("
"comprehensive: ${comprehensive_tests_len}, "
"integration: ${integration_tests_len}, "
"regression: ${regression_tests_len}, "
"unit: ${unit_tests_len}"
")"
Expand All @@ -136,12 +136,12 @@ endif()
# Add custom target to build all the tests as a single target
add_custom_target(
tests
DEPENDS ${comprehensive_tests} ${regression_tests} ${unit_tests}
DEPENDS ${integration_tests} ${regression_tests} ${unit_tests}
)

# Add custom target to build all the tests and run the tests
add_custom_target(tests_and_run COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS ${comprehensive_tests} ${regression_tests} ${unit_tests}
DEPENDS ${integration_tests} ${regression_tests} ${unit_tests}
)

dart_format_add(GTestUtils.hpp)
72 changes: 0 additions & 72 deletions unittests/comprehensive/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 8eb7688

Please sign in to comment.