GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/procinfo_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 47 47 100.0%
Functions: 1 1 100.0%
Branches: 37 74 50.0%

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 #include "unique_shmem.h"
21
22 #include "LB_comm/shmem.h"
23 #include "LB_comm/shmem_procinfo.h"
24 #include "apis/dlb_errors.h"
25 #include "apis/dlb_types.h"
26 #include "support/mask_utils.h"
27
28 #include <sched.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <assert.h>
33
34 // Basic checks with 1 sub-process
35
36 1 int main( int argc, char **argv ) {
37
38 enum { SHMEM_SIZE_MULTIPLIER = 1 };
39
40 1 int new_threads = 0;
41 1 pid_t pid = getpid();
42 cpu_set_t process_mask, new_mask;
43 1 sched_getaffinity(0, sizeof(cpu_set_t), &process_mask);
44
45 // Check shmem not initialized
46
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__getprocessmask(pid, NULL, DLB_SYNC_QUERY) == DLB_ERR_NOSHMEM );
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__polldrom(pid, NULL, NULL) == DLB_ERR_NOSHMEM );
48
49 // Init
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CPU_CLR(mu_get_system_size(), &process_mask);
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(pid, 0, &process_mask, NULL, SHMEM_KEY,
52 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
53 // A second init for the same pid should fail
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(pid, 0, &process_mask, NULL, SHMEM_KEY,
55 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_INIT );
56
57 // Check registered mask is the same as our process mask
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__getprocessmask(pid, &new_mask, DLB_SYNC_QUERY) == DLB_SUCCESS );
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL(&process_mask, &new_mask) );
60
61 // process mask should not be dirty
62
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__polldrom(pid, &new_threads, NULL) == DLB_NOUPDT );
63
64 // Check unknown pid
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__getprocessmask(pid+1, NULL, DLB_SYNC_QUERY) == DLB_ERR_NOPROC );
66
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__polldrom(pid+1, NULL, NULL) == DLB_ERR_NOPROC );
67
68 // Check shmem cannot be inherited by another pid, since it's not flagged as preregistered
69 1 pid_t new_pid = pid+1;
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(new_pid, pid, &process_mask, NULL, SHMEM_KEY,
71 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_INIT );
72
73 // Finalize
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
75 == DLB_SUCCESS );
76 // A second finalize should return error
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
78 == DLB_ERR_NOSHMEM );
79
80 // Test init with an empty mask
81 1 CPU_ZERO(&process_mask);
82
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(pid, 0, &process_mask, NULL, SHMEM_KEY,
83 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
84 1 shmem_procinfo__print_info(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER);
85
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
86 == DLB_SUCCESS );
87
88 // Test init sharing CPUs
89 1 sched_getaffinity(0, sizeof(cpu_set_t), &process_mask);
90
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init_with_cpu_sharing(111, 0, &process_mask, SHMEM_KEY,
91 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init_with_cpu_sharing(222, 0, &process_mask, SHMEM_KEY,
93 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__getprocessmask(111, &new_mask, DLB_SYNC_QUERY) == DLB_SUCCESS );
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL(&process_mask, &new_mask) );
96
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__getprocessmask(222, &new_mask, DLB_SYNC_QUERY) == DLB_SUCCESS );
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL(&process_mask, &new_mask) );
98
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(111, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
99 == DLB_SUCCESS );
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(222, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
101 == DLB_SUCCESS );
102 // Subsequent "regular inits" with shared masks should still fail
103
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(111, 0, &process_mask, NULL, SHMEM_KEY,
104 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
105
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(222, 0, &process_mask, NULL, SHMEM_KEY,
106 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_PERM );
107 // Mixed "inits" will fail
108 1 cpu_set_t empty_mask = {};
109
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init_with_cpu_sharing(333, 0, &empty_mask, SHMEM_KEY,
110 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_NOCOMP );
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(111, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
112 == DLB_SUCCESS );
113 // Flag not decided if initializing from ext__init (no cpu sharing first)
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(111, 0, &process_mask, NULL, SHMEM_KEY,
116 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init_with_cpu_sharing(222, 0, &process_mask, SHMEM_KEY,
118 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_NOCOMP );
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(111, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
120 == DLB_SUCCESS );
121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__finalize() == DLB_SUCCESS );
122 // Flag not decided if initializing from ext__init (with cpu sharing first)
123
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init_with_cpu_sharing(111, 0, &process_mask, SHMEM_KEY,
125 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
126
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(222, 0, &process_mask, NULL, SHMEM_KEY,
127 SHMEM_SIZE_MULTIPLIER) == DLB_ERR_NOCOMP );
128
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(111, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
129 == DLB_SUCCESS );
130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__finalize() == DLB_SUCCESS );
131
132 1 return 0;
133 }
134