GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/cpuinfo_get_binding_00.c
Date: 2026-11-30 15:03:27
Exec Total Coverage
Lines: 60 60 100.0%
Functions: 1 1 100.0%
Branches: 43 86 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_cpuinfo.h"
23 #include "apis/dlb_errors.h"
24 #include "support/mask_utils.h"
25
26 #include <assert.h>
27
28 /* Thread binding tests involving CPU ownership changes */
29
30 1 int main(int argc, char *argv[]) {
31 // This test needs at least room for 4 CPUs
32 enum { SYS_SIZE = 4 };
33 1 mu_init();
34 1 mu_testing_set_sys_size(SYS_SIZE);
35
36 // Initialize local masks to [1100] and [0011]
37 1 pid_t p1_pid = 111;
38 cpu_set_t p1_mask;
39 1 CPU_ZERO(&p1_mask);
40
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(0, &p1_mask);
41
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(1, &p1_mask);
42 1 pid_t p2_pid = 222;
43 cpu_set_t p2_mask;
44 1 CPU_ZERO(&p2_mask);
45
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(2, &p2_mask);
46
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(3, &p2_mask);
47
48 // Init P1
49
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
50
51 // P1 temporarily acquires CPUs 2 and 3
52
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(2, &p1_mask);
53
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(3, &p1_mask);
54 1 shmem_cpuinfo__update_ownership(p1_pid, &p1_mask, NULL);
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 0) == 0 );
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 1) == 1 );
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 2) == 2 );
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 3) == 3 );
59
60 // Reduce p1 mask to its original
61
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(2, &p1_mask);
62
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(3, &p1_mask);
63 1 shmem_cpuinfo__update_ownership(p1_pid, &p1_mask, NULL);
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 0) == 0 );
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 1) == 1 );
66
67 // Init P2
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p2_pid, 0, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 2 );
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 1) == 3 );
71
72 // Reduce p2 mask (thread 1)
73
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(3, &p2_mask);
74 1 shmem_cpuinfo__update_ownership(p2_pid, &p2_mask, NULL);
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 2 );
76
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 1) == -1 );
77
78 // Restore p2 mask
79
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(3, &p2_mask);
80 1 shmem_cpuinfo__update_ownership(p2_pid, &p2_mask, NULL);
81
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 2 );
82
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 1) == 3 );
83
84 // Reduce p2 mask (thread 0, needs reassigning)
85
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(2, &p2_mask);
86 1 shmem_cpuinfo__update_ownership(p2_pid, &p2_mask, NULL);
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 3 );
88
89 // P1 acquires CPU 2
90
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(2, &p1_mask);
91 1 shmem_cpuinfo__update_ownership(p1_pid, &p1_mask, NULL);
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 0) == 0 );
93
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 1) == 1 );
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 2) == 2 );
95
96 // Reduce p1 mask
97
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(1, &p1_mask);
98
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_CLR(2, &p1_mask);
99 1 shmem_cpuinfo__update_ownership(p1_pid, &p1_mask, NULL);
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 0) == 0 );
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 1) == -1 );
102
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p1_pid, 2) == -1 );
103
104 // P2 bind check
105
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 3 );
106
107 // P2 acquires CPUs 1 and 2
108
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(1, &p2_mask);
109
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 CPU_SET(2, &p2_mask);
110 1 shmem_cpuinfo__update_ownership(p2_pid, &p2_mask, NULL);
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 0) == 1 );
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 1) == 2 );
113
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__get_thread_binding(p2_pid, 2) == 3 );
114
115 // Finalize
116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
118
119 1 mu_finalize();
120
121 1 return 0;
122 }
123