GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_lewi_async_01.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 320 320 100.0%
Functions: 1 1 100.0%
Branches: 296 590 50.2%

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 // LeWI_async checks with 2+ sub-processes
21
22 #include "unique_shmem.h"
23
24 #include "LB_comm/shmem_lewi_async.h"
25 #include "apis/dlb_errors.h"
26 #include "apis/dlb_types.h"
27 #include "support/mask_utils.h"
28
29 #include <stdlib.h>
30 #include <sys/types.h>
31
32 1 int main(int argc, char *argv[]) {
33
34 enum { SHMEM_SIZE_MULTIPLIER = 1 };
35
36 // This test needs at least room for 4 CPUs
37 enum { SYS_SIZE = 4 };
38 1 mu_init();
39 1 mu_testing_set_sys_size(SYS_SIZE);
40
41 1 pid_t p1_pid = 111;
42 1 unsigned int p1_initial_ncpus = 2;
43 1 pid_t p2_pid = 222;
44 1 unsigned int p2_initial_ncpus = 2;
45
46 unsigned int p1_prev_requested;
47 unsigned int p2_prev_requested;
48 unsigned int p3_prev_requested;
49
50 unsigned int new_ncpus;
51 unsigned int nreqs;
52 1 int max_requests = SYS_SIZE;
53 1 lewi_request_t *requests = malloc(sizeof(lewi_request_t*)*max_requests);
54
55 // Init
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
57 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
59 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
60
61 /*** Successful ping-pong ***/
62 {
63 // Process 1 wants 1 CPU
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 1, &new_ncpus, requests,
65 &nreqs, max_requests) == DLB_NOTED );
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
68
69 // Process 2 lends 1 CPU (P1 gets it)
70 1 new_ncpus = p2_initial_ncpus - 1;
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
72 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
74
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 3 );
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
76
77 // Process 2 reclaims its CPU (P1 is notified to remove one)
78
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(p2_pid, &new_ncpus, requests,
79 &nreqs, max_requests, p2_prev_requested) == DLB_SUCCESS );
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
82
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 2 );
83
84 // Process 2 lends 1 CPU again (P1 still gets it)
85
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p2_pid, 1, &new_ncpus, requests,
86 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus - 1 );
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
89
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 3 );
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
91
92 // Process 2 reclaims its CPU again (P1 sacrifices again)
93
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(p2_pid, &new_ncpus, requests,
94 &nreqs, max_requests, p2_prev_requested) == DLB_SUCCESS );
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
97
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 2 );
98
99 // Process 1 removes petition of 1 CPU
100 1 shmem_lewi_async__remove_requests(p1_pid);
101
102 // Process 2 lends 1 CPU again, P1 petition does not exist anymore
103 1 new_ncpus = p2_initial_ncpus - 1;
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
105 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
108
109 // Process 2 reclaims its CPU again
110
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(p2_pid, &new_ncpus, requests,
111 &nreqs, max_requests, p2_prev_requested) == DLB_SUCCESS );
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
114 }
115
116 /*** Return acquired CPUs using Lend, request is not renewed ***/
117 {
118 // Process 1 wants 1 CPU
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 1, &new_ncpus, requests,
120 &nreqs, max_requests) == DLB_NOTED );
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
123
124 // Process 2 lends 1 CPU (P1 gets it)
125 1 new_ncpus = p2_initial_ncpus - 1;
126
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
127 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
129
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 3 );
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
131
132 // Process 1 lends 1 CPU (no one gets it)
133
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p1_pid, 1, &new_ncpus, requests,
134 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 1 );
138
139 // Process 2 lends 1 more CPU, P1 petition does not exist anymore
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p2_pid, 1, &new_ncpus, requests,
141 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus - 2 );
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
145
146 // Reset using borrows (because no reason)
147
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__borrow_cpus(p2_pid, p2_initial_ncpus,
148 &new_ncpus) == DLB_SUCCESS );
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
150 }
151
152 /*** Reclaim partial CPUs ***/
153 {
154 // Process 1 lends 2 CPUs
155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p1_pid, 2, &new_ncpus, requests,
156 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus - 2 );
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
160
161 // Process 2 wants 10 CPUs, only gets 2
162
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p2_pid, 10, &new_ncpus, requests,
163 &nreqs, max_requests) == DLB_NOTED );
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus + 2 );
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
166
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 8 );
167
168 // loop 20 times to reclaim 1 and then lend it again to check queue is not reset
169
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 for (int i=0; i<20; ++i) {
170
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 assert( shmem_lewi_async__acquire_cpus(p1_pid, 1, &new_ncpus,
171 requests, &nreqs, max_requests) == DLB_SUCCESS );
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 assert( new_ncpus == 1 );
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 assert( nreqs == 1 );
174
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 assert( requests[0].pid == p2_pid && requests[0].howmany == 3 );
175
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 assert( shmem_lewi_async__lend_cpus(p1_pid, 1, &new_ncpus, requests,
176 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 assert( new_ncpus == 0 );
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 assert( nreqs == 1 );
179
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 assert( requests[0].pid == p2_pid && requests[0].howmany == 4 );
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 assert( p1_prev_requested == 0 );
181 }
182
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 8 );
183
184 // Process 1 gets its initial CPUs
185
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, p1_initial_ncpus,
186 &new_ncpus, requests, &nreqs, max_requests) == DLB_SUCCESS );
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
189
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p2_pid && requests[0].howmany == p2_initial_ncpus );
190
191 // Process 2 removes requests
192 1 shmem_lewi_async__remove_requests(p2_pid);
193 }
194
195 /*** Reset ***/
196 {
197 // Process 1 resets (no-op)
198
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p1_pid, &new_ncpus, requests,
199 &nreqs, max_requests, &p1_prev_requested) == DLB_NOUPDT );
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
201
202 // Process 1 wants 2 CPUs
203
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 2, &new_ncpus, requests,
204 &nreqs, max_requests) == DLB_NOTED );
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
207
208 // Process 2 lends 1 CPU (P1 gets it)
209 1 new_ncpus = p2_initial_ncpus - 1;
210
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
211 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
213
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 3 );
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
215
216 // Process 1 resets
217
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p1_pid, &new_ncpus, requests,
218 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 2 );
222
223 // Process 2 lends 1 more CPU (no one gets it)
224
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p2_pid, 1, &new_ncpus, requests,
225 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 0 );
227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
228
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
229
230 // Process 2 resets
231
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p2_pid, &new_ncpus, requests,
232 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
236
237 // Process 1 wants 2 CPUs
238
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 2, &new_ncpus, requests,
239 &nreqs, max_requests) == DLB_NOTED );
240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
242
243 // Process 2 lends 2 CPUs again (P1 gets them)
244
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p2_pid, 2, &new_ncpus, requests,
245 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 0 );
247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
248
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 4 );
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
250
251 // Process 2 resets, causing a reclaim
252
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p2_pid, &new_ncpus, requests,
253 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
256
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 2 );
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
258
259 // Process 1 removes petition
260 1 shmem_lewi_async__remove_requests(p1_pid);
261 }
262
263 // Finalize
264 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
267 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
270
271 /* Re-init and finalize with CPUs lent */
272 {
273 // Init
274
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
275 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
276
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
277 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
278
279 // Process 2 lends 1 CPU
280 1 new_ncpus = p2_initial_ncpus - 1;
281
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
282 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
285
286 // Process 2 finalizes
287 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
290
291 // Process 1 wants 1 CPU (no CPU available)
292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 2, &new_ncpus, requests,
293 &nreqs, max_requests) == DLB_NOTED );
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
296
297 // Process 1 finalizes
298 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
301 }
302
303 /* Re-init and finalize with CPUs acquired */
304 {
305 // Init
306
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
307 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
308
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
309 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
310
311 // Process 2 lends 1 CPU
312 1 new_ncpus = p2_initial_ncpus - 1;
313
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
314 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
317
318 // Process 1 gets 1 CPU
319
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 1, &new_ncpus, requests,
320 &nreqs, max_requests) == DLB_SUCCESS );
321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus + 1 );
322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
323
324 // Process 2 finalizes
325 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
328
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == p2_initial_ncpus );
329
330 // Process 1 finalizes
331 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
334 }
335
336 /* Re-init and finalize with pending requests */
337 {
338 // Init
339
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
340 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
341
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
342 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
343
344 // Process 1 wants 2 CPUs
345
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 2, &new_ncpus, requests,
346 &nreqs, max_requests) == DLB_NOTED );
347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
349
350 // Process 1 finalizes
351 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
354
355 // Process 2 finalizes
356 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
359 }
360
361 /* Re-init and finalize with acquired external CPUs */
362 {
363 // Init
364
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
365 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
366
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
367 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
368
369 // Process 1 wants 2 CPUs
370
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 2, &new_ncpus, requests,
371 &nreqs, max_requests) == DLB_NOTED );
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
374
375 // Process 2 lends 1 CPU (P1 gets it)
376 1 new_ncpus = p2_initial_ncpus - 1;
377
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p2_pid, new_ncpus, requests,
378 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
380
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 3 );
381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
382
383 // Process 1 finalizes
384 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
387
388 // Process 2 finalizes
389 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
392 }
393
394 /* Re-init with more processes, test even distribution when reclaiming */
395 {
396 enum { NEW_SYS_SIZE = 64 };
397 1 mu_testing_set_sys_size(NEW_SYS_SIZE);
398
399 1 p1_initial_ncpus = 16;
400 1 p2_initial_ncpus = 16;
401 1 pid_t p3_pid = 333;
402 1 unsigned int p3_initial_ncpus = 16;
403 1 pid_t p4_pid = 444;
404 1 unsigned int p4_initial_ncpus = 16;
405
406 // Init
407
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
408 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
409
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
410 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
411
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p3_pid, p3_initial_ncpus, SHMEM_KEY,
412 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
413
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p4_pid, p4_initial_ncpus, SHMEM_KEY,
414 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
415
416 // Process 3 lends all
417
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(p3_pid, 0, requests,
418 &nreqs, max_requests, &p3_prev_requested) == DLB_SUCCESS );
419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p3_prev_requested == 0 );
421
422 // Process 1 gets 3 CPUs
423
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 3, &new_ncpus, requests,
424 &nreqs, max_requests) == DLB_SUCCESS );
425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus + 3 );
426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p1_pid) == 0 );
428
429 // Process 2 gets 8 CPUs
430
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p2_pid, 8, &new_ncpus, requests,
431 &nreqs, max_requests) == DLB_SUCCESS );
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus + 8 );
433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
434
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 0 );
435
436 // Process 4 wants 20 CPUs, only gets 5
437
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p4_pid, 20, &new_ncpus, requests,
438 &nreqs, max_requests) == DLB_NOTED );
439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p4_initial_ncpus + 5 );
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
441
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p4_pid) == 15 );
442
443 /* Status:
444 * P1: 16 + 3
445 * P2: 16 + 8
446 * P3: 0
447 * P4: 16 + 5 (+15 requested)
448 */
449
450 // Process 3 now reclaims 4 CPUs, which should be reclaimed evenly */
451
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p3_pid, 4, &new_ncpus, requests,
452 &nreqs, max_requests) == DLB_SUCCESS );
453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 4 );
454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 3 );
455
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 18 );
456
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[1].pid == p4_pid && requests[1].howmany == 20 );
457
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[2].pid == p2_pid && requests[2].howmany == 22 );
458
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p1_pid) == 1 );
459
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 2 );
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p3_pid) == 0 );
461
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p4_pid) == 16 );
462
463 /* Status:
464 * P1: 16 + 2 (+1 requested)
465 * P2: 16 + 6 (+2 requested)
466 * P3: 4
467 * P4: 16 + 4 (+16 requested)
468 */
469
470 // Process 3 now reclaims 10 CPUs, which should be reclaimed evenly */
471
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p3_pid, 10, &new_ncpus, requests,
472 &nreqs, max_requests) == DLB_SUCCESS );
473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 14 );
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 3 );
475
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 16 );
476
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[1].pid == p4_pid && requests[1].howmany == 16 );
477
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[2].pid == p2_pid && requests[2].howmany == 18 );
478
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p1_pid) == 3 );
479
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 6 );
480
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p3_pid) == 0 );
481
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p4_pid) == 20 );
482
483 /* Status:
484 * P1: 16 (+3 requested)
485 * P2: 16 + 2 (+6 requested)
486 * P3: 14
487 * P4: 16 (+20 requested)
488 */
489
490 // Process 2 resets
491
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p2_pid, &new_ncpus, requests,
492 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 2 );
495
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p1_pid && requests[0].howmany == 17 );
496
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[1].pid == p4_pid && requests[1].howmany == 17 );
497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 8 );
498
499 // Process 3 reclaims last 2 CPUs
500
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p3_pid, 2, &new_ncpus, requests,
501 &nreqs, max_requests) == DLB_SUCCESS );
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 2 );
503
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p4_pid && requests[0].howmany == 16 );
504
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[1].pid == p1_pid && requests[1].howmany == 16 );
505
506 // Remove petitions
507
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p1_pid) == 3 );
508
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p2_pid) == 0 );
509
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p3_pid) == 0 );
510
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(p4_pid) == 20 );
511 1 shmem_lewi_async__remove_requests(p1_pid);
512 1 shmem_lewi_async__remove_requests(p4_pid);
513
514 // Finalize
515 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
518 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
521 1 shmem_lewi_async__finalize(p3_pid, &new_ncpus, requests, &nreqs, max_requests);
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p3_initial_ncpus );
523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
524 1 shmem_lewi_async__finalize(p4_pid, &new_ncpus, requests, &nreqs, max_requests);
525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p4_initial_ncpus );
526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
527 }
528
529 /* Re-init with more processes, test reclaim on mixed (idle and borrowed) CPUs */
530 {
531 enum { NEW_SYS_SIZE = 64 };
532 1 mu_testing_set_sys_size(NEW_SYS_SIZE);
533
534 1 p1_initial_ncpus = 16;
535 1 p2_initial_ncpus = 16;
536 1 pid_t p3_pid = 333;
537 1 unsigned int p3_initial_ncpus = 16;
538
539 // Init
540
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p1_pid, p1_initial_ncpus, SHMEM_KEY,
541 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
542
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p2_pid, p2_initial_ncpus, SHMEM_KEY,
543 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
544
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(p3_pid, p3_initial_ncpus, SHMEM_KEY,
545 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
546
547 // Process 1 and 2 lend 2 CPUs each
548
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p1_pid, 2, &new_ncpus, requests,
549 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus - 2 );
551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
553
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p2_pid, 2, &new_ncpus, requests,
554 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus - 2 );
556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
558
559 // Process 3 gets 3 CPUs (1 still idle)
560
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p3_pid, 3, &new_ncpus, requests,
561 &nreqs, max_requests) == DLB_SUCCESS );
562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p3_initial_ncpus + 3 );
563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
564
565 // Test 1: with Acquire
566 // Process 1 wants 3 CPUs (1 is idle, 1 is reclaimed, 1 is requested)
567
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(p1_pid, 3, &new_ncpus, requests,
568 &nreqs, max_requests) == DLB_NOTED );
569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
571
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus + 2 );
572
573 // Process 1 removes request and lends again 2 CPUs (P3 gets one)
574 1 shmem_lewi_async__remove_requests(p1_pid);
575
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p1_pid, 2, &new_ncpus, requests,
576 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus - 2 );
578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
579
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus + 3 );
580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
581
582 // Test 2: with Reclaim
583 // Process 1 reclaims (1 is idle, 1 is reclaimed)
584
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(p1_pid, &new_ncpus, requests,
585 &nreqs, max_requests, p1_prev_requested) == DLB_SUCCESS );
586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
588
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus + 2 );
589
590 // Process 1 removes request and lends again 2 CPUs (P3 gets one)
591 1 shmem_lewi_async__remove_requests(p1_pid);
592
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(p1_pid, 2, &new_ncpus, requests,
593 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus - 2 );
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
596
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus + 3 );
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
598
599 // Test 3: with Reset
600 // Process 1 resets (1 is idle, 1 is reclaimed)
601
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p1_pid, &new_ncpus, requests,
602 &nreqs, max_requests, &p1_prev_requested) == DLB_SUCCESS );
603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
605
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus + 2 );
606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p1_prev_requested == 0 );
607
608 // Process 2 and 3 reset
609
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p2_pid, &new_ncpus, requests,
610 &nreqs, max_requests, &p2_prev_requested) == DLB_SUCCESS );
611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 1 );
613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p2_prev_requested == 0 );
614
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( requests[0].pid == p3_pid && requests[0].howmany == p3_initial_ncpus );
615
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reset(p3_pid, &new_ncpus, requests,
616 &nreqs, max_requests, &p3_prev_requested) == DLB_NOUPDT );
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p3_initial_ncpus );
618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( p3_prev_requested == 0 );
620
621 // Finalize
622 1 shmem_lewi_async__finalize(p1_pid, &new_ncpus, requests, &nreqs, max_requests);
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p1_initial_ncpus );
624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
625 1 shmem_lewi_async__finalize(p2_pid, &new_ncpus, requests, &nreqs, max_requests);
626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p2_initial_ncpus );
627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
628 1 shmem_lewi_async__finalize(p3_pid, &new_ncpus, requests, &nreqs, max_requests);
629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == p3_initial_ncpus );
630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
631 }
632
633 1 mu_finalize();
634
635 1 return 0;
636 }
637