Skip to content

Commit 1116b5a

Browse files
Quentin Colombetqcolombet
Quentin Colombet
authored andcommitted
[cmake][test] Add a add_glow_test function and 'check' target
Introduce the add_glow_test function that on top of adding the test to the list of tests to be run with ctest, it will register the dependencies on the actual executable. Thanks to this information, the new 'check' target can re-build the test executables if needed and then run the test. In other words, the combination of those two additions act like `ninja all && ninja test`, except we don't have to think about it.
1 parent 2f36a2a commit 1116b5a

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
2121
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2222

2323
include(GlowDefaults)
24+
include(GlowTestSupport)
2425
include(SanitizerSupport)
2526
include(CoverageSupport)
2627
include(DoxygenSupport)
@@ -75,3 +76,9 @@ add_subdirectory(tests)
7576
add_custom_target(dependency_graph
7677
"${CMAKE_COMMAND}" "--graphviz=dependency_graph" .
7778
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
79+
80+
# Fetch the dependencies for all the tests.
81+
get_property(GLOW_TEST_DEPENDS GLOBAL PROPERTY GLOW_TEST_DEPENDS)
82+
83+
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
84+
DEPENDS ${GLOW_TEST_DEPENDS} USES_TERMINAL)

cmake/modules/GlowTestSupport.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# A function to add a test to be driven through the 'check' target.
2+
# Unlike the 'test' target, the 'check' target rebuilds the executables
3+
# before invoking the tests.
4+
function(add_glow_test)
5+
set(oneValueArgs NAME)
6+
set(multiValueArgs COMMAND DEPENDS)
7+
cmake_parse_arguments(ARG "" "${oneValueArgs}"
8+
"${multiValueArgs}" ${ARGN})
9+
10+
if (NOT ARG_NAME)
11+
list(GET ARG_UNPARSED_ARGUMENTS 0 ARG_NAME)
12+
list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0)
13+
endif()
14+
15+
if (NOT ARG_NAME)
16+
message(FATAL_ERROR "Name mandatory")
17+
endif()
18+
19+
if (NOT ARG_COMMAND)
20+
set(ARG_COMMAND ${ARG_UNPARSED_ARGUMENTS})
21+
endif()
22+
23+
if (NOT ARG_COMMAND)
24+
message(FATAL_ERROR "Command mandatory")
25+
endif()
26+
27+
list(GET ARG_COMMAND 0 TEST_EXEC)
28+
list(APPEND ARG_DEPENDS ${TEST_EXEC})
29+
30+
set_property(GLOBAL APPEND PROPERTY GLOW_TEST_DEPENDS ${ARG_DEPENDS})
31+
32+
# Produce the specific test rule using the default built-in.
33+
add_test(NAME ${ARG_NAME} COMMAND ${ARG_COMMAND})
34+
endfunction()

tests/unittests/CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ target_link_libraries(tensorsTest
1212
Base
1313
gtest
1414
testMain)
15-
add_test(tensorsTest ${GLOW_BINARY_DIR}/tests/tensorsTest)
15+
add_glow_test(tensorsTest ${GLOW_BINARY_DIR}/tests/tensorsTest)
1616

1717
add_executable(gradCheckTest
1818
gradCheckTest.cpp)
@@ -24,7 +24,7 @@ target_link_libraries(gradCheckTest
2424
IR
2525
gtest
2626
testMain)
27-
add_test(gradCheckTest ${GLOW_BINARY_DIR}/tests/gradCheckTest)
27+
add_glow_test(gradCheckTest ${GLOW_BINARY_DIR}/tests/gradCheckTest)
2828

2929
add_executable(IROptTest
3030
IROptTest.cpp)
@@ -35,7 +35,7 @@ target_link_libraries(IROptTest
3535
Optimizer
3636
gtest
3737
testMain)
38-
add_test(IROptTest ${GLOW_BINARY_DIR}/tests/IROptTest)
38+
add_glow_test(IROptTest ${GLOW_BINARY_DIR}/tests/IROptTest)
3939

4040
add_executable(basicIRTest
4141
basicIRTest.cpp)
@@ -45,7 +45,7 @@ target_link_libraries(basicIRTest
4545
IR
4646
gtest
4747
testMain)
48-
add_test(basicIRTest ${GLOW_BINARY_DIR}/tests/basicIRTest)
48+
add_glow_test(basicIRTest ${GLOW_BINARY_DIR}/tests/basicIRTest)
4949

5050
add_executable(backendTest
5151
BackendTest.cpp)
@@ -56,7 +56,7 @@ target_link_libraries(backendTest
5656
ExecutionEngine
5757
gtest
5858
testMain)
59-
add_test(backendTest ${GLOW_BINARY_DIR}/tests/backendTest)
59+
add_glow_test(backendTest ${GLOW_BINARY_DIR}/tests/backendTest)
6060

6161
add_executable(MLTest
6262
MLTest.cpp)
@@ -67,7 +67,7 @@ target_link_libraries(MLTest
6767
ExecutionEngine
6868
gtest
6969
testMain)
70-
add_test(MLTest ${GLOW_BINARY_DIR}/tests/MLTest)
70+
add_glow_test(MLTest ${GLOW_BINARY_DIR}/tests/MLTest)
7171

7272
add_executable(operatorTest
7373
OperatorTest.cpp)
@@ -78,7 +78,7 @@ target_link_libraries(operatorTest
7878
ExecutionEngine
7979
gtest
8080
testMain)
81-
add_test(operatorTest ${GLOW_BINARY_DIR}/tests/operatorTest)
81+
add_glow_test(operatorTest ${GLOW_BINARY_DIR}/tests/operatorTest)
8282

8383

8484
add_executable(graphTest
@@ -90,7 +90,7 @@ target_link_libraries(graphTest
9090
IR
9191
gtest
9292
testMain)
93-
add_test(graphTest ${GLOW_BINARY_DIR}/tests/graphTest)
93+
add_glow_test(graphTest ${GLOW_BINARY_DIR}/tests/graphTest)
9494

9595
add_executable(graphGradTest
9696
graphGradTest.cpp)
@@ -101,7 +101,7 @@ target_link_libraries(graphGradTest
101101
ExecutionEngine
102102
gtest
103103
testMain)
104-
add_test(graphGradTest ${GLOW_BINARY_DIR}/tests/graphGradTest)
104+
add_glow_test(graphGradTest ${GLOW_BINARY_DIR}/tests/graphGradTest)
105105

106106
add_executable(graphOptzTest
107107
graphOptzTest.cpp)
@@ -112,7 +112,7 @@ target_link_libraries(graphOptzTest
112112
Optimizer
113113
gtest
114114
testMain)
115-
add_test(graphOptzTest ${GLOW_BINARY_DIR}/tests/graphOptzTest)
115+
add_glow_test(graphOptzTest ${GLOW_BINARY_DIR}/tests/graphOptzTest)
116116

117117
add_executable(quantizationTest
118118
quantizationTest.cpp)
@@ -123,7 +123,7 @@ target_link_libraries(quantizationTest
123123
Quantization
124124
gtest
125125
testMain)
126-
add_test(quantizationTest ${GLOW_BINARY_DIR}/tests/quantizationTest)
126+
add_glow_test(quantizationTest ${GLOW_BINARY_DIR}/tests/quantizationTest)
127127

128128
add_executable(UtilsTest
129129
UtilsTest.cpp)
@@ -132,7 +132,7 @@ target_link_libraries(UtilsTest
132132
Support
133133
gtest
134134
testMain)
135-
add_test(UtilsTest ${GLOW_BINARY_DIR}/tests/UtilsTest)
135+
add_glow_test(UtilsTest ${GLOW_BINARY_DIR}/tests/UtilsTest)
136136

137137
if(GLOW_WITH_OPENCL)
138138
add_executable(OCLTest
@@ -145,7 +145,7 @@ target_link_libraries(OCLTest
145145
ExecutionEngine
146146
gtest
147147
testMain)
148-
add_test(OCLTest ${GLOW_BINARY_DIR}/tests/OCLTest)
148+
add_glow_test(OCLTest ${GLOW_BINARY_DIR}/tests/OCLTest)
149149
LIST(APPEND UNOPT_TESTS ./tests/OCLTest -optimize-ir=false &&)
150150
endif()
151151

@@ -160,7 +160,7 @@ target_link_libraries(BackendCorrectnessTest
160160
Support
161161
gtest
162162
testMain)
163-
add_test(BackendCorrectnessTest ${GLOW_BINARY_DIR}/tests/BackendCorrectnessTest)
163+
add_glow_test(BackendCorrectnessTest ${GLOW_BINARY_DIR}/tests/BackendCorrectnessTest)
164164
LIST(APPEND UNOPT_TESTS ./tests/BackendCorrectnessTest -optimize-ir=false &&)
165165

166166
if(GLOW_WITH_CPU)
@@ -176,7 +176,7 @@ target_link_libraries(GemmTest
176176
Support
177177
gtest
178178
testMain)
179-
add_test(GemmTest ${GLOW_BINARY_DIR}/tests/GemmTest)
179+
add_glow_test(GemmTest ${GLOW_BINARY_DIR}/tests/GemmTest)
180180
LIST(APPEND UNOPT_TESTS ./tests/GemmTest -optimize-ir=false &&)
181181
endif()
182182

@@ -187,7 +187,7 @@ target_link_libraries(memoryAllocatorTest
187187
CodeGen
188188
gtest
189189
testMain)
190-
add_test(memoryAllocatorTest ${GLOW_BINARY_DIR}/tests/memoryAllocatorTest)
190+
add_glow_test(memoryAllocatorTest ${GLOW_BINARY_DIR}/tests/memoryAllocatorTest)
191191

192192

193193
LIST(APPEND UNOPT_TESTS

0 commit comments

Comments
 (0)