GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/procinfo_04.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 1 1 100.0%
Branches: 16 30 53.3%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2024 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_procinfo.h"
23 #include "apis/dlb_errors.h"
24 #include "apis/dlb_types.h"
25 #include "support/mask_utils.h"
26
27 #include <sched.h>
28 #include <string.h>
29 #include <assert.h>
30
31 // PreInit tests of two applications overlapping resources
32 // APP1: ============X
33 // ============X
34 // ====|
35 // ====|
36 // APP2: ================X
37 // ================X
38 // ====X
39 // ====X
40
41 1 int main( int argc, char **argv ) {
42
43 enum { SHMEM_SIZE_MULTIPLIER = 1 };
44
45 // This test needs at least room for 4 CPUs
46 enum { SYS_SIZE = 4 };
47 enum { MASK_SIZE = sizeof(unsigned long) };
48 1 mu_init();
49 1 mu_testing_set_sys_size(SYS_SIZE);
50
51 1 const cpu_set_t original_p1_mask = { .__bits = {0xf} }; /* [1111] */
52 1 const cpu_set_t original_p2_mask = { .__bits = {0xc} }; /* [1100] */
53
54 1 dlb_drom_flags_t no_flags = DLB_DROM_FLAGS_NONE;
55
56 // Initialize external
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
58
59 // Pre-Initialize sub-process 1
60 1 pid_t p1_preinit_pid = 11;
61 cpu_set_t p1_mask;
62 1 memcpy(&p1_mask, &original_p1_mask, sizeof(cpu_set_t));
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__preinit(p1_preinit_pid, &p1_mask, no_flags) == DLB_SUCCESS );
64
65 // Pre-Initialize sub-process 2
66 1 pid_t p2_preinit_pid = 22;
67 cpu_set_t p2_mask;
68 1 memcpy(&p2_mask, &original_p2_mask, sizeof(cpu_set_t));
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__preinit(p2_preinit_pid, &p2_mask, DLB_STEAL_CPUS) == DLB_SUCCESS );
70
71 // Initialize sub-process 2
72 1 pid_t p2_pid = 222;
73 1 CPU_ZERO(&p2_mask);
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(p2_pid, p2_preinit_pid, NULL, &p2_mask, SHMEM_KEY,
75 SHMEM_SIZE_MULTIPLIER) == DLB_NOTED );
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL_S(MASK_SIZE, &original_p2_mask, &p2_mask) );
77
78 // Initialize sub-process 1
79 1 pid_t p1_pid = 111;
80 1 CPU_ZERO(&p1_mask);
81
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(p1_pid, p1_preinit_pid, NULL, &p1_mask, SHMEM_KEY,
82 SHMEM_SIZE_MULTIPLIER) == DLB_NOTED );
83 cpu_set_t p1_mask_after;
84 /* P1 needs to readjust its mask: [1111] - [1100] = [0011] */
85 1 mu_subtract(&p1_mask_after, &original_p1_mask, &original_p2_mask);
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL_S(MASK_SIZE, &p1_mask_after, &p1_mask) );
87
88 // Finalize sub-process 1
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(p1_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
90 == DLB_SUCCESS );
91
92 // Assign all CPUs to sub-process 2
93 cpu_set_t new_p2_mask;
94
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
17 CPU_OR(&new_p2_mask, &original_p1_mask, &original_p2_mask);
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__setprocessmask(p2_pid, &new_p2_mask, no_flags, NULL) == DLB_SUCCESS );
96
97 // Sub-process 2 polls
98 1 int ncpus = 0;
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__polldrom(p2_pid, &ncpus, &p2_mask) == DLB_SUCCESS );
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( ncpus == CPU_COUNT_S(MASK_SIZE, &new_p2_mask) );
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL_S(MASK_SIZE, &new_p2_mask, &p2_mask) );
102
103 // Finalize sub-process 2
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER)
105 == DLB_SUCCESS );
106
107 // Finalize external
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__finalize() == DLB_SUCCESS );
109
110 1 mu_finalize();
111
112 1 return 0;
113 }
114