xref: /petsc/src/sys/tests/ex1.c (revision ca0d62ff0b92f3b3ec10dd93d500c979243edb4e)
1 
2 static char help[] = "Demonstrates PETSc error handlers.\n";
3 
4 #include <petscsys.h>
5 
6 PetscErrorCode CreateError(int n)
7 {
8   PetscCheck(n, PETSC_COMM_WORLD, PETSC_ERR_USER, "Error Created");
9   PetscCall(CreateError(n - 1));
10   return PETSC_SUCCESS;
11 }
12 
13 int main(int argc, char **argv)
14 {
15   PetscFunctionBeginUser;
16   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
17   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates PETSc Error Handlers\n"));
18   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error is a contrived error to test error handling\n"));
19   PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
20   PetscCall(CreateError(5));
21   PetscCall(PetscFinalize());
22   return 0;
23 }
24 
25 /*TEST
26 
27  # Testing errors so only look for errors
28    test:
29      requires: !defined(PETSCTEST_VALGRIND)
30      args: -petsc_ci_portable_error_output -error_output_stdout
31      nsize: {{1 2 3}}
32      filter: grep -E "(PETSC ERROR)" | egrep "(Error Created|CreateError\(\)|main\(\))"
33 
34 TEST*/
35