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