GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_cleanup_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 1 1 100.0%
Branches: 17 30 56.7%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2022 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #include "unique_shmem.h"
21 #include "test_process.h"
22
23 #include "LB_comm/shmem.h"
24 #include "LB_comm/shmem_async.h"
25 #include "LB_comm/shmem_barrier.h"
26 #include "LB_comm/shmem_cpuinfo.h"
27 #include "LB_comm/shmem_lewi_light.h"
28 #include "LB_comm/shmem_procinfo.h"
29 #include "support/mask_utils.h"
30 #include "apis/dlb_errors.h"
31
32 #include <stdbool.h>
33 #include <sched.h>
34 #include <unistd.h>
35 #include <sys/wait.h>
36
37
38 1 int main(int argc, char *argv[]) {
39
40 enum { SHMEM_SIZE_MULTIPLIER = 1 };
41
42 pid_t pid;
43 cpu_set_t process_mask;
44 1 mu_parse_mask("0", &process_mask);
45
46 /* Child 1 registers and dies */
47 1 pid = fork();
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( pid >= 0 );
49
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (pid == 0) {
50 1 pid_t child_pid = getpid();
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(child_pid, 0, &process_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(child_pid, 0, &process_mask, NULL, SHMEM_KEY,
53 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_init(child_pid, NULL, &process_mask, SHMEM_KEY, 1) == DLB_SUCCESS );
55 1 shmem_barrier__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER);
56 1 shmem_barrier__register("barrier", 0);
57 1 shmem_lewi_light__init(1, 0, SHMEM_KEY);
58
59 /* Invoke _exit so that call assert_shmem destructors are not called */
60 1 dlb_test__exit(EXIT_SUCCESS);
61 }
62 1 waitpid(pid, NULL, 0);
63
64 /* Child 1 is dead, new child registers with the same mask */
65 1 pid = fork();
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( pid >= 0 );
67
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (pid == 0) {
68 1 pid_t child_pid = getpid();
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(child_pid, 0, &process_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(child_pid, 0, &process_mask, NULL, SHMEM_KEY,
71 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_init(child_pid, NULL, &process_mask, SHMEM_KEY, 1) == DLB_SUCCESS );
73 1 shmem_barrier__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER);
74 1 barrier_t *barrier = shmem_barrier__register("barrier", 0);
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( barrier != NULL );
76 1 shmem_lewi_light__init(1, 0, SHMEM_KEY);
77
78 /* Barrier must not block because I'm the only participant */
79 1 shmem_barrier__barrier(barrier);
80
81
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(child_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
82
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(child_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
83 == DLB_SUCCESS );
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_finalize(child_pid) == DLB_SUCCESS );
85
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_barrier__detach(barrier) == 0 );
86 1 shmem_barrier__finalize(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER);
87 1 shmem_lewi_light__finalize();
88
89 1 exit(EXIT_SUCCESS);
90 }
91 1 waitpid(pid, NULL, 0);
92
93 1 return 0;
94 }
95