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