Skip to content

Commit 47dfef0

Browse files
committed
Add props on targets to manage img requirements
- Fixes #267
1 parent 1fedcf2 commit 47dfef0

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

CMakeLists.txt

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,22 @@ function(check_script_style script_full_path)
500500
endif()
501501
endfunction()
502502

503+
#------------------------------------------------------------------------------
504+
# Add custom properties on targets for controling number of images during tests
505+
#------------------------------------------------------------------------------
506+
define_property(TARGET
507+
PROPERTY MIN_IMAGES
508+
BRIEF_DOCS "Minimum allowable images for the test <integer>"
509+
FULL_DOCS "Property to mark executable targets run as tests that they require at least <MIN_IMAGES> images to run"
510+
)
511+
512+
define_property(TARGET
513+
PROPERTY POWER_2_IMGS
514+
BRIEF_DOCS "True if test must be run with a power of 2 images (T/F)"
515+
FULL_DOCS "Property to mark executable targets run as tests that they require 2^n images."
516+
)
517+
518+
503519
#-------------------------------
504520
# Recurse into the src directory
505521
#-------------------------------
@@ -566,20 +582,32 @@ endif ()
566582
include( ProcessorCount )
567583
ProcessorCount(N_CPU)
568584
function(add_caf_test name num_caf_img test_target)
569-
# Function to add MPI tests.
570-
if ( ((N_CPU LESS num_caf_img) OR (N_CPU EQUAL 0)) )
571-
message(STATUS "Test ${name} is oversubscribed: ${num_caf_img} CAF images requested with ${N_CPU} system processor available.")
572-
if ( openmpi )
573-
if ( N_CPU LESS 2 )
574-
set( num_caf_img 2 )
575-
endif()
576-
set (test_parameters --oversubscribe)
577-
message( STATUS "Open-MPI back end detected, passing --oversubscribe for oversubscribed test, ${name}, with ${num_caf_img} ranks/images." )
578-
endif()
579-
endif()
580-
set(test_parameters -np ${num_caf_img} ${test_parameters})
581-
add_test(NAME ${name} COMMAND "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
582-
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
585+
# Function to add MPI tests.
586+
if(TARGET ${test_target})
587+
get_target_property(min_test_imgs ${test_target} MIN_IMAGES)
588+
elseif(TARGET build_${test_target})
589+
get_target_property(min_test_imgs build_${test_target} MIN_IMAGES)
590+
endif()
591+
if(min_test_imgs)
592+
if(num_caf_img LESS min_test_imgs)
593+
message( FATAL_ERROR "Test ${name} requires ${min_test_imgs} but was only given ${num_caf_images}" )
594+
endif()
595+
endif()
596+
if ( ((N_CPU LESS num_caf_img) OR (N_CPU EQUAL 0)) )
597+
message(STATUS "Test ${name} is oversubscribed: ${num_caf_img} CAF images requested with ${N_CPU} system processor available.")
598+
if ( openmpi )
599+
if (min_test_imgs)
600+
set( num_caf_img ${min_test_imgs} )
601+
elseif ( N_CPU LESS 2 )
602+
set( num_caf_img 2 )
603+
endif()
604+
set (test_parameters --oversubscribe)
605+
message( STATUS "Open-MPI back end detected, passing --oversubscribe for oversubscribed test, ${name}, with ${num_caf_img} ranks/images." )
606+
endif()
607+
endif()
608+
set(test_parameters -np ${num_caf_img} ${test_parameters})
609+
add_test(NAME ${name} COMMAND "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun" ${test_parameters} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}")
610+
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
583611
endfunction(add_caf_test)
584612

585613
#--------------

0 commit comments

Comments
 (0)