1*7f296bb3SBarry Smith(sec_runningtests)= 2*7f296bb3SBarry Smith 3*7f296bb3SBarry Smith# Running PETSc Tests 4*7f296bb3SBarry Smith 5*7f296bb3SBarry Smith## Quick start with the tests 6*7f296bb3SBarry Smith 7*7f296bb3SBarry SmithUsers should set 8*7f296bb3SBarry Smith`$PETSC_DIR` and `$PETSC_ARCH` before running the tests, or can 9*7f296bb3SBarry Smithprovide them on the command line as below. 10*7f296bb3SBarry Smith 11*7f296bb3SBarry SmithTo check if the libraries are working do: 12*7f296bb3SBarry Smith 13*7f296bb3SBarry Smith```console 14*7f296bb3SBarry Smith$ make PETSC_DIR=<PETSC_DIR> PETSC_ARCH=<PETSC_ARCH> check 15*7f296bb3SBarry Smith``` 16*7f296bb3SBarry Smith 17*7f296bb3SBarry SmithFor comprehensive testing of builds, the general invocation from the `$PETSC_DIR` is: 18*7f296bb3SBarry Smith 19*7f296bb3SBarry Smith```console 20*7f296bb3SBarry Smith$ make PETSC_DIR=<PETSC_DIR> $PETSC_ARCH=<PETSC_ARCH> alltests 21*7f296bb3SBarry Smith``` 22*7f296bb3SBarry Smith 23*7f296bb3SBarry Smithor 24*7f296bb3SBarry Smith 25*7f296bb3SBarry Smith```console 26*7f296bb3SBarry Smith$ make [-j <n>] test PETSC_ARCH=<PETSC_ARCH> 27*7f296bb3SBarry Smith``` 28*7f296bb3SBarry Smith 29*7f296bb3SBarry SmithFor testing `configure` that used the `--prefix` option, the 30*7f296bb3SBarry Smithgeneral invocation from the installation (prefix) directory is: 31*7f296bb3SBarry Smith 32*7f296bb3SBarry Smith```console 33*7f296bb3SBarry Smith$ make [-j <n>] -f share/petsc/examples/gmakefile.test test 34*7f296bb3SBarry Smith``` 35*7f296bb3SBarry Smith 36*7f296bb3SBarry Smithwhich will create/use the directories `tests/*` in the current directory for generated test files. 37*7f296bb3SBarry SmithYou may pass an additional argument `TESTDIR=mytests` to place these generated files elsewhere. 38*7f296bb3SBarry Smith 39*7f296bb3SBarry SmithFor a full list of options, use 40*7f296bb3SBarry Smith 41*7f296bb3SBarry Smith```console 42*7f296bb3SBarry Smith$ make help-test 43*7f296bb3SBarry Smith``` 44*7f296bb3SBarry Smith 45*7f296bb3SBarry Smith## Understanding test output and more information 46*7f296bb3SBarry Smith 47*7f296bb3SBarry SmithDepending on your machine’s configuration running the full test suite 48*7f296bb3SBarry Smith(above) can take from a few minutes to a couple hours. Note that 49*7f296bb3SBarry Smithcurrently we do not have a mechanism for automatically running the test 50*7f296bb3SBarry Smithsuite on batch computer systems except to obtain an interactive compute 51*7f296bb3SBarry Smithnode (via the batch system) and run the tests on that node (this assumes 52*7f296bb3SBarry Smiththat the compilers are available on the interactive compute nodes. 53*7f296bb3SBarry Smith 54*7f296bb3SBarry SmithThe test reporting system classifies them according to the Test Anywhere 55*7f296bb3SBarry SmithProtocal (TAP) [^id2]. In brief, the categories are 56*7f296bb3SBarry Smith 57*7f296bb3SBarry Smith- `ok` The test passed. 58*7f296bb3SBarry Smith- `not ok` The test failed. 59*7f296bb3SBarry Smith- `not ok #SKIP` The test was skipped, usually because build 60*7f296bb3SBarry Smith requirements were not met (for example, an external solver library 61*7f296bb3SBarry Smith was required, but PETSc was not `configure` for that library.) 62*7f296bb3SBarry Smith compiled against it). 63*7f296bb3SBarry Smith- `ok #TODO` The test is under development by the developers. 64*7f296bb3SBarry Smith 65*7f296bb3SBarry SmithThe tests are a series of shell scripts, generated by information 66*7f296bb3SBarry Smithcontained within the test source file, that are invoked by the makefile 67*7f296bb3SBarry Smithsystem. The tests are run in `$PETSC_DIR/$PETSC_ARCH/tests` with 68*7f296bb3SBarry Smiththe same directory as the source tree underneath. For testing installs, 69*7f296bb3SBarry Smiththe default location is `${PREFIX_DIR}/tests` but this can be changed 70*7f296bb3SBarry Smithwith the `TESTDIR` location. (See {any}`sec_directory`). A 71*7f296bb3SBarry Smithlabel is used to denote where it can be found within the source tree. 72*7f296bb3SBarry SmithFor example, test `vec_vec_tutorials-ex6`, which can be run e.g. with 73*7f296bb3SBarry Smith 74*7f296bb3SBarry Smith```console 75*7f296bb3SBarry Smith$ make test search='vec_vec_tutorials-ex6' 76*7f296bb3SBarry Smith``` 77*7f296bb3SBarry Smith 78*7f296bb3SBarry Smith(see the discussion of `search` below), denotes the shell script: 79*7f296bb3SBarry Smith 80*7f296bb3SBarry Smith```console 81*7f296bb3SBarry Smith$ $PETSC_DIR/$PETSC_ARCH/tests/vec/vec/tutorials/runex6.sh 82*7f296bb3SBarry Smith``` 83*7f296bb3SBarry Smith 84*7f296bb3SBarry SmithThese shell scripts can be run independently in those directories, and 85*7f296bb3SBarry Smithtake arguments to show the commands run, change arguments, etc. Use the 86*7f296bb3SBarry Smith`-h` option to the shell script to see these options. 87*7f296bb3SBarry Smith 88*7f296bb3SBarry SmithOften, you want to run only a subset of tests. Our makefiles use 89*7f296bb3SBarry Smith`gmake`’s wildcard syntax. In this syntax, `%` is a wild card 90*7f296bb3SBarry Smithcharacter and is passed in using the `search` argument. Two wildcard 91*7f296bb3SBarry Smithcharacters cannot be used in a search, so the `searchin` argument is 92*7f296bb3SBarry Smithused to provide the equivalent of `%pattern%` search. The default 93*7f296bb3SBarry Smithexamples have default arguments, and we often wish to test examples with 94*7f296bb3SBarry Smithvarious arguments; we use the `argsearch` argument for these searches. 95*7f296bb3SBarry SmithLike `searchin`, it does not use wildcards, but rather whether the 96*7f296bb3SBarry Smithstring is within the arguments. 97*7f296bb3SBarry Smith 98*7f296bb3SBarry SmithSome examples are: 99*7f296bb3SBarry Smith 100*7f296bb3SBarry Smith```console 101*7f296bb3SBarry Smith$ make test search='ts*' # Run all TS examples 102*7f296bb3SBarry Smith$ make test searchin='tutorials' # Run all tutorials 103*7f296bb3SBarry Smith$ make test search='ts*' searchin='tutorials' # Run all TS tutorials 104*7f296bb3SBarry Smith$ make test argsearch='cuda' # Run examples with cuda in arguments 105*7f296bb3SBarry Smith$ make test test-fail='1' 106*7f296bb3SBarry Smith$ make test query='requires' queryval='*MPI_PROCESS_SHARED_MEMORY*' 107*7f296bb3SBarry Smith``` 108*7f296bb3SBarry Smith 109*7f296bb3SBarry SmithIt is useful before invoking the tests to see what targets will be run. 110*7f296bb3SBarry SmithThe `print-test` target helps with this: 111*7f296bb3SBarry Smith 112*7f296bb3SBarry Smith```console 113*7f296bb3SBarry Smith$ make print-test argsearch='cuda' 114*7f296bb3SBarry Smith``` 115*7f296bb3SBarry Smith 116*7f296bb3SBarry SmithTo see all of the test targets which would be run, this command can be 117*7f296bb3SBarry Smithused: 118*7f296bb3SBarry Smith 119*7f296bb3SBarry Smith```console 120*7f296bb3SBarry Smith$ make print-test 121*7f296bb3SBarry Smith``` 122*7f296bb3SBarry Smith 123*7f296bb3SBarry SmithTo learn more about the test system details, one can look at the 124*7f296bb3SBarry Smith{doc}`the PETSc developers documentation </developers/testing>`. 125*7f296bb3SBarry Smith 126*7f296bb3SBarry Smith## Using the test harness for your own code 127*7f296bb3SBarry Smith 128*7f296bb3SBarry SmithSelect a package name, for example, `mypkg` and create a sub-directory with that name, say `/home/mine/mypackage/src/mypkg`. 129*7f296bb3SBarry SmithIn any sub-directory of that directory named `tests` or `tutorials` put a PETSc makefile, for example, 130*7f296bb3SBarry Smith`src/ts/tutorials/makefile` and standalone test applications that the makefile can compile with, for example 131*7f296bb3SBarry Smith 132*7f296bb3SBarry Smith```console 133*7f296bb3SBarry Smith$ make mytest 134*7f296bb3SBarry Smith``` 135*7f296bb3SBarry Smith 136*7f296bb3SBarry SmithInclude at the bottom of the test code a formatted comment indicating what tests should be run, see 137*7f296bb3SBarry Smith{any}`test_harness`. Also select a directory where you wish the tests to be compiled and run, say `/home/mine/mytests`. 138*7f296bb3SBarry Smith 139*7f296bb3SBarry SmithYou can build and run the tests with 140*7f296bb3SBarry Smith 141*7f296bb3SBarry Smith```console 142*7f296bb3SBarry Smith$ make -f ${PETSC_DIR}/gmakefile.test TESTSRCDIR=/home/mine/mypackage/src TESTDIR=/home/mine/mytests pkgs=mypkg 143*7f296bb3SBarry Smith``` 144*7f296bb3SBarry Smith 145*7f296bb3SBarry SmithThere is not yet a mechanism to have your test code also link against your library, contact us for ideas. 146*7f296bb3SBarry Smith 147*7f296bb3SBarry Smith[^id2]: See <https://testanything.org/tap-specification.html> 148