GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_abort_01.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 28 29 96.6%
Functions: 1 1 100.0%
Branches: 12 22 54.5%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2021 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 /* Test that shared memories are cleaned when the process aborts, even if the
21 * process has initialized multiple subprocesses.
22 * The fork is necessary to call the assert_noshm in the destructor
23 */
24
25 #include "unique_shmem.h"
26 #include "test_process.h"
27
28 #include "LB_comm/shmem_async.h"
29 #include "LB_comm/shmem_cpuinfo.h"
30 #include "LB_comm/shmem_procinfo.h"
31 #include "LB_core/spd.h"
32 #include "support/debug.h"
33 #include "support/options.h"
34 #include "support/mask_utils.h"
35 #include "apis/dlb_errors.h"
36
37 #include <sched.h>
38 #include <unistd.h>
39 #include <assert.h>
40 #include <signal.h>
41 #include <sys/wait.h>
42
43 1 int main(int argc, char **argv) {
44
45 enum { SHMEM_SIZE_MULTIPLIER = 1 };
46
47 // Create a child process
48 1 pid_t pid = fork();
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( pid >= 0 );
50
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (pid == 0) {
51
52 enum { SYS_SIZE = 4 };
53 1 mu_testing_set_sys_size(SYS_SIZE);
54
55 /* spd1 */
56 subprocess_descriptor_t spd1;
57 1 spd1.id = 111;
58 1 mu_parse_mask("0", &spd1.process_mask);
59 1 spd_register(&spd1);
60
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(spd1.id, 0, &spd1.process_mask, SHMEM_KEY, 0)
61 == DLB_SUCCESS );
62
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(spd1.id, 0, &spd1.process_mask, NULL, SHMEM_KEY,
63 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_init(spd1.id, NULL, &spd1.process_mask, SHMEM_KEY, 1)
65 == DLB_SUCCESS );
66
67 /* spd2 */
68 subprocess_descriptor_t spd2;
69 1 spd2.id = 222;
70 1 mu_parse_mask("1", &spd2.process_mask);
71 1 spd_register(&spd2);
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(spd2.id, 0, &spd2.process_mask, SHMEM_KEY, 0)
73 == DLB_SUCCESS );
74
75 /* spd3 */
76 subprocess_descriptor_t spd3;
77 1 spd3.id = 333;
78 1 mu_parse_mask("2", &spd3.process_mask);
79 1 spd_register(&spd3);
80
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(spd3.id, 0, &spd3.process_mask, SHMEM_KEY, 0)
81 == DLB_SUCCESS );
82
83 /* spd4 */
84 subprocess_descriptor_t spd4;
85 1 spd4.id = 444;
86 1 mu_parse_mask("3", &spd4.process_mask);
87 1 spd_register(&spd4);
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(spd4.id, 0, &spd4.process_mask, SHMEM_KEY, 0)
89 == DLB_SUCCESS );
90
91 1 dlb_test__gcov_dump();
92
93 ✗ fatal("This fatal should clean shmems");
94 }
95
96 // Wait child and end execution correctly in order to call destructors
97 int wstatus;
98
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( waitpid(pid, &wstatus, 0) > 0 );
99
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGABRT );
100
101 1 mu_finalize();
102
103 1 return 0;
104 }
105