1# -*- mode: makefile-gmake -*- 2-include petscdir.mk 3 4.SUFFIXES: .F .F90 .f90 ${SUFFIXES} .PETSc .C .cc .cpp .cxx .r .rm .so .html .ad .m .tex .make .fig .svg .eps .pdf .jpg .png .dvi .ps .F95 .f95 .fiat .cu .kokkos.cxx .raja.cxx .hip.cpp .sycl.cxx 5 6CONFIGDIR := $(PETSC_DIR)/config 7 8# TESTSRCDIR is always relative to gmakefile.test 9# This must be before includes 10mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) 11TESTSRCDIR := $(dir $(mkfile_path))src 12 13-include $(PETSC_DIR)/$(PETSC_ARCH)/lib/petsc/conf/petscvariables 14-include $(PETSC_DIR)/lib/petsc/conf/variables 15 16TESTDIR ?= ./$(PETSC_ARCH)/tests 17MODDIR := $(PETSC_DIR)/$(PETSC_ARCH)/include 18TESTLOGTAPFILE ?= $(TESTDIR)/test_$(PETSC_ARCH)_tap.log 19TESTLOGERRFILE ?= $(TESTDIR)/test_$(PETSC_ARCH)_err.log 20EXAMPLESDIR := $(TESTSRCDIR) 21 22pkgs := sys vec mat dm ksp snes ts tao 23 24petscconf := $(PETSC_DIR)/$(PETSC_ARCH)/include/petscconf.h 25petscvariables := $(PETSC_DIR)/$(PETSC_ARCH)/lib/petsc/conf/petscvariables 26generatedtest := $(TESTDIR)/testfiles 27 28.SECONDEXPANSION: # to expand $$(@D)/.DIR 29 30TESTFLAGS := # Initialize as simple variable 31 32#workaround old cygwin versions 33ifeq ($(PETSC_CYGWIN_BROKEN_PIPE),1) 34ifeq ($(shell basename $(AR)),ar) 35 V ?=1 36endif 37endif 38V ?= $(if $(findstring s,$(MAKEFLAGS)),0) 39ifeq ($(V),) # Default 40 quiet_HELP := "Use \"$(MAKE) V=1\" to see verbose compile lines, \"$(MAKE) V=0\" to suppress.\n" 41 quiet = @printf $(quiet_HELP)$(eval quiet_HELP:=)" %10s %s\n" "$1$2" "$@"; $($1) 42 quiettest = @printf " %10s %s\n" "TEST" "$(@:$(TESTDIR)/counts/%.counts=%)"; 43else ifeq ($(V),0) # Suppress entire command 44 quiet = @$($1) 45 quiettest = @ 46 TESTFLAGS += -o err_only 47else # Show the full command line 48 quiet = $($1) 49 quiettest = 50 TESTFLAGS += -v 51endif 52 53ifeq ($(FORCE),1) 54 TESTFLAGS += -f # force test execution 55endif 56ifeq ($(CUDAMEMCHECK),1) 57 TESTFLAGS += -U # Add cuda-memcheck option to the flags 58endif 59ifeq ($(VALGRIND),1) 60 TESTFLAGS += -V # Add valgrind option to the flags 61endif 62ifeq ($(DEBUG),1) 63 TESTFLAGS += -d # Launch test in debugger 64endif 65ifeq ($(REPLACE),1) 66 TESTFLAGS += -m # Replace results by passing -m to petscdiff 67endif 68ifeq ($(OUTPUT),1) 69 TESTFLAGS += -o 'err_only' # Show only the errors on stdout 70endif 71ifeq ($(ALT),1) 72 TESTFLAGS += -M # Replace alt files by passing -M to petscdiff 73endif 74PRINTONLY ?= 0 75ifeq ($(PRINTONLY),1) 76 TESTFLAGS += -p # Pass -p to petscdiff to print only command 77endif 78ifeq ($(DIFF_NUMBERS),1) 79 TESTFLAGS += -j # Pass -j to petscdiff to diff the actual numbers 80endif 81ifdef OPTIONS 82 TESTFLAGS += -a '$(OPTIONS)' # override arguments 83endif 84ifdef EXTRA_OPTIONS 85 TESTFLAGS += -e '$(EXTRA_OPTIONS)' # add extra arguments 86endif 87ifdef NP 88 TESTFLAGS += -n $(NP) # set number of processes 89endif 90# Override the default timeout that may be found at the top of config/petsc_harness.sh 91# This must be an integer. It is given in seconds. 92ifdef TIMEOUT 93 TESTFLAGS += -t $(TIMEOUT) # Override the default timeout 94endif 95 96$(generatedtest) : $(petscconf) $(petscvariables) $(CONFIGDIR)/gmakegentest.py $(TESTDIR)/.DIR | $$(@D)/.DIR 97 $(PYTHON) $(CONFIGDIR)/gmakegentest.py --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --testdir=$(TESTDIR) 98 99ifneq ($(filter-out clean check info libs all checkbadSource checkbadFileChange allfortranstubs alletags clangformat checkclangformat get%,$(MAKECMDGOALS:clean%=clean)),) 100include $(generatedtest) 101endif 102 103ifeq ($(PETSC_LANGUAGE),CXXONLY) 104 cc_name := CXX 105else 106 cc_name := CC 107endif 108 109PETSC_COMPILE.c = $(call quiet,$(cc_name)) -c $(PCC_FLAGS) $($(CLANGUAGE)FLAGS) $(CCPPFLAGS) $(C_DEPFLAGS) 110PETSC_COMPILE.cxx = $(call quiet,CXX) -c $(CXX_FLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(CXX_DEPFLAGS) 111PETSC_COMPILE.cu = $(call quiet,CUDAC) -c $(MPICXX_INCLUDES) $(CUDAC_FLAGS) --compiler-options="${PETSC_CXXCPPFLAGS} $(CUDACPPFLAGS) $(CUDA_CXXFLAGS)" 112PETSC_COMPILE.hip.cpp = $(call quiet,HIPC) -c $(MPICXX_INCLUDES) $(HIPC_FLAGS) $(HIPPP_FLAGS) $(HIPFLAGS) $(HIPPPFLAGS) $(HIPOPTFLAGS) $(HIPC_DEPFLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(HIP_DEPFLAGS) 113PETSC_COMPILE.sycl.cxx = $(call quiet,SYCLC) -c $(MPICXX_INCLUDES) $(SYCLC_FLAGS) $(SYCLPP_FLAGS) $(SYCLFLAGS) $(SYCLPPFLAGS) $(SYCLOPTFLAGS) $(CXXFLAGS) $(CXXCPPFLAGS) $(SYCL_DEPFLAGS) 114PETSC_GENDEPS.cu = $(call quiet,CUDAC,.dep) --generate-dependencies --output-directory=$(@D) $(MPICXX_INCLUDES) $(CUDAC_FLAGS) --compiler-options="${PETSC_CXXCPPFLAGS} $(CUDA_CXXFLAGS)" 115PETSC_COMPILE.F = $(call quiet,FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) 116 117ifneq ($(KOKKOS_USE_CUDA_COMPILER),) 118 # Kokkos requires nvcc to be in PATH and the C++ compiler to be given in an environmental variable 119 KOKC = PATH=`dirname $(CUDAC)`:$(PATH) NVCC_WRAPPER_DEFAULT_COMPILER="$(CUDA_CXX)" $(KOKKOS_BIN)/nvcc_wrapper --expt-extended-lambda 120 KOKKOS_COMPILE = $(call quiet,KOKC) -c $(CUDAC_FLAGS) ${PETSC_CXXCPPFLAGS} $(CUDACPPFLAGS) $(CUDA_CXXFLAGS) $(MPICXX_INCLUDES) 121else ifneq ($(KOKKOS_USE_HIP_COMPILER),) 122 KOKKOS_COMPILE = $(PETSC_COMPILE.hip.cpp) 123else ifneq ($(KOKKOS_USE_SYCL_COMPILER),) 124 KOKKOS_COMPILE = $(PETSC_COMPILE.sycl.cxx) 125else 126 KOKKOS_COMPILE = $(PETSC_COMPILE.cxx) 127endif 128# https://github.com/kokkos/kokkos/pull/5473 used a C++17 feature, inline static variables. 129# We found -fvisibility=hidden could hide these variables such that the supposed globally unique 130# variables become local to each file including them and thus have multiple copies (see an example 131# at the end of PR5473). It might be a gcc bug thus we also filed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107535 132# See also an older bug report related to visibility, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59693 133# 134# Our workaround here is to git rid of -fvisibility=hidden from Kokkos compiler options, so that petsc 135# files including Kokkos headers won't be affected by this flag. 136# 137# The solution is not ideal in the sense we have to duplicate the same workaround to any external libraries 138# using C++17 inline static variables. We have to wait for GNU to clarify this issue. 139PETSC_COMPILE.kokkos.cxx = $(filter-out -fvisibility=hidden,$(KOKKOS_COMPILE)) 140 141ifneq ($(RAJA_USE_CUDA_COMPILER),) 142 PETSC_COMPILE.raja.cxx = ${CUDAC} $(MPICXX_INCLUDES) ${CUDAC_FLAGS} -x cu -Xcudafe "--display_error_number" -c --compiler-options="${PETSC_CXXCPPFLAGS} ${PETSC_CC_INCLUDES} ${CUDA_CXXFLAGS}" --expt-extended-lambda --expt-relaxed-constexpr 143else 144 PETSC_COMPILE.raja.cxx = ${CXX} -o $*.o -c ${CXX_FLAGS} ${CXXFLAGS} ${CXXCPPFLAGS} 145endif 146 147testlangs := c cu cxx F F90 kokkos.cxx hip.cpp sycl.cxx raja.cxx 148$(foreach lang, $(testlangs), $(eval \ 149 testexe.$(lang) = $(foreach pkg, $(pkgs), $(testsrcs-$(pkg).$(lang):%.$(lang)=$(TESTDIR)/%)))) 150concattestlang = $(foreach lang, $(2), $(testsrcs-$(1).$(lang):%.$(lang)=$(TESTDIR)/%.o)) 151testsrcs.o := $(foreach pkg, $(pkgs), $(call concattestlang,$(pkg),$(testlangs))) 152testsrcs-rel := $(foreach pkg, $(pkgs), $(foreach lang, $(testlangs), $(testsrcs-$(pkg).$(lang)))) 153testsrcs := $(foreach sfile, $(testsrcs-rel), $(TESTSRCDIR)/$(sfile)) 154 155# workaround win32fe failure 156ifneq (,$(findstring win32fe,$(call quiet,$(cc_name)))) 157$(TESTDIR)/ts/tutorials/multirate/ex6: | $(TESTDIR)/ts/tutorials/multirate/ex5 158$(TESTDIR)/ts/tutorials/multirate/ex8: | $(TESTDIR)/ts/tutorials/multirate/ex6 159endif 160 161# Refresh testfiles when sources change, but don't balk if the source file is nonexistent (deleted) 162$(generatedtest) : $(testsrcs) 163$(testsrcs) : 164 165$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.c | $$(@D)/.DIR 166 $(PETSC_COMPILE.c) $(abspath $<) -o $@ 167 168$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.kokkos.cxx | $$(@D)/.DIR 169 $(PETSC_COMPILE.kokkos.cxx) $(abspath $<) -o $@ 170 171$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.sycl.cxx | $$(@D)/.DIR 172 $(PETSC_COMPILE.sycl.cxx) $(abspath $<) -o $@ 173 174$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.raja.cxx | $$(@D)/.DIR 175 $(PETSC_COMPILE.raja.cxx) $(abspath $<) -o $@ 176 177$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.cxx | $$(@D)/.DIR 178 $(PETSC_COMPILE.cxx) $(abspath $<) -o $@ 179 180$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.cu | $$(@D)/.DIR 181 $(PETSC_COMPILE.cu) $(abspath $<) -o $@ # Compile first so that if there is an error, it comes from a normal compile 182 @$(PETSC_GENDEPS.cu) $(abspath $<) -o $(@:%.o=%.d) # Generate the dependencies for later 183 184$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.hip.cpp | $$(@D)/.DIR 185 $(PETSC_COMPILE.hip.cpp) $(abspath $<) -o $@ 186 187# Test modules go in the same directory as the target *.o 188TESTMODDIR = $(@D) 189FCMOD = cd 190$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.F | $$(@D)/.DIR 191ifeq ($(FC_MODULE_OUTPUT_FLAG),) 192 $(call quiet,FCMOD) $(TESTMODDIR) && $(FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) -I$(dir $<) $(abspath $<) -o $(abspath $@) 193else 194 $(PETSC_COMPILE.F) -I$(dir $<) $(abspath $<) -o $@ $(FC_MODULE_OUTPUT_FLAG)$(TESTMODDIR) $(FC_MODULE_FLAG)$(TESTMODDIR) 195endif 196 -@$(GFORTRAN_DEP_CLEANUP) 197 198$(TESTDIR)/%.o : $(EXAMPLESDIR)/%.F90 | $$(@D)/.DIR 199ifeq ($(FC_MODULE_OUTPUT_FLAG),) 200 $(call quiet,FCMOD) $(TESTMODDIR) && $(FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) -I$(dir $<) $(abspath $<) -o $(abspath $@) 201else 202 $(PETSC_COMPILE.F) -I$(dir $<) $(abspath $<) -o $@ $(FC_MODULE_OUTPUT_FLAG)$(TESTMODDIR) $(FC_MODULE_FLAG)$(TESTMODDIR) 203endif 204 -@$(GFORTRAN_DEP_CLEANUP) 205 206# This is a hack to fix a broken gfortran. 207define GFORTRAN_DEP_CLEANUP 208 if test -e "$(@:%.o=%.d)" && head -1 "$(@:%.o=%.d)" | grep -F -q -v : ; then\ 209 echo "$(@): \\" > $(@:%.o=%.dtemp) ; \ 210 tr '\n' '@' < $(@:%.o=%.d) | cut -d: -f2- | tr '@' '\n' >> $(@:%.o=%.dtemp) ; \ 211 mv $(@:%.o=%.dtemp) $(@:%.o=%.d); \ 212 fi 213endef 214 215# link line constructed differently for gmakefile vs gmakefile.test invocation 216ifeq ($(libpetscall),) 217PETSC_TEST_LIB = $(PETSC_LIB) 218else 219PETSC_TEST_LIB = $(C_SH_LIB_PATH) $(PETSC_EXTERNAL_LIB_BASIC) 220endif 221 222# manually list some some library dependencies to check for circular dependencies 223$(TESTDIR)/sys/tests/ex9: PETSC_TEST_LIB = $(PETSC_SYS_LIB) 224$(TESTDIR)/vec/vec/tests/ex1: PETSC_TEST_LIB = $(PETSC_VEC_LIB) 225$(TESTDIR)/mat/tests/ex1: PETSC_TEST_LIB = $(PETSC_MAT_LIB) 226$(TESTDIR)/dm/tests/ex1: PETSC_TEST_LIB = $(PETSC_DM_LIB) 227$(TESTDIR)/ksp/ksp/tests/ex1: PETSC_TEST_LIB = $(PETSC_KSP_LIB) 228$(TESTDIR)/snes/tests/ex1: PETSC_TEST_LIB = $(PETSC_SNES_LIB) 229$(TESTDIR)/ts/tests/ex2: PETSC_TEST_LIB = $(PETSC_TS_LIB) 230$(TESTDIR)/tao/tutorials/ex1: PETSC_TEST_LIB = $(PETSC_TAO_LIB) 231 232# MACOS FIREWALL HANDLING 233# - if run with MACOS_FIREWALL=1 234# (automatically set in $PETSC_ARCH/lib/petsc/conf/petscvariables if configured --with-macos-firewall-rules), 235# ensure mpiexec and test executable is on firewall list 236# 237ifeq ($(MACOS_FIREWALL),1) 238FW := /usr/libexec/ApplicationFirewall/socketfilterfw 239# There is no reliable realpath command in macOS without need for 3rd party tools like homebrew coreutils 240# Using Python's realpath seems like the most robust way here 241realpath-py = $(shell $(PYTHON) -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' $(1)) 242# 243define macos-firewall-register 244 @APP=$(call realpath-py, $(1)); \ 245 if ! sudo -n true 2>/dev/null; then printf "Asking for sudo password to add new firewall rule for\n $$APP\n"; fi; \ 246 sudo $(FW) --remove $$APP --add $$APP --blockapp $$APP 247endef 248endif 249# 250macos-firewall-register-mpiexec: 251 -$(call macos-firewall-register, $(MPIEXEC)) 252 253# Test executables 254$(testexe.F) $(testexe.F90) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 255 $(call quiet,FLINKER) -o $@ $^ $(PETSC_TEST_LIB) 256 -$(call macos-firewall-register,$@) 257 258ifneq (,$(findstring emcc,$(CC))) 259$(testexe.c) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 260 -@$(call quiet,CLINKER) -s MAIN_MODULE -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=1 -s ALLOW_MEMORY_GROWTH $(EXEFLAGS) -o $@.js $@.o $(PETSC_LIB) 261 -@printf '#!/usr/bin/env sh\nnode --redirect-warnings=/dev/null $$0.js $$* | grep -v "Heap resize call from"' > $@ 262 -@chmod u+x $@ 263else 264$(testexe.c) $(testexe.cu) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 265 $(call quiet,CLINKER) $(EXEFLAGS) -o $@ $^ $(PETSC_TEST_LIB) 266 -$(call macos-firewall-register,$@) 267 268endif 269 270$(testexe.hip.cpp) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 271 $(call quiet,CLINKER) -o $@ $^ $(PETSC_TEST_LIB) 272 -$(call macos-firewall-register,$@) 273 274$(testexe.kokkos.cxx) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 275 $(call quiet,CLINKER) $(EXEFLAGS) -o $@ $^ $(PETSC_TEST_LIB) 276 -$(call macos-firewall-register,$@) 277 278$(testexe.raja.cxx) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 279 $(call quiet,CLINKER) -o $@ $^ $(PETSC_TEST_LIB) 280 -$(call macos-firewall-register,$@) 281 282$(testexe.cxx) : $(TESTDIR)/% : $(TESTDIR)/%.o $$^ $(libpetscall) 283 $(call quiet,CXXLINKER) -o $@ $^ $(PETSC_TEST_LIB) 284 -$(call macos-firewall-register,$@) 285 286# Fortran source files need petsc*.mod, which isn't explicitly managed in the makefile. 287$(foreach pkg, $(pkgs), $(call concattestlang,$(pkg),F F90)) : $(libpetscall) 288 289# Testing convenience targets 290.PHONY: test pre-clean 291 292test: report_tests 293 294pre-clean: 295 @$(RM) -rf $(TESTDIR)/counts $(TESTLOGTAPFILE) $(TESTLOGERRFILE) 296 @touch $(TESTLOGTAPFILE) $(TESTLOGERRFILE) 297 @echo "Using MAKEFLAGS:" ${MAKEFLAGS} 298 299check-test-errors: 300 @grep '^not ok' $(TESTLOGTAPFILE) | grep -v 'Exceeded timeout' | tee $(TESTDIR)/allgtests-tap-err.log 301 @test ! -s $(TESTDIR)/allgtests-tap-err.log 302 303.PHONY: $(foreach pkg, $(pkgs), test-$(pkg) $(foreach lang, $(testlangs), test-$(pkg).$(lang) test-rm-$(pkg).$(lang))) 304testpkgs := $(foreach pkg, $(pkgs), test-$(pkg)) 305# Targets to run tests in test-$pkg.$lang and delete the executables, language by language 306$(testpkgs) : test-% : $(foreach lang, $(testlangs), test-rm-%.$(lang)) 307# List of raw test run targets 308alltesttargets := $(foreach tp, $(testpkgs), $(foreach lang, $(testlangs), $($(tp).$(lang)))) 309 310# Run targets 311$(alltesttargets) : % : $(TESTDIR)/counts/%.counts 312.PHONY: $(alltesttargets) 313 314$(TESTDIR)/counts/%.counts : 315 $(quiettest) $< $(TESTFLAGS) 316 317# Targets to run tests and remove executables, by package-lang pairs. 318# Run the tests in each batch using recursive invocation of make because 319# we need all of them to complete before removing the executables. Make 320# doesn't guarantee an exploration order for the graph. Only recursive 321# if there is something to be done. 322alltest-rm := $(foreach pkg, $(pkgs), $(foreach lang, $(testlangs), test-rm-$(pkg).$(lang))) 323$(alltest-rm) : test-rm-% : test-% 324ifneq ($(NO_RM),1) 325 $(call quiet,RM) $(addprefix $(TESTDIR)/,$(basename $($(@:test-rm-%=testsrcs-%)))) 326endif 327 328# Remove intermediate .o files 329# This only removes the files at the end which is insufficient 330#.INTERMEDIATE: $(testsrcs.o:%.o=%) 331 332# all sources should get recompiled when petscvariables changes (i.e when configure is rerun or when petscvariables is manually edited.) 333$(testsrcs.o) : $(petscvariables) 334 335%/.DIR : 336 @mkdir -p $(@D) 337 @touch $@ 338 339.PRECIOUS: %/.DIR 340 341.SUFFIXES: # Clear .SUFFIXES because we don't use implicit rules 342.DELETE_ON_ERROR: # Delete likely-corrupt target file if rule fails 343 344.PHONY: clean cleantest all 345 346cleantest: 347 ${RM} -r $(TESTDIR) $(generatedtest) 348 349clean: cleantest 350 351alltest.d := $(testsrcs.o:%.o=%.d) 352# Tell make that alltest.d are all up to date. Without this, the include 353# below has quadratic complexity, taking more than one second for a 354# do-nothing build of PETSc (much worse for larger projects) 355$(alltest.d) : ; 356 357-include $(alltest.d) 358 359# Tests can be generated by searching -- see documentation below 360showreport= 361ifndef searchin 362 searchin = " " 363endif 364ifdef i 365 searchin = $(i) 366endif 367ifdef gs 368 gmakesearch = $(gs) 369endif 370ifdef gmakesearch 371 TESTTARGETS := $(filter $(gmakesearch),$(alltesttargets)) 372 ifdef gmakesearchin 373 TESTTARGETS2 := $(foreach v,$(TESTTARGETS),$(if $(findstring $(gmakesearchin),$(v)),$(v))) 374 TESTTARGETS := $(TESTTARGETS2) 375 endif 376else ifdef gmakesearchin 377 TESTTARGETS := $(foreach v,$(alltesttargets),$(if $(findstring $(gmakesearchin),$(v)),$(v))) 378else ifdef argsearch 379 TESTTARGETS := $(foreach v,$(alltesttargets),$(if $(findstring $(argsearch),$($(v)_ARGS)),$(v))) 380else ifdef search 381 TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) 'name' '$(search)') 382else ifdef s 383 TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) 'name' '$(s)') 384else ifdef test-fail 385 TESTTARGETS := $(shell $(TESTDIR)/echofailures.sh) 386else ifdef query 387 TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) '$(query)' '$(queryval)') 388else ifdef q 389 TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) '$(q)' '$(qv)') 390else # No filter - run them all, but delete the executables as we go 391 TESTTARGETS := $(testpkgs) 392 ifneq ($(PRINTONLY),1) 393 showreport = "-s" # Only show full report when all tests are run 394 endif 395endif 396 397.PHONY: report_tests print-test 398 399print-test: 400 $(info $(TESTTARGETS)) 401 @true 402 403show-fail: 404 -@$(PYTHON) $(CONFIGDIR)/report_tests.py -d $(TESTDIR)/counts -f 405 406 407 408# Don't start running tests until starttime has completed 409$(alltesttargets:%=$(TESTDIR)/counts/%.counts) : starttime 410 411# Ensure that libpetsc (if it is a prerequisite) has been built and clean the counts/logs before starting timer 412starttime: pre-clean $(libpetscall) macos-firewall-register-mpiexec 413 @$(eval STARTTIME := $(shell date +%s)) 414 415report_tests: starttime $(TESTTARGETS) 416 @$(eval ENDTIME := $(shell date +%s)) 417 -@ elapsed_time=$$(($(ENDTIME)- $(STARTTIME))) && \ 418 $(PYTHON) $(CONFIGDIR)/report_tests.py -m $(MAKE) -d $(TESTDIR)/counts -t 5 -e $${elapsed_time} $(showreport) 419 420check_output: 421 $(PYTHON) $(CONFIGDIR)/gmakegentest.py --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --testdir=$(TESTDIR) --check-output 422 423# Do not how how to invoke test from makefile 424HASGMAKEFILE := $(filter gmakefile,$(MAKEFILE_LIST)) 425ifeq ($(HASGMAKEFILE),gmakefile) 426helpdeps:=help-make help-targets 427makefile="gmakefile" 428other_help="To see full test help: make -f gmakefile.test help" 429else 430helpdeps:=help-make help-targets help-test 431makefile="gmakefile.test" 432other_help="" 433endif 434 435help: ${helpdeps} 436 -@echo "Above is from: ${helpdeps}" 437 -@echo "${other_help}" 438 439help-make: 440 -@echo 441 -@echo "Basic build usage:" 442 -@echo " make -f ${makefile} <options>" 443 -@echo 444 -@echo "Options:" 445 -@echo " V=0 Very quiet builds" 446 -@echo " V=1 Verbose builds" 447 -@echo 448 449help-targets: 450 -@echo "All makefile targets and their dependencies:" 451 -@grep ^[a-z] ${makefile} | grep : | grep -v = 452 -@echo 453 -@echo 454 455help-test: 456 -@echo "Basic test usage:" 457 -@echo " make -f ${makefile} test <options>" 458 -@echo 459 -@echo "Options:" 460 -@echo " V=1 Verbose output (-v to scripts)" 461 -@echo " NO_RM=1 Do not remove the executables after running" 462 -@echo " REPLACE=1 Replace the output in PETSC_DIR source tree (-m to test scripts)" 463 -@echo " OUTPUT=1 Show only the errors on stdout" 464 -@echo " ALT=1 Replace 'alt' output in PETSC_DIR source tree (-M to test scripts)" 465 -@echo " DIFF_NUMBERS=1 Diff the numbers in the output (-j to test scripts and petscdiff)" 466 -@echo " CUDAMEMCHECK=1 Execute the tests using cuda-memcheck (-U to test scripts)" 467 -@echo " Use PETSC_CUDAMEMCHECK_COMMAND to change the executable to run and" 468 -@echo " PETSC_CUDAMEMCHECK_ARGS to change the arguments (note: both" 469 -@echo " cuda-memcheck and compute-sanitizer are supported)" 470 -@echo " VALGRIND=1 Execute the tests using valgrind (-V to test scripts)" 471 -@echo " DEBUG=1 Launch tests in the debugger (-d to the scripts)" 472 -@echo " NP=<num proc> Set a number of processors to pass to scripts." 473 -@echo " FORCE=1 Force SKIP or TODO tests to run" 474 -@echo " PRINTONLY=1 Print the command, but do not run. For loops print first command" 475 -@echo " TIMEOUT=<time> Test timeout limit in seconds (default in config/petsc_harness.sh)" 476 -@echo " TESTDIR='tests' Subdirectory where tests are run ($${PETSC_DIR}/$${PETSC_ARCH}/$${TESTDIR}" 477 -@echo " or $${PREFIX_DIR}/$${TESTDIR}" 478 -@echo " or $${PREFIX_DIR}/share/petsc/examples/$${TESTDIR})" 479 -@echo " TESTBASE='tests' Subdirectory where tests are run ($${PETSC_DIR}/$${PETSC_ARCH}/$${TESTDIR}" 480 -@echo " OPTIONS='<args>' Override options to scripts (-a to test scripts)" 481 -@echo " EXTRA_OPTIONS='<args>' Add options to scripts (-e to test scripts)" 482 -@echo 483 -@echo "Special options for macOS:" 484 -@echo " MACOS_FIREWALL=1 Add each built test to the macOS firewall list to prevent popups. Configure --with-macos-firewall-rules to make this default" 485 -@echo 486 -@echo "Tests can be generated by searching with multiple methods" 487 -@echo " For general searching (using config/query_test.py):" 488 -@echo " make -f ${makefile} test search='sys*ex2*'" 489 -@echo " or the shortcut using s" 490 -@echo " make -f ${makefile} test s='sys*ex2*'" 491 -@echo " You can also use the full path to a file directory" 492 -@echo " make -f ${makefile} test s='src/sys/tests/'" 493 -@echo 494 -@echo " To search for fields from the original test definitions:" 495 -@echo " make -f ${makefile} test query='requires' queryval='*MPI_PROCESS_SHARED_MEMORY*'" 496 -@echo " or the shortcut using q and qv" 497 -@echo " make -f ${makefile} test q='requires' qv='*MPI_PROCESS_SHARED_MEMORY*'" 498 -@echo " To filter results from other searches, use searchin" 499 -@echo " make -f ${makefile} test s='src/sys/tests/' searchin='*options*'" 500 -@echo 501 -@echo " To re-run the last tests which failed:" 502 -@echo " make -f ${makefile} test test-fail='1'" 503 -@echo 504 -@echo " To see which targets match a given pattern (useful for doing a specific target):" 505 -@echo " make -f ${makefile} print-test search=sys*" 506 -@echo 507 -@echo " To build an executable, give full path to location:" 508 -@echo ' make -f ${makefile} $${PETSC_ARCH}/tests/sys/tests/ex1' 509 -@echo " or make the test with NO_RM=1" 510 -@echo 511