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