GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_lewi_async_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 77 77 100.0%
Functions: 1 1 100.0%
Branches: 67 134 50.0%

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 // Basic checks with 1 sub-process
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 1 pid_t pid = 111;
37 1 int system_size = mu_get_system_size();
38 unsigned int new_ncpus;
39 unsigned int nreqs;
40 unsigned int prev_requested;
41 1 unsigned int initial_ncpus = system_size;
42 1 int max_requests = system_size;
43 1 lewi_request_t *requests = malloc(sizeof(lewi_request_t*)*max_requests);
44
45 // no shmem yet
46
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(pid, 1, NULL, NULL, NULL, 0, NULL)
47 == DLB_ERR_NOSHMEM );
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, 1, NULL, NULL, 0, NULL)
49 == DLB_ERR_NOSHMEM );
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid, NULL, NULL, NULL, 0, 0)
51 == DLB_ERR_NOSHMEM );
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, system_size, NULL, NULL, NULL, 0)
53 == DLB_ERR_NOSHMEM );
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__borrow_cpus(pid, system_size, NULL)
55 == DLB_ERR_NOSHMEM );
56 1 shmem_lewi_async__remove_requests(pid);
57
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__init(pid, initial_ncpus, SHMEM_KEY,
59 SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
60
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__exists() );
61
62 /* Lend cpus */
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(pid, 0, &new_ncpus, requests, &nreqs,
64 max_requests, &prev_requested) == DLB_NOUPDT );
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 0 );
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == 0 );
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(pid, 1, &new_ncpus, requests, &nreqs,
69 max_requests, &prev_requested) == DLB_SUCCESS );
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus - 1 );
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == 0 );
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(pid, system_size, &new_ncpus, requests,
74 &nreqs, max_requests, &prev_requested) == DLB_ERR_PERM );
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_cpus(pid+1, 1, &new_ncpus, requests, &nreqs,
76 max_requests, &prev_requested) == DLB_ERR_NOPROC );
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid, &new_ncpus, requests, &nreqs,
78 max_requests, prev_requested) == DLB_SUCCESS );
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
80
81 /* Lend up to ncpus */
82
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, 1, requests, &nreqs,
83 max_requests, &prev_requested) == DLB_SUCCESS );
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == 0 );
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, 1, requests, &nreqs,
87 max_requests, &prev_requested) == DLB_NOUPDT );
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == 0 );
90
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, system_size, requests, &nreqs,
91 max_requests, &prev_requested) == DLB_ERR_PERM );
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid+1, 1, requests, &nreqs,
93 max_requests, &prev_requested) == DLB_ERR_NOPROC );
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid, &new_ncpus, requests, &nreqs,
95 max_requests, prev_requested) == DLB_SUCCESS );
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
98
99 /* Reclaim */
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid, &new_ncpus, requests, &nreqs,
101 max_requests, prev_requested) == DLB_NOUPDT );
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
103
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid+1, NULL, NULL, NULL, 0, 0) == DLB_ERR_NOPROC );
104
105 /* Acquire */
106
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, 0, NULL, NULL, NULL, 0) == DLB_NOUPDT );
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid+1, 1, NULL, NULL, NULL, 0) == DLB_ERR_NOPROC );
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, 1, &new_ncpus, requests, &nreqs,
109 max_requests) == DLB_NOTED );
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, 2, &new_ncpus, requests, &nreqs,
112 max_requests) == DLB_NOTED );
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
114 1 shmem_lewi_async__remove_requests(pid);
115
116 /* Borrow */
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__borrow_cpus(pid, 0, &new_ncpus) == DLB_NOUPDT );
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__borrow_cpus(pid+1, 1, NULL) == DLB_ERR_NOPROC );
120
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__borrow_cpus(pid, 0, &new_ncpus) == DLB_NOUPDT );
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
122
123 /* Lend + Acquire */
124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, 0, requests, &nreqs,
125 max_requests, &prev_requested) == DLB_SUCCESS );
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == 0 );
128
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, 1, &new_ncpus, requests, &nreqs,
129 max_requests) == DLB_SUCCESS );
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == 1 );
132
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (initial_ncpus > 1) {
133
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, initial_ncpus-1, &new_ncpus,
134 requests, &nreqs, max_requests) == DLB_SUCCESS );
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
137 }
138
139 /* Acquire (add requests) + Lend */
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__acquire_cpus(pid, DLB_MAX_CPUS, &new_ncpus,
141 requests, &nreqs, max_requests) == DLB_NOTED );
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
144
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(pid) == DLB_MAX_CPUS );
145
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__lend_keep_cpus(pid, 0, requests, &nreqs,
146 max_requests, &prev_requested) == DLB_SUCCESS );
147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( prev_requested == DLB_MAX_CPUS );
149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__reclaim(pid, &new_ncpus, requests, &nreqs,
150 max_requests, prev_requested) == DLB_SUCCESS );
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_lewi_async__get_num_requests(pid) == DLB_MAX_CPUS );
153
154
155 1 shmem_lewi_async__finalize(pid, &new_ncpus, requests, &nreqs, max_requests);
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( new_ncpus == initial_ncpus );
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nreqs == 0 );
158
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( !shmem_lewi_async__exists() );
159
160 1 return 0;
161 }
162