Skip to content

[cmake][test] Add a add_glow_test function and 'check' target #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(GlowDefaults)
include(GlowTestSupport)
include(SanitizerSupport)
include(CoverageSupport)
include(DoxygenSupport)
Expand Down Expand Up @@ -75,3 +76,9 @@ add_subdirectory(tests)
add_custom_target(dependency_graph
"${CMAKE_COMMAND}" "--graphviz=dependency_graph" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")

# Fetch the dependencies for all the tests.
get_property(GLOW_TEST_DEPENDS GLOBAL PROPERTY GLOW_TEST_DEPENDS)

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS ${GLOW_TEST_DEPENDS} USES_TERMINAL)
34 changes: 34 additions & 0 deletions cmake/modules/GlowTestSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# A function to add a test to be driven through the 'check' target.
# Unlike the 'test' target, the 'check' target rebuilds the executables
# before invoking the tests.
function(add_glow_test)
set(oneValueArgs NAME)
set(multiValueArgs COMMAND DEPENDS)
cmake_parse_arguments(ARG "" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})

if (NOT ARG_NAME)
list(GET ARG_UNPARSED_ARGUMENTS 0 ARG_NAME)
list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0)
endif()

if (NOT ARG_NAME)
message(FATAL_ERROR "Name mandatory")
endif()

if (NOT ARG_COMMAND)
set(ARG_COMMAND ${ARG_UNPARSED_ARGUMENTS})
endif()

if (NOT ARG_COMMAND)
message(FATAL_ERROR "Command mandatory")
endif()

list(GET ARG_COMMAND 0 TEST_EXEC)
list(APPEND ARG_DEPENDS ${TEST_EXEC})

set_property(GLOBAL APPEND PROPERTY GLOW_TEST_DEPENDS ${ARG_DEPENDS})

# Produce the specific test rule using the default built-in.
add_test(NAME ${ARG_NAME} COMMAND ${ARG_COMMAND})
endfunction()
32 changes: 16 additions & 16 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_link_libraries(tensorsTest
Base
gtest
testMain)
add_test(tensorsTest ${GLOW_BINARY_DIR}/tests/tensorsTest)
add_glow_test(tensorsTest ${GLOW_BINARY_DIR}/tests/tensorsTest)

add_executable(gradCheckTest
gradCheckTest.cpp)
Expand All @@ -24,7 +24,7 @@ target_link_libraries(gradCheckTest
IR
gtest
testMain)
add_test(gradCheckTest ${GLOW_BINARY_DIR}/tests/gradCheckTest)
add_glow_test(gradCheckTest ${GLOW_BINARY_DIR}/tests/gradCheckTest)

add_executable(IROptTest
IROptTest.cpp)
Expand All @@ -35,7 +35,7 @@ target_link_libraries(IROptTest
Optimizer
gtest
testMain)
add_test(IROptTest ${GLOW_BINARY_DIR}/tests/IROptTest)
add_glow_test(IROptTest ${GLOW_BINARY_DIR}/tests/IROptTest)

add_executable(basicIRTest
basicIRTest.cpp)
Expand All @@ -45,7 +45,7 @@ target_link_libraries(basicIRTest
IR
gtest
testMain)
add_test(basicIRTest ${GLOW_BINARY_DIR}/tests/basicIRTest)
add_glow_test(basicIRTest ${GLOW_BINARY_DIR}/tests/basicIRTest)

add_executable(backendTest
BackendTest.cpp)
Expand All @@ -56,7 +56,7 @@ target_link_libraries(backendTest
ExecutionEngine
gtest
testMain)
add_test(backendTest ${GLOW_BINARY_DIR}/tests/backendTest)
add_glow_test(backendTest ${GLOW_BINARY_DIR}/tests/backendTest)

add_executable(MLTest
MLTest.cpp)
Expand All @@ -67,7 +67,7 @@ target_link_libraries(MLTest
ExecutionEngine
gtest
testMain)
add_test(MLTest ${GLOW_BINARY_DIR}/tests/MLTest)
add_glow_test(MLTest ${GLOW_BINARY_DIR}/tests/MLTest)

add_executable(operatorTest
OperatorTest.cpp)
Expand All @@ -78,7 +78,7 @@ target_link_libraries(operatorTest
ExecutionEngine
gtest
testMain)
add_test(operatorTest ${GLOW_BINARY_DIR}/tests/operatorTest)
add_glow_test(operatorTest ${GLOW_BINARY_DIR}/tests/operatorTest)


add_executable(graphTest
Expand All @@ -90,7 +90,7 @@ target_link_libraries(graphTest
IR
gtest
testMain)
add_test(graphTest ${GLOW_BINARY_DIR}/tests/graphTest)
add_glow_test(graphTest ${GLOW_BINARY_DIR}/tests/graphTest)

add_executable(graphGradTest
graphGradTest.cpp)
Expand All @@ -101,7 +101,7 @@ target_link_libraries(graphGradTest
ExecutionEngine
gtest
testMain)
add_test(graphGradTest ${GLOW_BINARY_DIR}/tests/graphGradTest)
add_glow_test(graphGradTest ${GLOW_BINARY_DIR}/tests/graphGradTest)

add_executable(graphOptzTest
graphOptzTest.cpp)
Expand All @@ -112,7 +112,7 @@ target_link_libraries(graphOptzTest
Optimizer
gtest
testMain)
add_test(graphOptzTest ${GLOW_BINARY_DIR}/tests/graphOptzTest)
add_glow_test(graphOptzTest ${GLOW_BINARY_DIR}/tests/graphOptzTest)

add_executable(quantizationTest
quantizationTest.cpp)
Expand All @@ -123,7 +123,7 @@ target_link_libraries(quantizationTest
Quantization
gtest
testMain)
add_test(quantizationTest ${GLOW_BINARY_DIR}/tests/quantizationTest)
add_glow_test(quantizationTest ${GLOW_BINARY_DIR}/tests/quantizationTest)

add_executable(UtilsTest
UtilsTest.cpp)
Expand All @@ -132,7 +132,7 @@ target_link_libraries(UtilsTest
Support
gtest
testMain)
add_test(UtilsTest ${GLOW_BINARY_DIR}/tests/UtilsTest)
add_glow_test(UtilsTest ${GLOW_BINARY_DIR}/tests/UtilsTest)

if(GLOW_WITH_OPENCL)
add_executable(OCLTest
Expand All @@ -145,7 +145,7 @@ target_link_libraries(OCLTest
ExecutionEngine
gtest
testMain)
add_test(OCLTest ${GLOW_BINARY_DIR}/tests/OCLTest)
add_glow_test(OCLTest ${GLOW_BINARY_DIR}/tests/OCLTest)
LIST(APPEND UNOPT_TESTS ./tests/OCLTest -optimize-ir=false &&)
endif()

Expand All @@ -160,7 +160,7 @@ target_link_libraries(BackendCorrectnessTest
Support
gtest
testMain)
add_test(BackendCorrectnessTest ${GLOW_BINARY_DIR}/tests/BackendCorrectnessTest)
add_glow_test(BackendCorrectnessTest ${GLOW_BINARY_DIR}/tests/BackendCorrectnessTest)
LIST(APPEND UNOPT_TESTS ./tests/BackendCorrectnessTest -optimize-ir=false &&)

if(GLOW_WITH_CPU)
Expand All @@ -176,7 +176,7 @@ target_link_libraries(GemmTest
Support
gtest
testMain)
add_test(GemmTest ${GLOW_BINARY_DIR}/tests/GemmTest)
add_glow_test(GemmTest ${GLOW_BINARY_DIR}/tests/GemmTest)
LIST(APPEND UNOPT_TESTS ./tests/GemmTest -optimize-ir=false &&)
endif()

Expand All @@ -187,7 +187,7 @@ target_link_libraries(memoryAllocatorTest
CodeGen
gtest
testMain)
add_test(memoryAllocatorTest ${GLOW_BINARY_DIR}/tests/memoryAllocatorTest)
add_glow_test(memoryAllocatorTest ${GLOW_BINARY_DIR}/tests/memoryAllocatorTest)


LIST(APPEND UNOPT_TESTS
Expand Down