Dear Matthew, dear Jacob,

Thank you very much for your useful remarks. I managed to use the PETSc Testing System by doing as follows:

1. Redefined TESTDIR when running make
2. Used a project tree similar to that of PETSc. For examples, tests for 'package1' are in $MYLIB/src/package1/tests/
3. cp $PETSC_DIR/gmakefile.test $MYLIB/gmakefile.test

Inside gmakefile.test:

4. Right AFTER "-include petscdir.mk" added "-include mylib.mk" to have $MYLIB exported (note: this affects TESTSRCDIR)
5. Redefined variable pkgs as "pkgs := package1"
6. Introduced a few variables to make PETSC_COMPILE.c work:

CFLAGS := -I$(MYLIB)/include
LDFLAGS = -L$(MYLIB)/lib
LDLIBS = -lmylib

7. Changed the call to gmakegentest.py as follows

$(PYTHON) $(CONFIGDIR)/gmakegentest.py --petsc-dir=$(PETSC_DIR) --petsc-arch=$(PETSC_ARCH) --testdir=$(TESTDIR) --srcdir=$(MYLIB)/src --pkg-pkgs=$(pkgs)

8. Changed the rule $(testexe.c) as follows:

$(call quiet,CLINKER) $(EXEFLAGS) $(LDFLAGS) -o $@ $^ $(PETSC_TEST_LIB) $(LDLIBS)

9. Added the option --srcdir=$(TESTSRCDIR) and set --petsc-dir=$(MYLIB) when calling query_tests.py, for example:

TESTTARGETS := $(shell $(PYTHON) $(CONFIGDIR)/query_tests.py --srcdir=$(TESTSRCDIR) --testdir=$(TESTDIR) --petsc-dir=$(MYLIB) --petsc-arch=$(PETSC_ARCH) --searchin=$(searchin) 'name' '$(search)')



What do you think?

Best,
Daniele

On Mon, Mar 27, 2023 at 4:38 PM Matthew Knepley <knepley@gmail.com> wrote:
On Mon, Mar 27, 2023 at 10:19 AM Jacob Faibussowitsch <jacob.fai@gmail.com> wrote:
Our testing framework was pretty much tailor-made for the PETSc src tree and as such has many hard-coded paths and decisions. I’m going to go out on a limb and say you probably won’t get this to work...

I think we can help you get this to work. I have wanted to generalize the test framework for a long time. Everything is build by

  confg/gmakegentest.py

and I think we can get away with just changing paths here and everything will work.

  Thanks!

     Matt
 
That being said, one of the “base” paths that the testing harness uses to initially find tests is the `TESTSRCDIR` variable in `${PETSC_DIR}/gmakefile.test`. It is currently defined as
```
# TESTSRCDIR is always relative to gmakefile.test
#  This must be before includes
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
TESTSRCDIR := $(dir $(mkfile_path))src
```
You should start by changing this to
```
# TESTSRCDIR is always relative to gmakefile.test
#  This must be before includes
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
TESTSRCDIR ?= $(dir $(mkfile_path))src
```
That way you could run your tests via
```
$ make test TESTSRCDIR=/path/to/your/src/dir
```
I am sure there are many other modifications you will need to make.

Best regards,

Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)

> On Mar 27, 2023, at 06:14, Daniele Prada <daniele.prada85@gmail.com> wrote:
>
> Hello everyone,
>
> I would like to use the PETSc Testing System for testing a package that I am developing.
>
> I have read the PETSc developer documentation and have written some tests using the PETSc Test Description Language. I am going through the files in ${PETSC_DIR}/config but I am not able to make the testing system look into the directory tree of my project.
>
> Any suggestions?
>
> Thanks in advance
> Daniele



--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener