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