Skip to content

Commit 030c3bf

Browse files
committed
Generalize test macros.
1 parent 6ac62f4 commit 030c3bf

File tree

3 files changed

+156
-90
lines changed

3 files changed

+156
-90
lines changed

autotest/cpp/CMakeLists.txt

Lines changed: 147 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,23 @@ if (WIN32 OR APPLE)
165165
endif ()
166166

167167
macro (register_test_as_custom_target _test_name _binary_name)
168+
set(multiValueArgs CMD_ARGS)
169+
cmake_parse_arguments(ARGS "" "" "${multiValueArgs}" ${ARGN})
170+
168171
if (NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
169172
add_custom_target(
170173
${_test_name}
171-
COMMAND ${CMAKE_COMMAND} -E env ${TEST_ENV} $<TARGET_FILE:${_binary_name}> ${ARGN}
174+
COMMAND ${CMAKE_COMMAND} -E env ${TEST_ENV} $<TARGET_FILE:${_binary_name}> ${ARGS_CMD_ARGS}
172175
DEPENDS ${_binary_name})
173176
endif ()
174177
endmacro ()
175178

176179
macro (register_test _test_name _binary_name)
177-
register_test_as_custom_target(${_test_name} ${_binary_name} ${ARGN})
178-
add_test(NAME ${_test_name} COMMAND ${_binary_name} ${ARGN})
180+
set(multiValueArgs CMD_ARGS)
181+
cmake_parse_arguments(ARGS "" "" "${multiValueArgs}" ${ARGN})
182+
183+
register_test_as_custom_target(${_test_name} ${_binary_name} CMD_ARGS ${ARGS_CMD_ARGS})
184+
add_test(NAME ${_test_name} COMMAND ${_binary_name} ${ARGS_CMD_ARGS})
179185
set_property(TEST ${_test_name} PROPERTY ENVIRONMENT "${TEST_ENV}")
180186
endmacro ()
181187

@@ -190,88 +196,96 @@ add_library(main_gtest STATIC main_gtest.cpp)
190196
target_link_libraries(main_gtest PRIVATE gtest_for_gdal $<TARGET_NAME:${GDAL_LIB_TARGET_NAME}>)
191197
gdal_standard_includes(main_gtest)
192198

193-
gdal_test_target(testblockcache testblockcache.cpp)
199+
gdal_test_target(testblockcache FILES testblockcache.cpp)
194200
target_link_libraries(testblockcache PRIVATE gtest_for_gdal main_gtest)
195201

196202
register_test(
197203
test-block-cache-1
198204
testblockcache
199-
-check
200-
-co
201-
TILED=YES
202-
--debug
203-
TEST,LOCK
204-
-loops
205-
3
206-
--config
207-
GDAL_RB_LOCK_DEBUG_CONTENTION
208-
YES)
205+
CMD_ARGS
206+
-check
207+
-co
208+
TILED=YES
209+
--debug
210+
TEST,LOCK
211+
-loops
212+
3
213+
--config
214+
GDAL_RB_LOCK_DEBUG_CONTENTION
215+
YES)
209216
register_test(
210217
test-block-cache-2
211218
testblockcache
212-
-check
213-
-co
214-
TILED=YES
215-
--debug
216-
TEST,LOCK
217-
-loops
218-
3
219-
--config
220-
GDAL_RB_LOCK_DEBUG_CONTENTION
221-
YES
222-
--config
223-
GDAL_RB_LOCK_TYPE
224-
SPIN)
225-
register_test(test-block-cache-3 testblockcache -check -co TILED=YES -migrate)
226-
register_test(test-block-cache-4 testblockcache -check -memdriver)
219+
CMD_ARGS
220+
-check
221+
-co
222+
TILED=YES
223+
--debug
224+
TEST,LOCK
225+
-loops
226+
3
227+
--config
228+
GDAL_RB_LOCK_DEBUG_CONTENTION
229+
YES
230+
--config
231+
GDAL_RB_LOCK_TYPE
232+
SPIN)
233+
register_test(test-block-cache-3 testblockcache
234+
CMD_ARGS
235+
-check -co TILED=YES -migrate)
236+
register_test(test-block-cache-4 testblockcache
237+
CMD_ARGS
238+
-check -memdriver)
227239
register_test(
228240
test-block-cache-5
229241
testblockcache
230-
--config
231-
GDAL_BAND_BLOCK_CACHE
232-
HASHSET
233-
-check
234-
-co
235-
TILED=YES
236-
--debug
237-
TEST,LOCK
238-
-loops
239-
3
240-
--config
241-
GDAL_RB_LOCK_DEBUG_CONTENTION
242-
YES)
242+
CMD_ARGS
243+
--config
244+
GDAL_BAND_BLOCK_CACHE
245+
HASHSET
246+
-check
247+
-co
248+
TILED=YES
249+
--debug
250+
TEST,LOCK
251+
-loops
252+
3
253+
--config
254+
GDAL_RB_LOCK_DEBUG_CONTENTION
255+
YES)
243256
register_test(
244257
test-block-cache-6
245258
testblockcache
246-
--config
247-
GDAL_BAND_BLOCK_CACHE
248-
HASHSET
249-
-check
250-
-co
251-
TILED=YES
252-
--debug
253-
TEST,LOCK
254-
-loops
255-
3
256-
--config
257-
GDAL_RB_LOCK_DEBUG_CONTENTION
258-
YES
259-
--config
260-
GDAL_RB_LOCK_TYPE
261-
SPIN)
259+
CMD_ARGS
260+
--config
261+
GDAL_BAND_BLOCK_CACHE
262+
HASHSET
263+
-check
264+
-co
265+
TILED=YES
266+
--debug
267+
TEST,LOCK
268+
-loops
269+
3
270+
--config
271+
GDAL_RB_LOCK_DEBUG_CONTENTION
272+
YES
273+
--config
274+
GDAL_RB_LOCK_TYPE
275+
SPIN)
262276

263277
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86_64|AMD64)" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND HAVE_SSE_AT_COMPILE_TIME)
264-
gdal_test_target(testsse2 testsse.cpp)
265-
gdal_test_target(testsse2_emulation testsse.cpp)
278+
gdal_test_target(testsse2 FILES testsse.cpp)
279+
gdal_test_target(testsse2_emulation FILES testsse.cpp)
266280
target_compile_definitions(testsse2_emulation PRIVATE -DUSE_SSE2_EMULATION -DNO_WARN_USE_SSE2_EMULATION)
267281
register_test(test-sse2 testsse2)
268282
register_test(test-sse2-emulation testsse2_emulation)
269283

270284
if (HAVE_AVX_AT_COMPILE_TIME)
271285
# Do not include in ctest as we aren't sure the target machine support this
272-
gdal_test_target(testssse3 testsse.cpp)
273-
gdal_test_target(testsse4_1 testsse.cpp)
274-
gdal_test_target(testavx2 testsse.cpp)
286+
gdal_test_target(testssse3 FILES testsse.cpp)
287+
gdal_test_target(testsse4_1 FILES testsse.cpp)
288+
gdal_test_target(testavx2 FILES testsse.cpp)
275289
target_compile_options(testssse3 PRIVATE ${GDAL_SSSE3_FLAG})
276290
target_compile_options(testsse4_1 PRIVATE ${GDAL_SSSE3_FLAG} ${GDAL_SSE41_FLAG})
277291
target_compile_options(testavx2 PRIVATE ${GDAL_AVX2_FLAG})
@@ -281,13 +295,19 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86_64|AMD64)" AND CMAKE_SIZEOF_VOID_P
281295
endif ()
282296
endif ()
283297

284-
macro (gdal_autotest_target _target testlabel _source)
285-
gdal_test_target(${_target} ${_source})
286-
register_test(${testlabel} ${_target} ${ARGN})
298+
macro (gdal_autotest_target _target testlabel)
299+
set(multiValueArgs CMD_ARGS FILES)
300+
cmake_parse_arguments(ARGS "" "" "${multiValueArgs}" ${ARGN})
301+
302+
gdal_test_target(${_target} FILES ${ARGS_FILES})
303+
register_test(${testlabel} ${_target} CMD_ARGS ${ARGS_CMD_ARGS})
287304
endmacro ()
288305

289-
function (gdal_gtest_target _target testlabel _source)
290-
gdal_autotest_target(${_target} ${testlabel} ${_source} ${ARGN})
306+
function (gdal_gtest_target _target testlabel)
307+
set(multiValueArgs CMD_ARGS FILES)
308+
cmake_parse_arguments(ARGS "" "" "${multiValueArgs}" ${ARGN})
309+
310+
gdal_autotest_target(${_target} ${testlabel} ARGS ${ARGS_CMD_ARGS} FILES ${ARGS_FILES})
291311
target_link_libraries(${_target} PRIVATE gtest_for_gdal main_gtest)
292312
endfunction ()
293313

@@ -313,32 +333,74 @@ set(QUICKTEST_LIST
313333
test-deferred-plugin
314334
)
315335

316-
gdal_gtest_target(testfloat16 test-float16 testfloat16.cpp)
317-
gdal_gtest_target(testcopywords test-copy-words testcopywords.cpp)
318-
gdal_gtest_target(testclosedondestroydm test-closed-on-destroy-DM testclosedondestroydm.cpp)
319-
gdal_gtest_target(testthreadcond test-threaded-condition testthreadcond.cpp)
320-
gdal_gtest_target(testvirtualmem test-virtual-memory testvirtualmem.cpp)
321-
gdal_gtest_target(testblockcachewrite test-block-cache-write testblockcachewrite.cpp --debug ON)
322-
gdal_gtest_target(testblockcachelimits test-block-cache-limit testblockcachelimits.cpp --debug ON)
323-
gdal_gtest_target(testmultithreadedwriting test-multi-threaded-writing testmultithreadedwriting.cpp)
324-
gdal_gtest_target(testdestroy test-destroy testdestroy.cpp)
325-
gdal_autotest_target(test_include_from_c_file test-include-from-C-file test_include_from_c_file.c "")
326-
gdal_autotest_target(test_c_include_from_cpp_file test-C-include-from-CPP-file test_c_include_from_cpp_file.cpp "")
327-
gdal_gtest_target(bug1488 test-bug1488 bug1488.cpp)
328-
gdal_gtest_target(testlog test-log testlog.cpp)
329-
gdal_gtest_target(test_deferred_plugin test-deferred-plugin test_deferred_plugin.cpp)
336+
gdal_gtest_target(testfloat16 test-float16
337+
FILES
338+
testfloat16.cpp)
339+
gdal_gtest_target(testcopywords test-copy-words
340+
FILES
341+
testcopywords.cpp)
342+
gdal_gtest_target(testclosedondestroydm test-closed-on-destroy-DM
343+
FILES
344+
testclosedondestroydm.cpp)
345+
gdal_gtest_target(testthreadcond test-threaded-condition
346+
FILES
347+
testthreadcond.cpp)
348+
gdal_gtest_target(testvirtualmem test-virtual-memory
349+
FILES
350+
testvirtualmem.cpp)
351+
gdal_gtest_target(testblockcachewrite test-block-cache-write
352+
FILES
353+
testblockcachewrite.cpp
354+
CMD_ARGS
355+
--debug ON)
356+
gdal_gtest_target(testblockcachelimits test-block-cache-limit
357+
FILES
358+
testblockcachelimits.cpp
359+
CMD_ARGS
360+
--debug ON)
361+
gdal_gtest_target(testmultithreadedwriting test-multi-threaded-writing
362+
FILES
363+
testmultithreadedwriting.cpp)
364+
gdal_gtest_target(testdestroy test-destroy
365+
FILES
366+
testdestroy.cpp
367+
CMD_ARGS
368+
"")
369+
gdal_autotest_target(test_include_from_c_file test-include-from-C-file
370+
FILES
371+
test_include_from_c_file.c)
372+
gdal_autotest_target(test_c_include_from_cpp_file test-C-include-from-CPP-file
373+
FILES
374+
test_c_include_from_cpp_file.cpp
375+
CMD_ARGS
376+
"")
377+
378+
379+
gdal_gtest_target(bug1488 test-bug1488
380+
FILES
381+
bug1488.cpp)
382+
gdal_gtest_target(testlog test-log
383+
FILES
384+
testlog.cpp)
385+
gdal_gtest_target(test_deferred_plugin test-deferred-plugin
386+
FILES
387+
test_deferred_plugin.cpp)
330388

331389
if (GDAL_ENABLE_DRIVER_JPEG_PLUGIN)
332390
target_compile_definitions(test_deferred_plugin PRIVATE -DJPEG_PLUGIN)
333391
endif()
334392

335393
if (UNIX)
336394
list(APPEND QUICKTEST_LIST test-osr-set-proj-search-paths)
337-
gdal_gtest_target(test_osr_set_proj_search_paths test-osr-set-proj-search-paths test_osr_set_proj_search_paths.cpp)
395+
gdal_gtest_target(test_osr_set_proj_search_paths test-osr-set-proj-search-paths
396+
FILES
397+
test_osr_set_proj_search_paths.cpp)
338398
endif()
339399

340400
if (UNIX)
341-
gdal_gtest_target(proj_with_fork test-proj-with-fork proj_with_fork.cpp)
401+
gdal_gtest_target(proj_with_fork test-proj-with-fork
402+
FILES
403+
proj_with_fork.cpp)
342404
list(APPEND QUICKTEST_LIST test-proj-with-fork)
343405
endif ()
344406

@@ -349,3 +411,4 @@ endif ()
349411
foreach (_test IN LISTS QUICKTEST_LIST)
350412
set_tests_properties(${_test} PROPERTIES LABELS "quicktest")
351413
endforeach ()
414+

cmake/helpers/GdalTestTarget.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
macro (gdal_test_target _target _source)
2-
add_executable(${_target} ${_source})
1+
macro (gdal_test_target _target)
2+
set(multiValueArgs FILES)
3+
cmake_parse_arguments(ARGS "" "" "${multiValueArgs}" ${ARGN})
4+
5+
add_executable(${_target} ${ARGS_FILES})
36
target_link_libraries(${_target} PRIVATE $<TARGET_NAME:${GDAL_LIB_TARGET_NAME}>)
47
gdal_standard_includes(${_target})
58
target_compile_options(${_target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${GDAL_CXX_WARNING_FLAGS}>

perftests/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ if (WIN32)
1313
list(APPEND TEST_ENV "CPL_ERROR_SEPARATOR=\\;")
1414
endif ()
1515

16-
gdal_test_target(testperfcopywords testperfcopywords.cpp)
17-
gdal_test_target(testperfdeinterleave testperfdeinterleave.cpp)
16+
gdal_test_target(testperfcopywords FILES testperfcopywords.cpp)
17+
gdal_test_target(testperfdeinterleave FILES testperfdeinterleave.cpp)
1818

1919
add_executable(bench_ogr_batch bench_ogr_batch.cpp)
2020
gdal_standard_includes(bench_ogr_batch)
@@ -24,14 +24,14 @@ add_executable(bench_ogr_c_api bench_ogr_c_api.cpp)
2424
gdal_standard_includes(bench_ogr_c_api)
2525
target_link_libraries(bench_ogr_c_api PRIVATE $<TARGET_NAME:${GDAL_LIB_TARGET_NAME}>)
2626

27-
gdal_test_target(testperf_gdal_minmax_element testperf_gdal_minmax_element.cpp)
27+
gdal_test_target(testperf_gdal_minmax_element FILES testperf_gdal_minmax_element.cpp)
2828
if (GDAL_ENABLE_ARM_NEON_OPTIMIZATIONS)
2929
target_compile_definitions(testperf_gdal_minmax_element PRIVATE -DUSE_NEON_OPTIMIZATIONS)
3030
endif()
3131
add_test(NAME testperf_gdal_minmax_element COMMAND testperf_gdal_minmax_element)
3232
set_property(TEST testperf_gdal_minmax_element PROPERTY ENVIRONMENT "${TEST_ENV}")
3333

34-
gdal_test_target(testperftranspose testperftranspose.cpp)
34+
gdal_test_target(testperftranspose FILES testperftranspose.cpp)
3535
if (HAVE_SSSE3_AT_COMPILE_TIME)
3636
target_compile_definitions(testperftranspose PRIVATE -DHAVE_SSSE3_AT_COMPILE_TIME)
3737
endif()

0 commit comments

Comments
 (0)