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