xref: /petsc/src/sys/tests/ex2.c (revision df4cd43f92eaa320656440c40edb1046daee8f75)
1 
2 static char help[] = "Tests the signal handler.\n";
3 
4 #include <petscsys.h>
5 
6 PetscErrorCode CreateError(int n)
7 {
8   if (n) {
9     PetscCall(CreateError(n - 1));
10   } else {
11     volatile PetscReal *x = 0;
12     x[0]                  = 100.;
13   }
14   return PETSC_SUCCESS;
15 }
16 
17 int main(int argc, char **argv)
18 {
19   PetscFunctionBeginUser;
20   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
21   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates how PETSc can trap error interrupts\n"));
22   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error below is contrived to test the code!\n"));
23   PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
24   PetscCall(CreateError(5));
25   PetscCall(PetscFinalize());
26   return 0;
27 }
28 
29 /*TEST
30 
31    test:
32      args: -error_output_stdout
33      filter: grep -E "(Caught signal number 11 SEGV|Caught signal number 4 Illegal)" | wc -l
34      TODO:  Does not always produce exactly expected output on all systems for all runs
35 
36 TEST*/
37