xref: /petsc/gmakefile.test (revision 4ad8454beace47809662cdae21ee081016eaa39a)
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 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
300test: report_tests
301
302pre-clean:
303	@$(RM) -rf $(TESTDIR)/counts $(TESTLOGTAPFILE) $(TESTLOGERRFILE)
304	@touch $(TESTLOGTAPFILE) $(TESTLOGERRFILE)
305	@echo "Using MAKEFLAGS:" ${MAKEFLAGS}
306
307check-test-errors:
308	@grep '^not ok' $(TESTLOGTAPFILE) | grep -v 'Exceeded timeout' | tee $(TESTDIR)/allgtests-tap-err.log
309	@test ! -s $(TESTDIR)/allgtests-tap-err.log
310
311.PHONY: $(foreach pkg, $(pkgs), test-$(pkg) $(foreach lang, $(testlangs), test-$(pkg).$(lang) test-rm-$(pkg).$(lang)))
312testpkgs := $(foreach pkg, $(pkgs), test-$(pkg))
313# Targets to run tests in test-$pkg.$lang and delete the executables, language by language
314$(testpkgs) : test-% : $(foreach lang, $(testlangs), test-rm-%.$(lang))
315# List of raw test run targets
316alltesttargets := $(foreach tp, $(testpkgs), $(foreach lang, $(testlangs), $($(tp).$(lang))))
317
318# Run targets
319$(alltesttargets) : % : $(TESTDIR)/counts/%.counts
320.PHONY: $(alltesttargets)
321
322$(TESTDIR)/counts/%.counts :
323	$(quiettest) $< $(TESTFLAGS)
324
325# Targets to run tests and remove executables, by package-lang pairs.
326# Run the tests in each batch using recursive invocation of make because
327# we need all of them to complete before removing the executables.  Make
328# doesn't guarantee an exploration order for the graph.  Only recursive
329# if there is something to be done.
330alltest-rm := $(foreach pkg, $(pkgs), $(foreach lang, $(testlangs), test-rm-$(pkg).$(lang)))
331$(alltest-rm) : test-rm-% : test-%
332ifneq ($(NO_RM),1)
333	$(call quiet,RM) $(addprefix $(TESTDIR)/,$(basename $($(@:test-rm-%=testsrcs-%))))
334endif
335
336# Remove intermediate .o files
337# This only removes the files at the end which is insufficient
338#.INTERMEDIATE: $(testsrcs.o:%.o=%)
339
340# all sources should get recompiled when petscvariables changes (i.e when configure is rerun or when petscvariables is manually edited.)
341$(testsrcs.o) : $(petscvariables)
342
343%/.DIR :
344	@mkdir -p $(@D)
345	@touch $@
346
347.PRECIOUS: %/.DIR
348
349.SUFFIXES: # Clear .SUFFIXES because we don't use implicit rules
350.DELETE_ON_ERROR:               # Delete likely-corrupt target file if rule fails
351
352.PHONY: clean cleantest all
353
354cleantest:
355	${RM} -r $(TESTDIR) $(generatedtest)
356
357clean: cleantest
358
359alltest.d := $(testsrcs.o:%.o=%.d)
360# Tell make that alltest.d are all up to date.  Without this, the include
361# below has quadratic complexity, taking more than one second for a
362# do-nothing build of PETSc (much worse for larger projects)
363$(alltest.d) : ;
364
365-include $(alltest.d)
366
367# Tests can be generated by searching -- see documentation below
368showreport=
369ifndef searchin
370   searchin = " "
371endif
372ifdef i
373   searchin = $(i)
374endif
375ifdef gs
376  gmakesearch = $(gs)
377endif
378ifdef gmakesearch
379  TESTTARGETS := $(filter $(gmakesearch),$(alltesttargets))
380  ifdef gmakesearchin
381    TESTTARGETS2 := $(foreach v,$(TESTTARGETS),$(if $(findstring $(gmakesearchin),$(v)),$(v)))
382    TESTTARGETS := $(TESTTARGETS2)
383  endif
384else ifdef gmakesearchin
385  TESTTARGETS := $(foreach v,$(alltesttargets),$(if $(findstring $(gmakesearchin),$(v)),$(v)))
386else ifdef argsearch
387  TESTTARGETS := $(foreach v,$(alltesttargets),$(if $(findstring $(argsearch),$($(v)_ARGS)),$(v)))
388else ifdef search
389  TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) 'name' '$(search)')
390else ifdef s
391  TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) 'name' '$(s)')
392else ifdef test-fail
393  TESTTARGETS := $(shell $(TESTDIR)/echofailures.sh)
394else ifdef query
395  TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) '$(query)' '$(queryval)')
396else ifdef q
397  TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --testdir=$(TESTDIR) --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) '$(q)' '$(qv)')
398else                            # No filter - run them all, but delete the executables as we go
399  TESTTARGETS := $(testpkgs)
400  ifneq ($(PRINTONLY),1)
401    showreport = "-s"  # Only show full report when all tests are run
402  endif
403endif
404
405.PHONY: report_tests print-test
406
407print-test:
408	$(info $(TESTTARGETS))
409	@true
410
411show-fail:
412	-@$(PYTHON) $(CONFIGDIR)/report_tests.py -d $(TESTDIR)/counts -f
413
414
415
416# Don't start running tests until starttime has completed
417$(alltesttargets:%=$(TESTDIR)/counts/%.counts) : starttime
418
419# Ensure that libpetsc (if it is a prerequisite) has been built and clean the counts/logs before starting timer
420starttime: pre-clean $(libpetscall) macos-firewall-register-mpiexec
421	@$(eval STARTTIME := $(shell date +%s))
422
423report_tests: starttime $(TESTTARGETS)
424	@$(eval ENDTIME := $(shell date +%s))
425	-@ elapsed_time=$$(($(ENDTIME)- $(STARTTIME))) && \
426	$(PYTHON) $(CONFIGDIR)/report_tests.py -m $(MAKE) -d $(TESTDIR)/counts -t 5 -e $${elapsed_time} $(showreport)
427
428check_output:
429	$(PYTHON) $(CONFIGDIR)/gmakegentest.py --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --testdir=$(TESTDIR)  --srcdir $(TESTSRCDIR) --pkg-pkgs "$(pkgs)" --check-output
430
431# If users make is a gnumake then these messages are provided even if the user does not do make -f gmakefile.test
432HASGMAKEFILE := $(filter gmakefile,$(MAKEFILE_LIST))
433ifeq ($(HASGMAKEFILE),gmakefile)
434helpdeps:= help-nontest
435else
436helpdeps:= help-test
437endif
438
439help: help-make ${helpdeps}
440	-@echo ""
441
442help-make:
443	-@echo
444	-@echo "PETSc makefile Basic usage:"
445	-@echo "  ${OMAKE} rule <V=1 for verbose output> <other options>"
446	-@echo
447
448help-nontest:
449	-@echo "Available rules:"
450	-@echo "   all - build (update) the PETSc and related libraries in parallel"
451	-@echo "   libs - build (update) the PETSc and related libraries"
452	-@echo "   check - run a basic check that the libraries are built correctly and can be used"
453	-@echo "   "
454	-@echo "   getmpiexec - print the mpiexec to use to run PETSc programs"
455	-@echo "   getlinklibs - print the libraries that a PETSc application must link against"
456	-@echo "   getincludedirs - print the include directories that a PETSc application must be compiled against"
457	-@echo "   getcflags - print the C compiler flags PETSc is using"
458	-@echo "   getcxxflags - print the C++ compiler flags PETSc is using"
459	-@echo "   getfortranflags - print the Fortran compiler flags PETSc is using"
460	-@echo "   "
461	-@echo "   petsc4pytest - run the entire petsc4py test suite"
462	-@echo "   alltests - run the entire PETSc test suite"
463	-@echo "   test - use \"make help-test\" for help on running the extensive tests"
464	-@echo
465	-@echo "Developer rules:"
466	-@echo "   docs - build all the PETSc documentation locally as a website"
467	-@echo "   clean - delete libraries and Fortran module files (used in $PETSC_DIR)"
468	-@echo "           delete compiled examples, .o and related files (used in tutorials or test directories)"
469	-@echo "   clangformat - run clangformat on the PETSc C/C++ source code"
470	-@echo "   clang-tidy - run clang-tidy on the PETSc C code"
471	-@echo "   allfortranstubs - regenerate Fortran stubs/interface definitions, needed after git pulls or source code changes"
472	-@echo "   deletefortranstubs - delete the generated Fortran stubs/interface definitions"
473	-@echo "   checkbadSource - check the source code for violations of coding standards"
474	-@echo "   abitest - Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD"
475	-@echo "   reconfigure - delete libraries and Fortran module files and run the previously run configure again"
476	-@echo "   lint - run lint on the source code, including its embedded documentation"
477	-@echo "     Run \"${OMAKE} help-lint\" for lint options"
478	-@echo "   "
479	-@echo "Building website: (run in the doc directory)"
480	-@cd doc; ${OMAKE} help
481	-@echo "   "
482
483help-test:
484	-@echo "Test usage:"
485	-@echo "   ${OMAKE} test <options>"
486	-@echo
487	-@echo "Options:"
488	-@echo "  NO_RM=1           Do not remove the executables after running"
489	-@echo "  REPLACE=1         Replace the output in PETSC_DIR source tree (-m to test scripts)"
490	-@echo "  OUTPUT=1          Show only the errors on stdout"
491	-@echo "  ALT=1             Replace 'alt' output in PETSC_DIR source tree (-M to test scripts)"
492	-@echo "  DIFF_NUMBERS=1    Diff the numbers in the output (-j to test scripts and petscdiff)"
493	-@echo "  CUDAMEMCHECK=1    Execute the tests using cuda-memcheck (-U to test scripts)"
494	-@echo "                    Use PETSC_CUDAMEMCHECK_COMMAND to change the executable to run and"
495	-@echo "                    PETSC_CUDAMEMCHECK_ARGS to change the arguments (note: both"
496	-@echo "                    cuda-memcheck and compute-sanitizer are supported)"
497	-@echo "  VALGRIND=1        Execute the tests using valgrind (-V to test scripts)"
498	-@echo "  DEBUG=1           Launch tests in the debugger (-d to the scripts)"
499	-@echo "  NP=<num proc>     Set a number of processors to pass to scripts."
500	-@echo "  FORCE=1           Force SKIP or TODO tests to run"
501	-@echo "  PRINTONLY=1       Print the command, but do not run.  For loops print first command"
502	-@echo "  TIMEOUT=<time>    Test timeout limit in seconds (default in config/petsc_harness.sh)"
503	-@echo "  TESTDIR='tests'   Subdirectory where tests are run ($${PETSC_DIR}/$${PETSC_ARCH}/$${TESTDIR}"
504	-@echo "                    or $${PREFIX_DIR}/$${TESTDIR}"
505	-@echo "                    or $${PREFIX_DIR}/share/petsc/examples/$${TESTDIR})"
506	-@echo "  TESTBASE='tests'   Subdirectory where tests are run ($${PETSC_DIR}/$${PETSC_ARCH}/$${TESTDIR}"
507	-@echo "  OPTIONS='<args>'  Override options to scripts (-a to test scripts)"
508	-@echo "  EXTRA_OPTIONS='<args>'  Add options to scripts (-e to test scripts)"
509	-@echo
510	-@echo "Special options for macOS:"
511	-@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"
512	-@echo
513	-@echo "Tests can be generated by searching with multiple methods"
514	-@echo "  For general searching (using config/query_tests.py):"
515	-@echo "    ${OMAKE} test search='sys*ex2*'"
516	-@echo "   or the shortcut using s"
517	-@echo "    ${OMAKE} test s='sys*ex2*'"
518	-@echo "  You can also use the full path to a file directory"
519	-@echo "    ${OMAKE} test s='src/sys/tests/'"
520	-@echo
521	-@echo "  To search for fields from the original test definitions:"
522	-@echo "    ${OMAKE} test query='requires' queryval='*MPI_PROCESS_SHARED_MEMORY*'"
523	-@echo "   or the shortcut using q and qv"
524	-@echo "    ${OMAKE} test q='requires' qv='*MPI_PROCESS_SHARED_MEMORY*'"
525	-@echo "  To filter results from other searches, use searchin"
526	-@echo "    ${OMAKE} test s='src/sys/tests/' searchin='*options*'"
527	-@echo
528	-@echo "  To re-run the last tests which failed:"
529	-@echo "    ${OMAKE} test test-fail='1'"
530	-@echo
531	-@echo "  To see which targets match a given pattern (useful for doing a specific target):"
532	-@echo "    ${OMAKE} print-test search=sys*"
533	-@echo
534	-@echo "  To build an executable, give full path to location:"
535	-@echo '    ${OMAKE} $${PETSC_ARCH}/tests/sys/tests/ex1'
536	-@echo "  or make the test with NO_RM=1"
537	-@echo
538
539help-targets:
540	-@echo "All makefile targets and their dependencies:"
541	-@grep ^[a-z] ${makefile} | grep : | grep -v =
542	-@echo
543