Actual source code: ex68.c
1: static const char help[] = "Tests vector lock locations with deep call and lock stacks.\n\n";
3: #include <petscvec.h>
5: static PetscErrorCode CheckVectorLocks(Vec x, int remaining)
6: {
7: const char *file, *function;
8: int line;
10: PetscFunctionBeginUser;
11: PetscCall(VecLockReadPush(x));
12: for (int i = 0; i < 2; ++i) {
13: PetscCall(VecLockGetLocation(x, &file, &function, &line));
14: PetscCheck(file && function, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Missing lock location");
15: if (petscstack.currentsize > PETSCSTACKSIZE) {
16: char *match;
18: PetscCall(PetscStrstr(file, "stack depth exceeds PETSCSTACKSIZE=", &match));
19: PetscCheck(match && !line, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Missing lock stack truncation diagnostic");
20: } else {
21: PetscBool filematch, functionmatch;
23: PetscCall(PetscStrcmp(file, __FILE__, &filematch));
24: PetscCall(PetscStrcmp(function, PETSC_FUNCTION_NAME, &functionmatch));
25: PetscCheck(filematch && functionmatch && line > 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Incorrect lock location");
26: }
27: if (!i && remaining) PetscCall(CheckVectorLocks(x, remaining - 1));
28: }
29: PetscCall(VecLockReadPop(x));
30: PetscFunctionReturn(PETSC_SUCCESS);
31: }
33: int main(int argc, char **argv)
34: {
35: Vec x;
36: const char *file, *function;
37: int line;
39: PetscFunctionBeginUser;
40: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
41: PetscCall(VecCreateSeq(PETSC_COMM_SELF, 1, &x));
42: PetscCall(CheckVectorLocks(x, 2 * PETSCSTACKSIZE));
43: PetscCall(VecLockGetLocation(x, &file, &function, &line));
44: PetscCheck(!file && !function && !line, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Lock stack was not restored");
45: PetscCall(VecDestroy(&x));
46: PetscCall(PetscFinalize());
47: return 0;
48: }
50: /*TEST
52: build:
53: requires: debug
55: test:
56: args: -checkstack {{0 1}}
57: output_file: output/empty.out
59: TEST*/