1*4bcd95a3SBarry Smith(test_harness)= 2*4bcd95a3SBarry Smith 3*4bcd95a3SBarry Smith# PETSc Testing System 4*4bcd95a3SBarry Smith 5*4bcd95a3SBarry SmithThe PETSc test system consists of 6*4bcd95a3SBarry Smith 7*4bcd95a3SBarry Smith- Formatted comments at the bottom of the tutorials and test source files that describes the tests to be run. 8*4bcd95a3SBarry Smith- The *test generator* (`config/gmakegentest.py`) that parses the tutorial and test source files and generates the makefiles and shell scripts. This is run 9*4bcd95a3SBarry Smith automatically by the make system and rarely is run directly. 10*4bcd95a3SBarry Smith- The *PETSc test harness* that consists of makefile and shell scripts that runs the executables with several logging and reporting features. 11*4bcd95a3SBarry Smith 12*4bcd95a3SBarry SmithDetails on using the harness may be found in the {ref}`user's manual <sec_runningtests>`. The testing system is used by {any}`pipelines`. 13*4bcd95a3SBarry Smith 14*4bcd95a3SBarry Smith## PETSc Test Description Language 15*4bcd95a3SBarry Smith 16*4bcd95a3SBarry SmithPETSc tests and tutorials contain at the bottom of the their source files a simple language to 17*4bcd95a3SBarry Smithdescribe tests and subtests required to run executables associated with 18*4bcd95a3SBarry Smithcompilation of that file. The general skeleton of the file is 19*4bcd95a3SBarry Smith 20*4bcd95a3SBarry Smith``` 21*4bcd95a3SBarry Smithstatic const char help[] = "A simple MOAB example\n"; 22*4bcd95a3SBarry Smith 23*4bcd95a3SBarry Smith... 24*4bcd95a3SBarry Smith<source code> 25*4bcd95a3SBarry Smith... 26*4bcd95a3SBarry Smith 27*4bcd95a3SBarry Smith/*TEST 28*4bcd95a3SBarry Smith build: 29*4bcd95a3SBarry Smith requires: moab 30*4bcd95a3SBarry Smith testset: 31*4bcd95a3SBarry Smith suffix: 1 32*4bcd95a3SBarry Smith requires: !complex 33*4bcd95a3SBarry Smith testset: 34*4bcd95a3SBarry Smith suffix: 2 35*4bcd95a3SBarry Smith args: -debug -fields v1,v2,v3 36*4bcd95a3SBarry Smith test: 37*4bcd95a3SBarry Smith test: 38*4bcd95a3SBarry Smith args: -foo bar 39*4bcd95a3SBarry SmithTEST*/ 40*4bcd95a3SBarry Smith``` 41*4bcd95a3SBarry Smith 42*4bcd95a3SBarry SmithFor our language, a *test* is associated with the following 43*4bcd95a3SBarry Smith 44*4bcd95a3SBarry Smith- A single shell script 45*4bcd95a3SBarry Smith 46*4bcd95a3SBarry Smith- A single makefile 47*4bcd95a3SBarry Smith 48*4bcd95a3SBarry Smith- An output file that represents the *expected results*. It is also possible -- though unusual -- to have multiple output files for a single test 49*4bcd95a3SBarry Smith 50*4bcd95a3SBarry Smith- Two or more command tests, usually: 51*4bcd95a3SBarry Smith 52*4bcd95a3SBarry Smith - one or more `mpiexec` tests that run the executable 53*4bcd95a3SBarry Smith - one or more `diff` tests to compare output with the expected result 54*4bcd95a3SBarry Smith 55*4bcd95a3SBarry SmithOur language also supports a *testset* that specifies either a new test 56*4bcd95a3SBarry Smithentirely or multiple executable/diff tests within a single test. At the 57*4bcd95a3SBarry Smithcore, the executable/diff test combination will look something like 58*4bcd95a3SBarry Smiththis: 59*4bcd95a3SBarry Smith 60*4bcd95a3SBarry Smith```sh 61*4bcd95a3SBarry Smithmpiexec -n 1 ../ex1 1> ex1.tmp 2> ex1.err 62*4bcd95a3SBarry Smithdiff ex1.tmp output/ex1.out 1> diff-ex1.tmp 2> diff-ex1.err 63*4bcd95a3SBarry Smith``` 64*4bcd95a3SBarry Smith 65*4bcd95a3SBarry SmithIn practice, we want to do various logging and counting by the test 66*4bcd95a3SBarry Smithharness; as are explained further below. The input language supports 67*4bcd95a3SBarry Smithsimple yet flexible test control. 68*4bcd95a3SBarry Smith 69*4bcd95a3SBarry Smith### Runtime Language Options 70*4bcd95a3SBarry Smith 71*4bcd95a3SBarry SmithAt the end of each test file, a marked comment block is 72*4bcd95a3SBarry Smithinserted to describe the test(s) to be run. The elements of the test are 73*4bcd95a3SBarry Smithdone with a set of supported key words that sets up the test. 74*4bcd95a3SBarry Smith 75*4bcd95a3SBarry SmithThe goals of the language are to be 76*4bcd95a3SBarry Smith 77*4bcd95a3SBarry Smith- as minimal as possible with the simplest test requiring only one keyword, 78*4bcd95a3SBarry Smith- independent of the filename such that a file can be renamed without rewriting the tests, and 79*4bcd95a3SBarry Smith- intuitive. 80*4bcd95a3SBarry Smith 81*4bcd95a3SBarry SmithIn order to enable the second goal, the *basestring* of the filename is 82*4bcd95a3SBarry Smithdefined as the filename without the extension; for example, if the 83*4bcd95a3SBarry Smithfilename is `ex1.c`, then `basestring=ex1`. 84*4bcd95a3SBarry Smith 85*4bcd95a3SBarry SmithWith this background, these keywords are as follows. 86*4bcd95a3SBarry Smith 87*4bcd95a3SBarry Smith- **testset** or **test**: (*Required*) 88*4bcd95a3SBarry Smith 89*4bcd95a3SBarry Smith - At the top level either a single test or a test set must be 90*4bcd95a3SBarry Smith specified. All other keywords are sub-entries of this keyword. 91*4bcd95a3SBarry Smith 92*4bcd95a3SBarry Smith- **suffix**: (*Optional*; *Default:* `suffix=""`) 93*4bcd95a3SBarry Smith 94*4bcd95a3SBarry Smith - The test name is given by `testname = basestring` if the suffix 95*4bcd95a3SBarry Smith is set to an empty string, and by 96*4bcd95a3SBarry Smith `testname = basestring + "_" + suffix` otherwise. 97*4bcd95a3SBarry Smith - This can be specified only for top level test nodes. 98*4bcd95a3SBarry Smith 99*4bcd95a3SBarry Smith- **output_file**: (*Optional*; *Default:* 100*4bcd95a3SBarry Smith `output_file = "output/" + testname + ".out"`) 101*4bcd95a3SBarry Smith 102*4bcd95a3SBarry Smith - The output of the test is to be compared with an *expected result* 103*4bcd95a3SBarry Smith whose name is given by `output_file`. 104*4bcd95a3SBarry Smith - This file is described relative to the source directory of the 105*4bcd95a3SBarry Smith source file and should be in the output subdirectory (for example, 106*4bcd95a3SBarry Smith `output/ex1.out`) 107*4bcd95a3SBarry Smith 108*4bcd95a3SBarry Smith- **nsize**: (*Optional*; *Default:* `nsize=1`) 109*4bcd95a3SBarry Smith 110*4bcd95a3SBarry Smith - This integer is passed to mpiexec; i.e., `mpiexec -n nsize` 111*4bcd95a3SBarry Smith 112*4bcd95a3SBarry Smith- **args**: (*Optional*; *Default:* `""`) 113*4bcd95a3SBarry Smith 114*4bcd95a3SBarry Smith - These arguments are passed to the executable. 115*4bcd95a3SBarry Smith 116*4bcd95a3SBarry Smith- **diff_args**: (*Optional*; *Default:* `""`) 117*4bcd95a3SBarry Smith 118*4bcd95a3SBarry Smith - These arguments are passed to the `lib/petsc/bin/petscdiff` script that 119*4bcd95a3SBarry Smith is used in the diff part of the test. For example, `-j` enables testing 120*4bcd95a3SBarry Smith the floating point numbers. 121*4bcd95a3SBarry Smith 122*4bcd95a3SBarry Smith- **TODO**: (*Optional*; *Default:* `False`) 123*4bcd95a3SBarry Smith 124*4bcd95a3SBarry Smith - Setting this Boolean to True will tell the test to appear in the 125*4bcd95a3SBarry Smith test harness but report only TODO per the TAP standard. Optionally 126*4bcd95a3SBarry Smith provide a string indicating why it is todo. 127*4bcd95a3SBarry Smith - A runscript will be generated and can easily be modified by hand 128*4bcd95a3SBarry Smith to run. 129*4bcd95a3SBarry Smith 130*4bcd95a3SBarry Smith- **filter**: (*Optional*; *Default:* `""`) 131*4bcd95a3SBarry Smith 132*4bcd95a3SBarry Smith - Sometimes only a subset of the output is meant to be tested 133*4bcd95a3SBarry Smith against the expected result. If this keyword is used, it filters 134*4bcd95a3SBarry Smith the executable output to 135*4bcd95a3SBarry Smith compare with `output_file`. 136*4bcd95a3SBarry Smith - The value of this is the command to be run, for example, 137*4bcd95a3SBarry Smith `grep foo` or `sort -nr`. 138*4bcd95a3SBarry Smith - **NOTE: this method of testing error output is NOT recommended. See section on** 139*4bcd95a3SBarry Smith {ref}`testing errors <sec_testing_error_testing>` **instead.** If the filter begins 140*4bcd95a3SBarry Smith with `Error:`, then the test is assumed to be testing the `stderr` output, and the 141*4bcd95a3SBarry Smith error code and output are set up to be tested. 142*4bcd95a3SBarry Smith 143*4bcd95a3SBarry Smith- **filter_output**: (*Optional*; *Default:* `""`) 144*4bcd95a3SBarry Smith 145*4bcd95a3SBarry Smith - Sometimes filtering the output file is useful for standardizing 146*4bcd95a3SBarry Smith tests. For example, in order to handle the issues related to 147*4bcd95a3SBarry Smith parallel output, both the output from the test example and the 148*4bcd95a3SBarry Smith output file need to be sorted (since sort does not produce the 149*4bcd95a3SBarry Smith same output on all machines). This works the same as filter to 150*4bcd95a3SBarry Smith implement this feature 151*4bcd95a3SBarry Smith 152*4bcd95a3SBarry Smith- **localrunfiles**: (*Optional*; *Default:* `""`) 153*4bcd95a3SBarry Smith 154*4bcd95a3SBarry Smith - Some tests 155*4bcd95a3SBarry Smith require runtime files that are maintained in the source tree. 156*4bcd95a3SBarry Smith Files in this (space-delimited) list will be copied over to the 157*4bcd95a3SBarry Smith testing directory so they will be found by the executable. If you 158*4bcd95a3SBarry Smith list a directory instead of files, it will copy the entire 159*4bcd95a3SBarry Smith directory (this is limited currently to a single directory) 160*4bcd95a3SBarry Smith - The copying is done by the test generator and not by creating 161*4bcd95a3SBarry Smith makefile dependencies. 162*4bcd95a3SBarry Smith 163*4bcd95a3SBarry Smith- **temporaries**: (*Optional*; *Default:* `""`) 164*4bcd95a3SBarry Smith 165*4bcd95a3SBarry Smith - Some tests produce temporary files that are read by the filter 166*4bcd95a3SBarry Smith to compare to expected results. 167*4bcd95a3SBarry Smith Files in this (space-delimited) list will cleared before 168*4bcd95a3SBarry Smith the test is run to ensure that stale temporary files are not read. 169*4bcd95a3SBarry Smith 170*4bcd95a3SBarry Smith- **requires**: (*Optional*; *Default:* `""`) 171*4bcd95a3SBarry Smith 172*4bcd95a3SBarry Smith - This is a space-delimited list of run requirements (not build 173*4bcd95a3SBarry Smith requirements; see Build requirements below). 174*4bcd95a3SBarry Smith - In general, the language supports `and` and `not` constructs 175*4bcd95a3SBarry Smith using `! => not` and `, => and`. 176*4bcd95a3SBarry Smith - MPIUNI should work for all -n 1 examples so this need not be in 177*4bcd95a3SBarry Smith the requirements list. 178*4bcd95a3SBarry Smith - Inputs sometimes require external matrices that are found in the 179*4bcd95a3SBarry Smith directory given by the environmental variable `DATAFILESPATH`. 180*4bcd95a3SBarry Smith The repository [datafiles](https://gitlab.com/petsc/datafiles) 181*4bcd95a3SBarry Smith contains all the test files needed for the test suite. 182*4bcd95a3SBarry Smith For these tests `requires: datafilespath` can be 183*4bcd95a3SBarry Smith specified. 184*4bcd95a3SBarry Smith - Packages are indicated with lower-case specification, for example, 185*4bcd95a3SBarry Smith `requires: superlu_dist`. 186*4bcd95a3SBarry Smith - Any defined variable in petscconf.h can be specified with the 187*4bcd95a3SBarry Smith `defined(...)` syntax, for example, `defined(PETSC_USE_INFO)`. 188*4bcd95a3SBarry Smith - Any definition of the form `PETSC_HAVE_FOO` can just use 189*4bcd95a3SBarry Smith `requires: foo` similar to how third-party packages are handled. 190*4bcd95a3SBarry Smith 191*4bcd95a3SBarry Smith- **timeoutfactor**: (*Optional*; *Default:* `"1"`) 192*4bcd95a3SBarry Smith 193*4bcd95a3SBarry Smith - This parameter allows you to extend the default timeout for an 194*4bcd95a3SBarry Smith individual test such that the new timeout time is 195*4bcd95a3SBarry Smith `timeout=(default timeout) x (timeoutfactor)`. 196*4bcd95a3SBarry Smith - Tests are limited to a set time that is found at the top of 197*4bcd95a3SBarry Smith `"config/petsc_harness.sh"` and can be overwritten by passing in 198*4bcd95a3SBarry Smith the `TIMEOUT` argument to `gmakefile` 199*4bcd95a3SBarry Smith 200*4bcd95a3SBarry Smith- **env**: (*Optional*; *Default:* `env=""`) 201*4bcd95a3SBarry Smith 202*4bcd95a3SBarry Smith - Allows you to set environment variables for the test. Values are copied verbatim to 203*4bcd95a3SBarry Smith the runscript and defined and exported prior to all other variables. 204*4bcd95a3SBarry Smith 205*4bcd95a3SBarry Smith - Variables defined within `env:` blocks are expanded and processed by the shell that 206*4bcd95a3SBarry Smith runs the runscript. No prior preprocessing (other than splitting the lines into 207*4bcd95a3SBarry Smith separate declarations) is done. This means that any escaping of special characters 208*4bcd95a3SBarry Smith must be done in the text of the `TEST` block. 209*4bcd95a3SBarry Smith 210*4bcd95a3SBarry Smith - Defining the `env:` keyword more than once is allowed. Subsequent declarations are 211*4bcd95a3SBarry Smith then appended to prior list of declarations . Multiple environment variables may also 212*4bcd95a3SBarry Smith be defined in the same `env:` block, i.e. given a test `ex1.c` with the following 213*4bcd95a3SBarry Smith spec: 214*4bcd95a3SBarry Smith 215*4bcd95a3SBarry Smith ```yaml 216*4bcd95a3SBarry Smith test: 217*4bcd95a3SBarry Smith env: FOO=1 BAR=1 218*4bcd95a3SBarry Smith 219*4bcd95a3SBarry Smith # equivalently 220*4bcd95a3SBarry Smith test: 221*4bcd95a3SBarry Smith env: FOO=1 222*4bcd95a3SBarry Smith env: BAR=1 223*4bcd95a3SBarry Smith ``` 224*4bcd95a3SBarry Smith 225*4bcd95a3SBarry Smith results in 226*4bcd95a3SBarry Smith 227*4bcd95a3SBarry Smith ```console 228*4bcd95a3SBarry Smith $ export FOO=1; export BAR=1; ./ex1 229*4bcd95a3SBarry Smith ``` 230*4bcd95a3SBarry Smith 231*4bcd95a3SBarry Smith - Variables defined in an `env:` block are evaluated by the runscript in the order in 232*4bcd95a3SBarry Smith which they are defined in the `TEST` block. Thus it is possible for later variables 233*4bcd95a3SBarry Smith to refer to previously defined ones: 234*4bcd95a3SBarry Smith 235*4bcd95a3SBarry Smith ```yaml 236*4bcd95a3SBarry Smith test: 237*4bcd95a3SBarry Smith env: FOO='hello' BAR=${FOO} 238*4bcd95a3SBarry Smith ``` 239*4bcd95a3SBarry Smith 240*4bcd95a3SBarry Smith results in 241*4bcd95a3SBarry Smith 242*4bcd95a3SBarry Smith ```console 243*4bcd95a3SBarry Smith $ export FOO='hello'; export BAR=${FOO}; ./ex1 244*4bcd95a3SBarry Smith # expanded by shell to 245*4bcd95a3SBarry Smith $ export FOO='hello'; export BAR='hello'; ./ex1 246*4bcd95a3SBarry Smith ``` 247*4bcd95a3SBarry Smith 248*4bcd95a3SBarry Smith Note this also implies that 249*4bcd95a3SBarry Smith 250*4bcd95a3SBarry Smith ```yaml 251*4bcd95a3SBarry Smith test: 252*4bcd95a3SBarry Smith env: FOO=1 FOO=0 253*4bcd95a3SBarry Smith ``` 254*4bcd95a3SBarry Smith 255*4bcd95a3SBarry Smith results in 256*4bcd95a3SBarry Smith 257*4bcd95a3SBarry Smith ```console 258*4bcd95a3SBarry Smith $ export FOO=1; export FOO=0; ./ex1 259*4bcd95a3SBarry Smith ``` 260*4bcd95a3SBarry Smith 261*4bcd95a3SBarry Smith### Additional Specifications 262*4bcd95a3SBarry Smith 263*4bcd95a3SBarry SmithIn addition to the above keywords, other language features are 264*4bcd95a3SBarry Smithsupported. 265*4bcd95a3SBarry Smith 266*4bcd95a3SBarry Smith- **for loops**: Specifying `{{list of values}}` will generate a loop over 267*4bcd95a3SBarry Smith an enclosed space-delimited list of values. 268*4bcd95a3SBarry Smith It is supported within `nsize` and `args`. For example, 269*4bcd95a3SBarry Smith 270*4bcd95a3SBarry Smith ``` 271*4bcd95a3SBarry Smith nsize: {{1 2 4}} 272*4bcd95a3SBarry Smith args: -matload_block_size {{2 3}shared output} 273*4bcd95a3SBarry Smith ``` 274*4bcd95a3SBarry Smith 275*4bcd95a3SBarry Smith Here the output for each `-matload_block_size` value is assumed to be 276*4bcd95a3SBarry Smith the same so that only one output file is needed. 277*4bcd95a3SBarry Smith 278*4bcd95a3SBarry Smith If the loop causes different output for each loop iteration, then `separate output` needs to be used: 279*4bcd95a3SBarry Smith 280*4bcd95a3SBarry Smith ``` 281*4bcd95a3SBarry Smith args: -matload_block_size {{2 3}separate output} 282*4bcd95a3SBarry Smith ``` 283*4bcd95a3SBarry Smith 284*4bcd95a3SBarry Smith In this case, each loop value generates a separate script, 285*4bcd95a3SBarry Smith and uses a separate output file for comparison. 286*4bcd95a3SBarry Smith 287*4bcd95a3SBarry Smith Note that `{{...}}` is equivalent to `{{...}shared output}`. 288*4bcd95a3SBarry Smith 289*4bcd95a3SBarry Smith(sec_testing_error_testing)= 290*4bcd95a3SBarry Smith 291*4bcd95a3SBarry Smith### Testing Errors And Exceptional Code 292*4bcd95a3SBarry Smith 293*4bcd95a3SBarry SmithIt is possible (and encouraged!) to test error conditions within the test harness. Since 294*4bcd95a3SBarry Smitherror messages produced by `SETERRQ()` and friends are not portable between systems, 295*4bcd95a3SBarry Smithadditional arguments must be passed to tests to modify error handling, specifically: 296*4bcd95a3SBarry Smith 297*4bcd95a3SBarry Smith```yaml 298*4bcd95a3SBarry Smithargs: -petsc_ci_portable_error_output -error_output_stdout 299*4bcd95a3SBarry Smith``` 300*4bcd95a3SBarry Smith 301*4bcd95a3SBarry SmithThese arguments have the following effect: 302*4bcd95a3SBarry Smith 303*4bcd95a3SBarry Smith- `-petsc_ci_portable_error_output`: Strips system or configuration-specific information 304*4bcd95a3SBarry Smith from error messages. Specifically this: 305*4bcd95a3SBarry Smith 306*4bcd95a3SBarry Smith - Removes all path components except the file name from the traceback 307*4bcd95a3SBarry Smith - Removes line and column numbers from the traceback 308*4bcd95a3SBarry Smith - Removes PETSc version information 309*4bcd95a3SBarry Smith - Removes `configure` options used 310*4bcd95a3SBarry Smith - Removes system name 311*4bcd95a3SBarry Smith - Removes hostname 312*4bcd95a3SBarry Smith - Removes date 313*4bcd95a3SBarry Smith 314*4bcd95a3SBarry Smith With this option error messages will be identical across systems, runs, and PETSc 315*4bcd95a3SBarry Smith configurations (barring of course configurations in which the error is not raised). 316*4bcd95a3SBarry Smith 317*4bcd95a3SBarry Smith Furthermore, this option also changes the default behavior of the error handler to 318*4bcd95a3SBarry Smith **gracefully** exit where possible. For single-ranked runs this means returning with 319*4bcd95a3SBarry Smith exit-code `0` and calling `MPI_Finalize()` instead of `MPI_Abort()`. Multi-rank 320*4bcd95a3SBarry Smith tests will call `MPI_Abort()` on errors raised on `PETSC_COMM_SELF`, but will call 321*4bcd95a3SBarry Smith `MPI_Finalize()` otherwise. 322*4bcd95a3SBarry Smith 323*4bcd95a3SBarry Smith- `-error_output_stdout`: Forces `SETERRQ()` and friends to dump error messages to 324*4bcd95a3SBarry Smith `stdout` instead of `stderr`. While using `stderr` (alongside the `Error:` 325*4bcd95a3SBarry Smith sub-directive under `filter:`) also works it appears to be unstable under heavy 326*4bcd95a3SBarry Smith load, especially in CI. 327*4bcd95a3SBarry Smith 328*4bcd95a3SBarry SmithUsing both options in tandem allows one to use the normal `output:` mechanism to compare 329*4bcd95a3SBarry Smithexpected and actual error outputs. 330*4bcd95a3SBarry Smith 331*4bcd95a3SBarry SmithWhen writing ASCII output that may be not portable, so one wants `-petsc_ci_portable_error_output` to 332*4bcd95a3SBarry Smithcause the output to be skipped, enclose the output with code such as 333*4bcd95a3SBarry Smith 334*4bcd95a3SBarry Smith``` 335*4bcd95a3SBarry Smithif (!PetscCIEnabledPortableErrorOutput) 336*4bcd95a3SBarry Smith``` 337*4bcd95a3SBarry Smith 338*4bcd95a3SBarry Smithto prevent it from being output when the CI test harness is running. 339*4bcd95a3SBarry Smith 340*4bcd95a3SBarry Smith### Test Block Examples 341*4bcd95a3SBarry Smith 342*4bcd95a3SBarry SmithThe following is the simplest test block: 343*4bcd95a3SBarry Smith 344*4bcd95a3SBarry Smith```yaml 345*4bcd95a3SBarry Smith/*TEST 346*4bcd95a3SBarry Smith test: 347*4bcd95a3SBarry SmithTEST*/ 348*4bcd95a3SBarry Smith``` 349*4bcd95a3SBarry Smith 350*4bcd95a3SBarry SmithIf this block is in `src/a/b/examples/tutorials/ex1.c`, then it will 351*4bcd95a3SBarry Smithcreate `a_b_tutorials-ex1` test that requires only one 352*4bcd95a3SBarry Smithprocess, with no arguments, and diff the resultant output with 353*4bcd95a3SBarry Smith`src/a/b/examples/tutorials/output/ex1.out`. 354*4bcd95a3SBarry Smith 355*4bcd95a3SBarry SmithFor Fortran, the equivalent is 356*4bcd95a3SBarry Smith 357*4bcd95a3SBarry Smith```fortran 358*4bcd95a3SBarry Smith!/*TEST 359*4bcd95a3SBarry Smith! test: 360*4bcd95a3SBarry Smith!TEST*/ 361*4bcd95a3SBarry Smith``` 362*4bcd95a3SBarry Smith 363*4bcd95a3SBarry SmithA more complete example, showing just the lines between `/*TEST` and `TEST*/`: 364*4bcd95a3SBarry Smith 365*4bcd95a3SBarry Smith```yaml 366*4bcd95a3SBarry Smithtest: 367*4bcd95a3SBarry Smithtest: 368*4bcd95a3SBarry Smith suffix: 1 369*4bcd95a3SBarry Smith nsize: 2 370*4bcd95a3SBarry Smith args: -t 2 -pc_type jacobi -ksp_monitor_short -ksp_type gmres 371*4bcd95a3SBarry Smith args: -ksp_gmres_cgs_refinement_type refine_always -s2_ksp_type bcgs 372*4bcd95a3SBarry Smith args: -s2_pc_type jacobi -s2_ksp_monitor_short 373*4bcd95a3SBarry Smith requires: x 374*4bcd95a3SBarry Smith``` 375*4bcd95a3SBarry Smith 376*4bcd95a3SBarry SmithThis creates two tests. Assuming that this is 377*4bcd95a3SBarry Smith`src/a/b/examples/tutorials/ex1.c`, the tests would be 378*4bcd95a3SBarry Smith`a_b_tutorials-ex1` and `a_b_tutorials-ex1_1`. 379*4bcd95a3SBarry Smith 380*4bcd95a3SBarry SmithFollowing is an example of how to test a permutation of arguments 381*4bcd95a3SBarry Smithagainst the same output file: 382*4bcd95a3SBarry Smith 383*4bcd95a3SBarry Smith```yaml 384*4bcd95a3SBarry Smithtestset: 385*4bcd95a3SBarry Smith suffix: 19 386*4bcd95a3SBarry Smith requires: datafilespath 387*4bcd95a3SBarry Smith args: -f0 ${DATAFILESPATH}/matrices/poisson1 388*4bcd95a3SBarry Smith args: -ksp_type cg -pc_type icc -pc_factor_levels 2 389*4bcd95a3SBarry Smith test: 390*4bcd95a3SBarry Smith test: 391*4bcd95a3SBarry Smith args: -mat_type seqsbaij 392*4bcd95a3SBarry Smith``` 393*4bcd95a3SBarry Smith 394*4bcd95a3SBarry SmithAssuming that this is `ex10.c`, there would be two mpiexec/diff 395*4bcd95a3SBarry Smithinvocations in `runex10_19.sh`. 396*4bcd95a3SBarry Smith 397*4bcd95a3SBarry SmithHere is a similar example, but the permutation of arguments creates 398*4bcd95a3SBarry Smithdifferent output: 399*4bcd95a3SBarry Smith 400*4bcd95a3SBarry Smith```yaml 401*4bcd95a3SBarry Smithtestset: 402*4bcd95a3SBarry Smith requires: datafilespath 403*4bcd95a3SBarry Smith args: -f0 ${DATAFILESPATH}/matrices/medium 404*4bcd95a3SBarry Smith args: -ksp_type bicg 405*4bcd95a3SBarry Smith test: 406*4bcd95a3SBarry Smith suffix: 4 407*4bcd95a3SBarry Smith args: -pc_type lu 408*4bcd95a3SBarry Smith test: 409*4bcd95a3SBarry Smith suffix: 5 410*4bcd95a3SBarry Smith``` 411*4bcd95a3SBarry Smith 412*4bcd95a3SBarry SmithAssuming that this is `ex10.c`, two shell scripts will be created: 413*4bcd95a3SBarry Smith`runex10_4.sh` and `runex10_5.sh`. 414*4bcd95a3SBarry Smith 415*4bcd95a3SBarry SmithAn example using a for loop is: 416*4bcd95a3SBarry Smith 417*4bcd95a3SBarry Smith```yaml 418*4bcd95a3SBarry Smithtestset: 419*4bcd95a3SBarry Smith suffix: 1 420*4bcd95a3SBarry Smith args: -f ${DATAFILESPATH}/matrices/small -mat_type aij 421*4bcd95a3SBarry Smith requires: datafilespath 422*4bcd95a3SBarry Smithtestset: 423*4bcd95a3SBarry Smith suffix: 2 424*4bcd95a3SBarry Smith output_file: output/ex138_1.out 425*4bcd95a3SBarry Smith args: -f ${DATAFILESPATH}/matrices/small 426*4bcd95a3SBarry Smith args: -mat_type baij -matload_block_size {{2 3}shared output} 427*4bcd95a3SBarry Smith requires: datafilespath 428*4bcd95a3SBarry Smith``` 429*4bcd95a3SBarry Smith 430*4bcd95a3SBarry SmithIn this example, `ex138_2` will invoke `runex138_2.sh` twice with 431*4bcd95a3SBarry Smithtwo different arguments, but both are diffed with the same file. 432*4bcd95a3SBarry Smith 433*4bcd95a3SBarry SmithFollowing is an example showing the hierarchical nature of the test 434*4bcd95a3SBarry Smithspecification. 435*4bcd95a3SBarry Smith 436*4bcd95a3SBarry Smith```yaml 437*4bcd95a3SBarry Smithtestset: 438*4bcd95a3SBarry Smith suffix:2 439*4bcd95a3SBarry Smith output_file: output/ex138_1.out 440*4bcd95a3SBarry Smith args: -f ${DATAFILESPATH}/matrices/small -mat_type baij 441*4bcd95a3SBarry Smith test: 442*4bcd95a3SBarry Smith args: -matload_block_size 2 443*4bcd95a3SBarry Smith test: 444*4bcd95a3SBarry Smith args: -matload_block_size 3 445*4bcd95a3SBarry Smith``` 446*4bcd95a3SBarry Smith 447*4bcd95a3SBarry SmithThis is functionally equivalent to the for loop shown above. 448*4bcd95a3SBarry Smith 449*4bcd95a3SBarry SmithHere is a more complex example using for loops: 450*4bcd95a3SBarry Smith 451*4bcd95a3SBarry Smith```yaml 452*4bcd95a3SBarry Smithtestset: 453*4bcd95a3SBarry Smith suffix: 19 454*4bcd95a3SBarry Smith requires: datafilespath 455*4bcd95a3SBarry Smith args: -f0 ${DATAFILESPATH}/matrices/poisson1 456*4bcd95a3SBarry Smith args: -ksp_type cg -pc_type icc 457*4bcd95a3SBarry Smith args: -pc_factor_levels {{0 2 4}separate output} 458*4bcd95a3SBarry Smith test: 459*4bcd95a3SBarry Smith test: 460*4bcd95a3SBarry Smith args: -mat_type seqsbaij 461*4bcd95a3SBarry Smith``` 462*4bcd95a3SBarry Smith 463*4bcd95a3SBarry SmithIf this is in `ex10.c`, then the shell scripts generated would be 464*4bcd95a3SBarry Smith 465*4bcd95a3SBarry Smith- `runex10_19_pc_factor_levels-0.sh` 466*4bcd95a3SBarry Smith- `runex10_19_pc_factor_levels-2.sh` 467*4bcd95a3SBarry Smith- `runex10_19_pc_factor_levels-4.sh` 468*4bcd95a3SBarry Smith 469*4bcd95a3SBarry SmithEach shell script would invoke twice. 470*4bcd95a3SBarry Smith 471*4bcd95a3SBarry Smith### Build Language Options 472*4bcd95a3SBarry Smith 473*4bcd95a3SBarry SmithYou can specify issues related to the compilation of the source file 474*4bcd95a3SBarry Smithwith the `build:` block. The language is as follows. 475*4bcd95a3SBarry Smith 476*4bcd95a3SBarry Smith- **requires:** (*Optional*; *Default:* `""`) 477*4bcd95a3SBarry Smith 478*4bcd95a3SBarry Smith - Same as the runtime requirements (for example, can include 479*4bcd95a3SBarry Smith `requires: fftw`) but also requirements related to types: 480*4bcd95a3SBarry Smith 481*4bcd95a3SBarry Smith 1. Precision types: `single`, `double`, `quad`, `int32` 482*4bcd95a3SBarry Smith 2. Scalar types: `complex` (and `!complex`) 483*4bcd95a3SBarry Smith 484*4bcd95a3SBarry Smith - In addition, `TODO` is available to allow you to skip the build 485*4bcd95a3SBarry Smith of this file but still maintain it in the source tree. 486*4bcd95a3SBarry Smith 487*4bcd95a3SBarry Smith- **depends:** (*Optional*; *Default:* `""`) 488*4bcd95a3SBarry Smith 489*4bcd95a3SBarry Smith - List any dependencies required to compile the file 490*4bcd95a3SBarry Smith 491*4bcd95a3SBarry SmithA typical example for compiling for only real numbers is 492*4bcd95a3SBarry Smith 493*4bcd95a3SBarry Smith``` 494*4bcd95a3SBarry Smith/*TEST 495*4bcd95a3SBarry Smith build: 496*4bcd95a3SBarry Smith requires: !complex 497*4bcd95a3SBarry Smith test: 498*4bcd95a3SBarry SmithTEST*/ 499*4bcd95a3SBarry Smith``` 500*4bcd95a3SBarry Smith 501*4bcd95a3SBarry Smith## Running the tests 502*4bcd95a3SBarry Smith 503*4bcd95a3SBarry SmithThe make rules for running tests are contained in `gmakefile.test` in the PETSc root directory. They can usually be accessed by 504*4bcd95a3SBarry Smithsimply using commands such as 505*4bcd95a3SBarry Smith 506*4bcd95a3SBarry Smith```console 507*4bcd95a3SBarry Smith$ make test 508*4bcd95a3SBarry Smith``` 509*4bcd95a3SBarry Smith 510*4bcd95a3SBarry Smithor, for a list of test options, 511*4bcd95a3SBarry Smith 512*4bcd95a3SBarry Smith```console 513*4bcd95a3SBarry Smith$ make help-test 514*4bcd95a3SBarry Smith``` 515*4bcd95a3SBarry Smith 516*4bcd95a3SBarry Smith### Determining the failed jobs of a given run 517*4bcd95a3SBarry Smith 518*4bcd95a3SBarry SmithThe running of the test harness will show which tests fail, but you may not have 519*4bcd95a3SBarry Smithlogged the output or run without showing the full error. The best way of 520*4bcd95a3SBarry Smithexamining the errors is with this command: 521*4bcd95a3SBarry Smith 522*4bcd95a3SBarry Smith```console 523*4bcd95a3SBarry Smith$ $EDITOR $PETSC_DIR/$PETSC_ARCH/tests/test*err.log 524*4bcd95a3SBarry Smith``` 525*4bcd95a3SBarry Smith 526*4bcd95a3SBarry SmithThis method can also be used for the PETSc continuous integration (CI) pipeline jobs. For failed jobs you can download the 527*4bcd95a3SBarry Smithlog files from the `artifacts download` tab on the right side: 528*4bcd95a3SBarry Smith 529*4bcd95a3SBarry Smith:::{figure} /images/developers/test-artifacts.png 530*4bcd95a3SBarry Smith:alt: Test Artifacts at Gitlab 531*4bcd95a3SBarry Smith 532*4bcd95a3SBarry SmithTest artifacts can be downloaded from GitLab. 533*4bcd95a3SBarry Smith::: 534*4bcd95a3SBarry Smith 535*4bcd95a3SBarry SmithTo see the list of all tests that failed from the last run, you can also run this command: 536*4bcd95a3SBarry Smith 537*4bcd95a3SBarry Smith```console 538*4bcd95a3SBarry Smith$ make print-test test-fail=1 539*4bcd95a3SBarry Smith``` 540*4bcd95a3SBarry Smith 541*4bcd95a3SBarry SmithTo print it out in a column format: 542*4bcd95a3SBarry Smith 543*4bcd95a3SBarry Smith```console 544*4bcd95a3SBarry Smith$ make print-test test-fail=1 | tr ' ' '\n' | sort 545*4bcd95a3SBarry Smith``` 546*4bcd95a3SBarry Smith 547*4bcd95a3SBarry SmithOnce you know which tests failed, the question is how to debug them. 548*4bcd95a3SBarry Smith 549*4bcd95a3SBarry Smith### Introduction to debugging workflows 550*4bcd95a3SBarry Smith 551*4bcd95a3SBarry SmithHere, two different workflows on developing with the test harness are presented, 552*4bcd95a3SBarry Smithand then the language for adding a new test is described. Before describing the 553*4bcd95a3SBarry Smithworkflow, we first discuss the output of the test harness and how it maps onto 554*4bcd95a3SBarry Smithmakefile targets and shell scripts. 555*4bcd95a3SBarry Smith 556*4bcd95a3SBarry SmithConsider this line from running the PETSc test system: 557*4bcd95a3SBarry Smith 558*4bcd95a3SBarry Smith``` 559*4bcd95a3SBarry SmithTEST arch-ci-linux-uni-pkgs/tests/counts/vec_is_sf_tests-ex1_basic_1.counts 560*4bcd95a3SBarry Smith``` 561*4bcd95a3SBarry Smith 562*4bcd95a3SBarry SmithThe string `vec_is_sf_tests-ex1_basic_1` gives the following information: 563*4bcd95a3SBarry Smith 564*4bcd95a3SBarry Smith- The file generating the tests is found in `$PETSC_DIR/src/vec/is/sf/tests/ex1.c` 565*4bcd95a3SBarry Smith- The makefile target for the *test* is `vec_is_sf_tests-ex1_basic_1` 566*4bcd95a3SBarry Smith- The makefile target for the *executable* is `$PETSC_ARCH/tests/vec/is/sf/tests/ex1` 567*4bcd95a3SBarry Smith- The shell script running the test is located at: `$PETSC_DIR/$PETSC_ARCH/tests/vec/is/sf/tests/runex1_basic_1.sh` 568*4bcd95a3SBarry Smith 569*4bcd95a3SBarry SmithLet's say that you want to debug a single test as part of development. There 570*4bcd95a3SBarry Smithare two basic methods of doing this: 1) use shell script directly in test 571*4bcd95a3SBarry Smithdirectory, or 2) use the gmakefile.test from the top level directory. We present both 572*4bcd95a3SBarry Smithworkflows. 573*4bcd95a3SBarry Smith 574*4bcd95a3SBarry Smith### Debugging a test using shell the generated scripts 575*4bcd95a3SBarry Smith 576*4bcd95a3SBarry SmithFirst, look at the working directory and the options for the 577*4bcd95a3SBarry Smithscripts: 578*4bcd95a3SBarry Smith 579*4bcd95a3SBarry Smith```console 580*4bcd95a3SBarry Smith$ cd $PETSC_ARCH/tests/vec/is/sf/tests 581*4bcd95a3SBarry Smith$ ./runex1_basic_1.sh -h 582*4bcd95a3SBarry SmithUsage: ./runex1_basic_1.sh [options] 583*4bcd95a3SBarry Smith 584*4bcd95a3SBarry SmithOPTIONS 585*4bcd95a3SBarry Smith -a <args> ......... Override default arguments 586*4bcd95a3SBarry Smith -c ................ Cleanup (remove generated files) 587*4bcd95a3SBarry Smith -C ................ Compile 588*4bcd95a3SBarry Smith -d ................ Launch in debugger 589*4bcd95a3SBarry Smith -e <args> ......... Add extra arguments to default 590*4bcd95a3SBarry Smith -f ................ force attempt to run test that would otherwise be skipped 591*4bcd95a3SBarry Smith -h ................ help: print this message 592*4bcd95a3SBarry Smith -n <integer> ...... Override the number of processors to use 593*4bcd95a3SBarry Smith -j ................ Pass -j to petscdiff (just use diff) 594*4bcd95a3SBarry Smith -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 595*4bcd95a3SBarry Smith -m ................ Update results using petscdiff 596*4bcd95a3SBarry Smith -M ................ Update alt files using petscdiff 597*4bcd95a3SBarry Smith -o <arg> .......... Output format: 'interactive', 'err_only' 598*4bcd95a3SBarry Smith -p ................ Print command: Print first command and exit 599*4bcd95a3SBarry Smith -t ................ Override the default timeout (default=60 sec) 600*4bcd95a3SBarry Smith -U ................ run cUda-memcheck 601*4bcd95a3SBarry Smith -V ................ run Valgrind 602*4bcd95a3SBarry Smith -v ................ Verbose: Print commands 603*4bcd95a3SBarry Smith``` 604*4bcd95a3SBarry Smith 605*4bcd95a3SBarry SmithWe will be using the `-C`, `-V`, and `-p` flags. 606*4bcd95a3SBarry Smith 607*4bcd95a3SBarry SmithA basic workflow is something similar to: 608*4bcd95a3SBarry Smith 609*4bcd95a3SBarry Smith```console 610*4bcd95a3SBarry Smith$ <edit> 611*4bcd95a3SBarry Smith$ runex1_basic_1.sh -C 612*4bcd95a3SBarry Smith$ <edit> 613*4bcd95a3SBarry Smith$ ... 614*4bcd95a3SBarry Smith$ runex1_basic_1.sh -m # If need to update results 615*4bcd95a3SBarry Smith$ ... 616*4bcd95a3SBarry Smith$ runex1_basic_1.sh -V # Make sure valgrind clean 617*4bcd95a3SBarry Smith$ cd $PETSC_DIR 618*4bcd95a3SBarry Smith$ git commit -a 619*4bcd95a3SBarry Smith``` 620*4bcd95a3SBarry Smith 621*4bcd95a3SBarry SmithFor loops it sometimes can become onerous to run the whole test. 622*4bcd95a3SBarry SmithIn this case, you can use the `-p` flag to print just the first 623*4bcd95a3SBarry Smithcommand. It will print a command suitable for running from 624*4bcd95a3SBarry Smith`$PETSC_DIR`, but it is easy to modify for execution in the test 625*4bcd95a3SBarry Smithdirectory: 626*4bcd95a3SBarry Smith 627*4bcd95a3SBarry Smith```console 628*4bcd95a3SBarry Smith$ runex1_basic_1.sh -p 629*4bcd95a3SBarry Smith``` 630*4bcd95a3SBarry Smith 631*4bcd95a3SBarry Smith### Debugging a PETSc test using the gmakefile.test 632*4bcd95a3SBarry Smith 633*4bcd95a3SBarry SmithFirst recall how to find help for the options: 634*4bcd95a3SBarry Smith 635*4bcd95a3SBarry Smith```console 636*4bcd95a3SBarry Smith$ make help-test 637*4bcd95a3SBarry Smith``` 638*4bcd95a3SBarry Smith 639*4bcd95a3SBarry SmithTo compile the test and run it: 640*4bcd95a3SBarry Smith 641*4bcd95a3SBarry Smith```console 642*4bcd95a3SBarry Smith$ make test search=vec_is_sf_tests-ex1_basic_1 643*4bcd95a3SBarry Smith``` 644*4bcd95a3SBarry Smith 645*4bcd95a3SBarry SmithThis can consist of your basic workflow. However, 646*4bcd95a3SBarry Smithfor the normal compile and edit, running the entire harness with search can be 647*4bcd95a3SBarry Smithcumbersome. So first get the command: 648*4bcd95a3SBarry Smith 649*4bcd95a3SBarry Smith```console 650*4bcd95a3SBarry Smith$ make vec_is_sf_tests-ex1_basic_1 PRINTONLY=1 651*4bcd95a3SBarry Smith<copy command> 652*4bcd95a3SBarry Smith<edit> 653*4bcd95a3SBarry Smith$ make $PETSC_ARCH/tests/vec/is/sf/tests/ex1 654*4bcd95a3SBarry Smith$ /scratch/kruger/contrib/petsc-mpich-cxx/bin/mpiexec -n 1 arch-mpich-cxx-py3/tests/vec/is/sf/tests/ex1 655*4bcd95a3SBarry Smith... 656*4bcd95a3SBarry Smith$ cd $PETSC_DIR 657*4bcd95a3SBarry Smith$ git commit -a 658*4bcd95a3SBarry Smith``` 659*4bcd95a3SBarry Smith 660*4bcd95a3SBarry Smith### Advanced searching 661*4bcd95a3SBarry Smith 662*4bcd95a3SBarry SmithFor forming a search, it is recommended to always use `print-test` instead of 663*4bcd95a3SBarry Smith`test` to make sure it is returning the values that you want. 664*4bcd95a3SBarry Smith 665*4bcd95a3SBarry SmithThe three basic and recommended arguments are: 666*4bcd95a3SBarry Smith 667*4bcd95a3SBarry Smith- `search` (or `s`) 668*4bcd95a3SBarry Smith 669*4bcd95a3SBarry Smith - Searches based on name of test target (see above) 670*4bcd95a3SBarry Smith 671*4bcd95a3SBarry Smith - Use the familiar glob syntax (like the Unix `ls` command). Example: 672*4bcd95a3SBarry Smith 673*4bcd95a3SBarry Smith ```console 674*4bcd95a3SBarry Smith $ make print-test search='vec_is*ex1*basic*1' 675*4bcd95a3SBarry Smith ``` 676*4bcd95a3SBarry Smith 677*4bcd95a3SBarry Smith Equivalently: 678*4bcd95a3SBarry Smith 679*4bcd95a3SBarry Smith ```console 680*4bcd95a3SBarry Smith $ make print-test s='vec_is*ex1*basic*1' 681*4bcd95a3SBarry Smith ``` 682*4bcd95a3SBarry Smith 683*4bcd95a3SBarry Smith - It also takes full paths. Examples: 684*4bcd95a3SBarry Smith 685*4bcd95a3SBarry Smith ```console 686*4bcd95a3SBarry Smith $ make print-test s='src/vec/is/tests/ex1.c' 687*4bcd95a3SBarry Smith ``` 688*4bcd95a3SBarry Smith 689*4bcd95a3SBarry Smith ```console 690*4bcd95a3SBarry Smith $ make print-test s='src/dm/impls/plex/tests/' 691*4bcd95a3SBarry Smith ``` 692*4bcd95a3SBarry Smith 693*4bcd95a3SBarry Smith ```console 694*4bcd95a3SBarry Smith $ make print-test s='src/dm/impls/plex/tests/ex1.c' 695*4bcd95a3SBarry Smith ``` 696*4bcd95a3SBarry Smith 697*4bcd95a3SBarry Smith- `query` and `queryval` (or `q` and `qv`) 698*4bcd95a3SBarry Smith 699*4bcd95a3SBarry Smith - `query` corresponds to test harness keyword, `queryval` to the value. Example: 700*4bcd95a3SBarry Smith 701*4bcd95a3SBarry Smith ```console 702*4bcd95a3SBarry Smith $ make print-test query='suffix' queryval='basic_1' 703*4bcd95a3SBarry Smith ``` 704*4bcd95a3SBarry Smith 705*4bcd95a3SBarry Smith - Invokes `config/query_tests.py` to query the tests (see 706*4bcd95a3SBarry Smith `config/query_tests.py --help` for more information). 707*4bcd95a3SBarry Smith 708*4bcd95a3SBarry Smith - See below for how to use as it has many features 709*4bcd95a3SBarry Smith 710*4bcd95a3SBarry Smith- `searchin` (or `i`) 711*4bcd95a3SBarry Smith 712*4bcd95a3SBarry Smith - Filters results of above searches. Example: 713*4bcd95a3SBarry Smith 714*4bcd95a3SBarry Smith ```console 715*4bcd95a3SBarry Smith $ make print-test s='src/dm/impls/plex/tests/ex1.c' i='*refine_overlap_2d*' 716*4bcd95a3SBarry Smith ``` 717*4bcd95a3SBarry Smith 718*4bcd95a3SBarry SmithSearching using GNU make's native regexp functionality is kept for people who like it, but most developers will likely prefer the above methods: 719*4bcd95a3SBarry Smith 720*4bcd95a3SBarry Smith- `gmakesearch` 721*4bcd95a3SBarry Smith 722*4bcd95a3SBarry Smith - Use GNU make's own filter capability. 723*4bcd95a3SBarry Smith 724*4bcd95a3SBarry Smith - Fast, but requires knowing GNU make regex syntax which uses `%` instead of `*` 725*4bcd95a3SBarry Smith 726*4bcd95a3SBarry Smith - Also very limited (cannot use two `%`'s for example) 727*4bcd95a3SBarry Smith 728*4bcd95a3SBarry Smith - Example: 729*4bcd95a3SBarry Smith 730*4bcd95a3SBarry Smith ```console 731*4bcd95a3SBarry Smith $ make test gmakesearch='vec_is%ex1_basic_1' 732*4bcd95a3SBarry Smith ``` 733*4bcd95a3SBarry Smith 734*4bcd95a3SBarry Smith- `gmakesearchin` 735*4bcd95a3SBarry Smith 736*4bcd95a3SBarry Smith - Use GNU make's own filter capability to search in previous results. Example: 737*4bcd95a3SBarry Smith 738*4bcd95a3SBarry Smith ```console 739*4bcd95a3SBarry Smith $ make test gmakesearch='vec_is%1' gmakesearchin='basic' 740*4bcd95a3SBarry Smith ``` 741*4bcd95a3SBarry Smith 742*4bcd95a3SBarry Smith### Query-based searching 743*4bcd95a3SBarry Smith 744*4bcd95a3SBarry SmithNote the use of glob style matching is also accepted in the value field: 745*4bcd95a3SBarry Smith 746*4bcd95a3SBarry Smith```console 747*4bcd95a3SBarry Smith$ make print-test query='suffix' queryval='basic_1' 748*4bcd95a3SBarry Smith``` 749*4bcd95a3SBarry Smith 750*4bcd95a3SBarry Smith```console 751*4bcd95a3SBarry Smith$ make print-test query='requires' queryval='cuda' 752*4bcd95a3SBarry Smith``` 753*4bcd95a3SBarry Smith 754*4bcd95a3SBarry Smith```console 755*4bcd95a3SBarry Smith$ make print-test query='requires' queryval='defined(PETSC_HAVE_MPI_GPU_AWARE)' 756*4bcd95a3SBarry Smith``` 757*4bcd95a3SBarry Smith 758*4bcd95a3SBarry Smith```console 759*4bcd95a3SBarry Smith$ make print-test query='requires' queryval='*GPU_AWARE*' 760*4bcd95a3SBarry Smith``` 761*4bcd95a3SBarry Smith 762*4bcd95a3SBarry SmithUsing the `name` field is equivalent to the search above: 763*4bcd95a3SBarry Smith 764*4bcd95a3SBarry Smith- Example: 765*4bcd95a3SBarry Smith 766*4bcd95a3SBarry Smith ```console 767*4bcd95a3SBarry Smith $ make print-test query='name' queryval='vec_is*ex1*basic*1' 768*4bcd95a3SBarry Smith ``` 769*4bcd95a3SBarry Smith 770*4bcd95a3SBarry Smith- This can be combined with union/intersect queries as discussed below 771*4bcd95a3SBarry Smith 772*4bcd95a3SBarry SmithArguments are tricky to search for. Consider 773*4bcd95a3SBarry Smith 774*4bcd95a3SBarry Smith```none 775*4bcd95a3SBarry Smithargs: -ksp_monitor_short -pc_type ml -ksp_max_it 3 776*4bcd95a3SBarry Smith``` 777*4bcd95a3SBarry Smith 778*4bcd95a3SBarry SmithSearch terms are 779*4bcd95a3SBarry Smith 780*4bcd95a3SBarry Smith```none 781*4bcd95a3SBarry Smithksp_monitor, pc_type ml, ksp_max_it 782*4bcd95a3SBarry Smith``` 783*4bcd95a3SBarry Smith 784*4bcd95a3SBarry SmithCertain items are ignored: 785*4bcd95a3SBarry Smith 786*4bcd95a3SBarry Smith- Numbers (see `ksp_max_it` above), but floats are ignored as well. 787*4bcd95a3SBarry Smith- Loops: `args: -pc_fieldsplit_diag_use_amat {{0 1}}` gives `pc_fieldsplit_diag_use_amat` as the search term 788*4bcd95a3SBarry Smith- Input files: `-f *` 789*4bcd95a3SBarry Smith 790*4bcd95a3SBarry SmithExamples of argument searching: 791*4bcd95a3SBarry Smith 792*4bcd95a3SBarry Smith```console 793*4bcd95a3SBarry Smith$ make print-test query='args' queryval='ksp_monitor' 794*4bcd95a3SBarry Smith``` 795*4bcd95a3SBarry Smith 796*4bcd95a3SBarry Smith```console 797*4bcd95a3SBarry Smith$ make print-test query='args' queryval='*monitor*' 798*4bcd95a3SBarry Smith``` 799*4bcd95a3SBarry Smith 800*4bcd95a3SBarry Smith```console 801*4bcd95a3SBarry Smith$ make print-test query='args' queryval='pc_type ml' 802*4bcd95a3SBarry Smith``` 803*4bcd95a3SBarry Smith 804*4bcd95a3SBarry SmithMultiple simultaneous queries can be performed with union (`,`), and intersection 805*4bcd95a3SBarry Smith(`|`) operators in the `query` field. One may also use their alternate spellings 806*4bcd95a3SBarry Smith(`%AND%` and `%OR%` respectively). The alternate spellings are useful in cases where 807*4bcd95a3SBarry Smithone cannot avoid (possibly multiple) shell expansions that might otherwise interpret the 808*4bcd95a3SBarry Smith`|` operator as a shell pipe. Examples: 809*4bcd95a3SBarry Smith 810*4bcd95a3SBarry Smith- All examples using `cuda` and all examples using `hip`: 811*4bcd95a3SBarry Smith 812*4bcd95a3SBarry Smith ```console 813*4bcd95a3SBarry Smith $ make print-test query='requires,requires' queryval='cuda,hip' 814*4bcd95a3SBarry Smith # equivalently 815*4bcd95a3SBarry Smith $ make print-test query='requires%AND%requires' queryval='cuda%AND%hip' 816*4bcd95a3SBarry Smith ``` 817*4bcd95a3SBarry Smith 818*4bcd95a3SBarry Smith- Examples that require both triangle and ctetgen (intersection of tests) 819*4bcd95a3SBarry Smith 820*4bcd95a3SBarry Smith ```console 821*4bcd95a3SBarry Smith $ make print-test query='requires|requires' queryval='ctetgen,triangle' 822*4bcd95a3SBarry Smith # equivalently 823*4bcd95a3SBarry Smith $ make print-test query='requires%OR%requires' queryval='ctetgen%AND%triangle' 824*4bcd95a3SBarry Smith ``` 825*4bcd95a3SBarry Smith 826*4bcd95a3SBarry Smith- Tests that require either `ctetgen` or `triangle` 827*4bcd95a3SBarry Smith 828*4bcd95a3SBarry Smith ```console 829*4bcd95a3SBarry Smith $ make print-test query='requires,requires' queryval='ctetgen,triangle' 830*4bcd95a3SBarry Smith # equivalently 831*4bcd95a3SBarry Smith $ make print-test query='requires%AND%requires' queryval='ctetgen%AND%triangle' 832*4bcd95a3SBarry Smith ``` 833*4bcd95a3SBarry Smith 834*4bcd95a3SBarry Smith- Find `cuda` examples in the `dm` package. 835*4bcd95a3SBarry Smith 836*4bcd95a3SBarry Smith ```console 837*4bcd95a3SBarry Smith $ make print-test query='requires|name' queryval='cuda,dm*' 838*4bcd95a3SBarry Smith # equivalently 839*4bcd95a3SBarry Smith $ make print-test query='requires%OR%name' queryval='cuda%AND%dm*' 840*4bcd95a3SBarry Smith ``` 841*4bcd95a3SBarry Smith 842*4bcd95a3SBarry SmithHere is a way of getting a feel for how the union and intersect operators work: 843*4bcd95a3SBarry Smith 844*4bcd95a3SBarry Smith```console 845*4bcd95a3SBarry Smith$ make print-test query='requires' queryval='ctetgen' | tr ' ' '\n' | wc -l 846*4bcd95a3SBarry Smith170 847*4bcd95a3SBarry Smith$ make print-test query='requires' queryval='triangle' | tr ' ' '\n' | wc -l 848*4bcd95a3SBarry Smith330 849*4bcd95a3SBarry Smith$ make print-test query='requires,requires' queryval='ctetgen,triangle' | tr ' ' '\n' | wc -l 850*4bcd95a3SBarry Smith478 851*4bcd95a3SBarry Smith$ make print-test query='requires|requires' queryval='ctetgen,triangle' | tr ' ' '\n' | wc -l 852*4bcd95a3SBarry Smith22 853*4bcd95a3SBarry Smith``` 854*4bcd95a3SBarry Smith 855*4bcd95a3SBarry SmithThe total number of tests for running only ctetgen or triangle is 500. They have 22 tests in common, and 478 that 856*4bcd95a3SBarry Smithrun independently of each other. 857*4bcd95a3SBarry Smith 858*4bcd95a3SBarry SmithThe union and intersection have fixed grouping. So this string argument 859*4bcd95a3SBarry Smith 860*4bcd95a3SBarry Smith```none 861*4bcd95a3SBarry Smithquery='requires,requires|args' queryval='cuda,hip,*log*' 862*4bcd95a3SBarry Smith# equivalently 863*4bcd95a3SBarry Smithquery='requires%AND%requires%OR%args' queryval='cuda%AND%hip%AND%*log*' 864*4bcd95a3SBarry Smith``` 865*4bcd95a3SBarry Smith 866*4bcd95a3SBarry Smithwill can be read as 867*4bcd95a3SBarry Smith 868*4bcd95a3SBarry Smith```none 869*4bcd95a3SBarry Smithrequires:cuda && (requires:hip || args:*log*) 870*4bcd95a3SBarry Smith``` 871*4bcd95a3SBarry Smith 872*4bcd95a3SBarry Smithwhich is probably not what is intended. 873*4bcd95a3SBarry Smith 874*4bcd95a3SBarry Smith`query/queryval` also support negation (`!`, alternate `%NEG%`), but is limited. 875*4bcd95a3SBarry SmithThe negation only applies to tests that have a related field in it. So for example, the 876*4bcd95a3SBarry Smitharguments of 877*4bcd95a3SBarry Smith 878*4bcd95a3SBarry Smith```console 879*4bcd95a3SBarry Smithquery=requires queryval='!cuda' 880*4bcd95a3SBarry Smith# equivalently 881*4bcd95a3SBarry Smithquery=requires queryval='%NEG%cuda' 882*4bcd95a3SBarry Smith``` 883*4bcd95a3SBarry Smith 884*4bcd95a3SBarry Smithwill only match if they explicitly have: 885*4bcd95a3SBarry Smith 886*4bcd95a3SBarry Smith``` 887*4bcd95a3SBarry Smithrequires: !cuda 888*4bcd95a3SBarry Smith``` 889*4bcd95a3SBarry Smith 890*4bcd95a3SBarry SmithIt does not match all cases that do not require cuda. 891*4bcd95a3SBarry Smith 892*4bcd95a3SBarry Smith### Debugging for loops 893*4bcd95a3SBarry Smith 894*4bcd95a3SBarry SmithOne of the more difficult issues is how to debug for loops when a subset of the 895*4bcd95a3SBarry Smitharguments are the ones that cause a code crash. The default naming scheme is 896*4bcd95a3SBarry Smithnot always helpful for figuring out the argument combination. 897*4bcd95a3SBarry Smith 898*4bcd95a3SBarry SmithFor example: 899*4bcd95a3SBarry Smith 900*4bcd95a3SBarry Smith```console 901*4bcd95a3SBarry Smith$ make test s='src/ksp/ksp/tests/ex9.c' i='*1' 902*4bcd95a3SBarry SmithUsing MAKEFLAGS: i=*1 s=src/ksp/ksp/tests/ex9.c 903*4bcd95a3SBarry Smith TEST arch-osx-pkgs-opt-new/tests/counts/ksp_ksp_tests-ex9_1.counts 904*4bcd95a3SBarry Smith ok ksp_ksp_tests-ex9_1+pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_type-additive 905*4bcd95a3SBarry Smith not ok diff-ksp_ksp_tests-ex9_1+pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_type-additive 906*4bcd95a3SBarry Smith ok ksp_ksp_tests-ex9_1+pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_type-multiplicative 907*4bcd95a3SBarry Smith ... 908*4bcd95a3SBarry Smith``` 909*4bcd95a3SBarry Smith 910*4bcd95a3SBarry SmithIn this case, the trick is to use the verbose option, `V=1` (or for the shell script workflows, `-v`) to have it show the commands: 911*4bcd95a3SBarry Smith 912*4bcd95a3SBarry Smith```console 913*4bcd95a3SBarry Smith$ make test s='src/ksp/ksp/tests/ex9.c' i='*1' V=1 914*4bcd95a3SBarry SmithUsing MAKEFLAGS: V=1 i=*1 s=src/ksp/ksp/tests/ex9.c 915*4bcd95a3SBarry Smitharch-osx-pkgs-opt-new/tests/ksp/ksp/tests/runex9_1.sh -v 916*4bcd95a3SBarry Smith ok ksp_ksp_tests-ex9_1+pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_diag_use_amat-0_pc_fieldsplit_type-additive # mpiexec -n 1 ../ex9 -ksp_converged_reason -ksp_error_if_not_converged -pc_fieldsplit_diag_use_amat 0 -pc_fieldsplit_diag_use_amat 0 -pc_fieldsplit_type additive > ex9_1.tmp 2> runex9_1.err 917*4bcd95a3SBarry Smith... 918*4bcd95a3SBarry Smith``` 919*4bcd95a3SBarry Smith 920*4bcd95a3SBarry SmithThis can still be hard to read and pick out what you want. So use the fact that you want `not ok` 921*4bcd95a3SBarry Smithcombined with the fact that `#` is the delimiter: 922*4bcd95a3SBarry Smith 923*4bcd95a3SBarry Smith```console 924*4bcd95a3SBarry Smith$ make test s='src/ksp/ksp/tests/ex9.c' i='*1' v=1 | grep 'not ok' | cut -d# -f2 925*4bcd95a3SBarry Smithmpiexec -n 1 ../ex9 -ksp_converged_reason -ksp_error_if_not_converged -pc_fieldsplit_diag_use_amat 0 -pc_fieldsplit_diag_use_amat 0 -pc_fieldsplit_type multiplicative > ex9_1.tmp 2> runex9_1.err 926*4bcd95a3SBarry Smith``` 927*4bcd95a3SBarry Smith 928*4bcd95a3SBarry Smith## PETSC Test Harness 929*4bcd95a3SBarry Smith 930*4bcd95a3SBarry SmithThe goals of the PETSc test harness are threefold. 931*4bcd95a3SBarry Smith 932*4bcd95a3SBarry Smith1. Provide standard output used by other testing tools 933*4bcd95a3SBarry Smith2. Be as lightweight as possible and easily fit within the PETSc build chain 934*4bcd95a3SBarry Smith3. Provide information on all tests, even those that are not built or run because they do not meet the configuration requirements 935*4bcd95a3SBarry Smith 936*4bcd95a3SBarry SmithBefore understanding the test harness, you should first understand the 937*4bcd95a3SBarry Smithdesired requirements for reporting and logging. 938*4bcd95a3SBarry Smith 939*4bcd95a3SBarry Smith### Testing the Parsing 940*4bcd95a3SBarry Smith 941*4bcd95a3SBarry SmithAfter inserting the language into the file, you can test the parsing by 942*4bcd95a3SBarry Smithexecuting 943*4bcd95a3SBarry Smith 944*4bcd95a3SBarry SmithA dictionary will be pretty-printed. From this dictionary printout, any 945*4bcd95a3SBarry Smithproblems in the parsing are is usually obvious. This python file is used 946*4bcd95a3SBarry Smithby 947*4bcd95a3SBarry Smith 948*4bcd95a3SBarry Smithin generating the test harness. 949*4bcd95a3SBarry Smith 950*4bcd95a3SBarry Smith## Test Output Standards: TAP 951*4bcd95a3SBarry Smith 952*4bcd95a3SBarry SmithThe PETSc test system is designed to be compliant with the [Test Anything Protocol (TAP)](https://testanything.org/tap-specification.html). 953*4bcd95a3SBarry Smith 954*4bcd95a3SBarry SmithThis is a simple standard designed to allow testing tools to work 955*4bcd95a3SBarry Smithtogether easily. There are libraries to enable the output to be used 956*4bcd95a3SBarry Smitheasily, including sharness, which is used by the Git team. However, the 957*4bcd95a3SBarry Smithsimplicity of the PETSc tests and TAP specification means that we use 958*4bcd95a3SBarry Smithour own simple harness given by a single shell script that each file 959*4bcd95a3SBarry Smithsources: `$PETSC_DIR/config/petsc_harness.sh`. 960*4bcd95a3SBarry Smith 961*4bcd95a3SBarry SmithAs an example, consider this test input: 962*4bcd95a3SBarry Smith 963*4bcd95a3SBarry Smith```yaml 964*4bcd95a3SBarry Smithtest: 965*4bcd95a3SBarry Smith suffix: 2 966*4bcd95a3SBarry Smith output_file: output/ex138.out 967*4bcd95a3SBarry Smith args: -f ${DATAFILESPATH}/matrices/small -mat_type {{aij baij sbaij}} -matload_block_size {{2 3}} 968*4bcd95a3SBarry Smith requires: datafilespath 969*4bcd95a3SBarry Smith``` 970*4bcd95a3SBarry Smith 971*4bcd95a3SBarry SmithA sample output from this would be: 972*4bcd95a3SBarry Smith 973*4bcd95a3SBarry Smith``` 974*4bcd95a3SBarry Smithok 1 In mat...tests: "./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type aij -matload_block_size 2" 975*4bcd95a3SBarry Smithok 2 In mat...tests: "Diff of ./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type aij -matload_block_size 2" 976*4bcd95a3SBarry Smithok 3 In mat...tests: "./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type aij -matload_block_size 3" 977*4bcd95a3SBarry Smithok 4 In mat...tests: "Diff of ./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type aij -matload_block_size 3" 978*4bcd95a3SBarry Smithok 5 In mat...tests: "./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type baij -matload_block_size 2" 979*4bcd95a3SBarry Smithok 6 In mat...tests: "Diff of ./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type baij -matload_block_size 2" 980*4bcd95a3SBarry Smith... 981*4bcd95a3SBarry Smith 982*4bcd95a3SBarry Smithok 11 In mat...tests: "./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type saij -matload_block_size 2" 983*4bcd95a3SBarry Smithok 12 In mat...tests: "Diff of ./ex138 -f ${DATAFILESPATH}/matrices/small -mat_type aij -matload_block_size 2" 984*4bcd95a3SBarry Smith``` 985*4bcd95a3SBarry Smith 986*4bcd95a3SBarry Smith## Test Harness Implementation 987*4bcd95a3SBarry Smith 988*4bcd95a3SBarry SmithMost of the requirements for being TAP-compliant lie in the shell 989*4bcd95a3SBarry Smithscripts, so we focus on that description. 990*4bcd95a3SBarry Smith 991*4bcd95a3SBarry SmithA sample shell script is given the following. 992*4bcd95a3SBarry Smith 993*4bcd95a3SBarry Smith```sh 994*4bcd95a3SBarry Smith#!/bin/sh 995*4bcd95a3SBarry Smith. petsc_harness.sh 996*4bcd95a3SBarry Smith 997*4bcd95a3SBarry Smithpetsc_testrun ./ex1 ex1.tmp ex1.err 998*4bcd95a3SBarry Smithpetsc_testrun 'diff ex1.tmp output/ex1.out' diff-ex1.tmp diff-ex1.err 999*4bcd95a3SBarry Smith 1000*4bcd95a3SBarry Smithpetsc_testend 1001*4bcd95a3SBarry Smith``` 1002*4bcd95a3SBarry Smith 1003*4bcd95a3SBarry Smith`petsc_harness.sh` is a small shell script that provides the logging and reporting 1004*4bcd95a3SBarry Smithfunctions `petsc_testrun` and `petsc_testend`. 1005*4bcd95a3SBarry Smith 1006*4bcd95a3SBarry SmithA small sample of the output from the test harness is as follows. 1007*4bcd95a3SBarry Smith 1008*4bcd95a3SBarry Smith```none 1009*4bcd95a3SBarry Smithok 1 ./ex1 1010*4bcd95a3SBarry Smithok 2 diff ex1.tmp output/ex1.out 1011*4bcd95a3SBarry Smithnot ok 4 ./ex2 1012*4bcd95a3SBarry Smith# ex2: Error: cannot read file 1013*4bcd95a3SBarry Smithnot ok 5 diff ex2.tmp output/ex2.out 1014*4bcd95a3SBarry Smithok 7 ./ex3 -f /matrices/small -mat_type aij -matload_block_size 2 1015*4bcd95a3SBarry Smithok 8 diff ex3.tmp output/ex3.out 1016*4bcd95a3SBarry Smithok 9 ./ex3 -f /matrices/small -mat_type aij -matload_block_size 3 1017*4bcd95a3SBarry Smithok 10 diff ex3.tmp output/ex3.out 1018*4bcd95a3SBarry Smithok 11 ./ex3 -f /matrices/small -mat_type baij -matload_block_size 2 1019*4bcd95a3SBarry Smithok 12 diff ex3.tmp output/ex3.out 1020*4bcd95a3SBarry Smithok 13 ./ex3 -f /matrices/small -mat_type baij -matload_block_size 3 1021*4bcd95a3SBarry Smithok 14 diff ex3.tmp output/ex3.out 1022*4bcd95a3SBarry Smithok 15 ./ex3 -f /matrices/small -mat_type sbaij -matload_block_size 2 1023*4bcd95a3SBarry Smithok 16 diff ex3.tmp output/ex3.out 1024*4bcd95a3SBarry Smithok 17 ./ex3 -f /matrices/small -mat_type sbaij -matload_block_size 3 1025*4bcd95a3SBarry Smithok 18 diff ex3.tmp output/ex3.out 1026*4bcd95a3SBarry Smith# FAILED 4 5 1027*4bcd95a3SBarry Smith# failed 2/16 tests; 87.500% ok 1028*4bcd95a3SBarry Smith``` 1029*4bcd95a3SBarry Smith 1030*4bcd95a3SBarry SmithFor developers, modifying the lines that get written to the file can be 1031*4bcd95a3SBarry Smithdone by modifying `$PETSC_DIR/config/example_template.py`. 1032*4bcd95a3SBarry Smith 1033*4bcd95a3SBarry SmithTo modify the test harness, you can modify `$PETSC_DIR/config/petsc_harness.sh`. 1034*4bcd95a3SBarry Smith 1035*4bcd95a3SBarry Smith### Additional Tips 1036*4bcd95a3SBarry Smith 1037*4bcd95a3SBarry SmithTo rerun just the reporting use 1038*4bcd95a3SBarry Smith 1039*4bcd95a3SBarry Smith```console 1040*4bcd95a3SBarry Smith$ config/report_tests.py 1041*4bcd95a3SBarry Smith``` 1042*4bcd95a3SBarry Smith 1043*4bcd95a3SBarry SmithTo see the full options use 1044*4bcd95a3SBarry Smith 1045*4bcd95a3SBarry Smith```console 1046*4bcd95a3SBarry Smith$ config/report_tests.py -h 1047*4bcd95a3SBarry Smith``` 1048*4bcd95a3SBarry Smith 1049*4bcd95a3SBarry SmithTo see the full timing information for the five most expensive tests use 1050*4bcd95a3SBarry Smith 1051*4bcd95a3SBarry Smith```console 1052*4bcd95a3SBarry Smith$ config/report_tests.py -t 5 1053*4bcd95a3SBarry Smith``` 1054