1 2 static char help[] = "Tests the signal handler.\n"; 3 4 #include <petscsys.h> 5 6 int CreateError(int n) { 7 PetscReal *x = 0; 8 if (!n) { 9 x[0] = 100.; 10 return 0; 11 } 12 PetscCall(CreateError(n - 1)); 13 return 0; 14 } 15 16 int main(int argc, char **argv) { 17 PetscFunctionBeginUser; 18 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 19 PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates how PETSc can trap error interrupts\n")); 20 PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error below is contrived to test the code!\n")); 21 PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT)); 22 PetscCall(CreateError(5)); 23 PetscCall(PetscFinalize()); 24 return 0; 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