Actual source code: ex2.c

  1: static char help[] = "Tests the signal handler.\n";

  3: #include <petscsys.h>

  5: PetscErrorCode CreateError(int n)
  6: {
  7:   if (n) {
  8:     PetscCall(CreateError(n - 1));
  9:   } else {
 10:     volatile PetscReal *x = 0;
 11:     x[0]                  = 100.;
 12:   }
 13:   return PETSC_SUCCESS;
 14: }

 16: int main(int argc, char **argv)
 17: {
 18:   PetscFunctionBeginUser;
 19:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 20:   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates how PETSc can trap error interrupts\n"));
 21:   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error below is contrived to test the code!\n"));
 22:   PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
 23:   PetscCall(CreateError(5));
 24:   PetscCall(PetscFinalize());
 25:   return 0;
 26: }

 28: /*TEST

 30:    test:
 31:      args: -error_output_stdout
 32:      filter: grep -E "(Caught signal number 11 SEGV|Caught signal number 4 Illegal)" | wc -l
 33:      TODO:  Does not always produce exactly expected output on all systems for all runs

 35: TEST*/