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