GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_versions_00.c
Date: 2026-12-02 14:34:28
Exec Total Coverage
Lines: 73 73 100.0%
Functions: 8 8 100.0%
Branches: 14 28 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 #include "apis/dlb_talp.h"
21 #include "LB_comm/shmem.h"
22 #include "LB_comm/shmem_async.h"
23 #include "LB_comm/shmem_barrier.h"
24 #include "LB_comm/shmem_cpuinfo.h"
25 #include "LB_comm/shmem_lewi_async.h"
26 #include "LB_comm/shmem_procinfo.h"
27 #include "LB_comm/shmem_talp.h"
28 #include "support/mask_utils.h"
29 #include "support/atomic.h"
30
31 #include <sched.h>
32 #include <unistd.h>
33 #include <stdio.h>
34 #include <assert.h>
35 #include <stdbool.h>
36 #include <pthread.h>
37 #include <semaphore.h>
38 #include <time.h>
39
40 /* queue_pid_t */
41 #define QUEUE_T pid_t
42 #define QUEUE_SIZE 8
43 #include "support/queue_template.h"
44
45 /* queue_lewi_mask_request_t */
46 typedef struct {
47 pid_t pid;
48 unsigned int howmany;
49 cpu_set_t allowed;
50 } lewi_mask_request_t;
51 #define QUEUE_T lewi_mask_request_t
52 #define QUEUE_KEY_T pid_t
53 #define QUEUE_SIZE 1024
54 #include "support/queue_template.h"
55
56 // Check versions of all shmems
57
58
59 1 static void check_shmem_sync_version(void) {
60 enum { KNOWN_SHMEM_SYNC_VERSION = 3 };
61 struct KnownShmemSync {
62 unsigned int uint1;
63 unsigned int uint2;
64 int int1;
65 int int2;
66 enum {ENUM1} enum1;
67 pthread_mutex_t mutex;
68 pid_t pidlist[];
69 };
70
71 1 int version = shmem_shsync__version();
72 1 size_t size = shmem_shsync__size();
73 1 size_t known_size = sizeof(struct KnownShmemSync) + sizeof(pid_t) * mu_get_system_size();
74 1 size_t alignment = DLB_CACHE_LINE; // in bytes
75 1 known_size = (known_size + (alignment - 1)) & ~(alignment - 1); // round up
76 1 fprintf(stderr, "shmem_sync version %d, size: %zu, known_size: %zu\n",
77 version, size, known_size);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_SHMEM_SYNC_VERSION );
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
80 1 }
81
82 1 static void check_async_version(void) {
83 enum { KNOWN_ASYNC_VERSION = 5 };
84 enum { KNOWN_QUEUE_SIZE = 100 };
85 struct KnownMessage {
86 enum {ENUM1} enum1;
87 int int1;
88 int int2;
89 cpu_set_t cpu_set;
90 };
91 enum KnownStatus { status1, status2, status3 };
92 struct KnownHelper {
93 /* Queue attributes */
94 struct KnownMessage message[KNOWN_QUEUE_SIZE];
95 unsigned int uint1;
96 unsigned int uint2;
97 pthread_mutex_t mutex;
98 pthread_cond_t cond;
99
100 /* Helper metadata */
101 pid_t pid;
102 pthread_t pth;
103 cpu_set_t mask;
104 void *ptr1;
105 bool bool1;
106 enum KnownStatus status;
107 };
108 struct KnownAsyncShdata {
109 bool bool1;
110 int int1;
111 int int2;
112 struct KnownHelper helpers[];
113 };
114
115 1 int version = shmem_async__version();
116 1 size_t size = shmem_async__size();
117 1 size_t known_size = sizeof(struct KnownAsyncShdata)
118 1 + sizeof(struct KnownHelper) * mu_get_system_size();
119 1 fprintf(stderr, "shmem_async version %d, size: %zu, known_size: %zu\n",
120 version, size, known_size);
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_ASYNC_VERSION );
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
123 1 }
124
125 1 static void check_barrier_version(void) {
126 enum { KNOWN_BARRIER_VERSION = 7 };
127 enum { KNOWN_BARRIER_NAME_MAX = 32 };
128 struct KnownBarrierFlags {
129 bool flag1:1;
130 bool flag2:1;
131 };
132 struct KnownBarrier {
133 char char1[KNOWN_BARRIER_NAME_MAX];
134 struct KnownBarrierFlags flags;
135 unsigned int int2;
136 atomic_uint int3;
137 atomic_uint int4;
138 pthread_barrier_t barrier;
139 pthread_rwlock_t rwlock;
140 };
141 struct KnownBarrierShdata {
142 bool bool1;
143 int int1;
144 int int2;
145 struct KnownBarrier barriers[];
146 };
147
148 1 int version = shmem_barrier__version();
149 1 size_t size = shmem_barrier__size();
150 1 size_t known_size = sizeof(struct KnownBarrierShdata)
151 1 + sizeof(struct KnownBarrier) * mu_get_system_size();
152 1 fprintf(stderr, "shmem_barrier version %d, size: %zu, known_size: %zu\n",
153 version, size, known_size);
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_BARRIER_VERSION );
155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
156 1 }
157
158 1 static void check_cpuinfo_version(void) {
159 enum { KNOWN_CPUINFO_VERSION = 7 };
160 enum { KNOWN_QUEUE_PROC_REQS_SIZE = 4096 };
161 enum { KNOWN_QUEUE_PIDS_SIZE = 8 };
162 struct KnownCpuinfo {
163 int int1;
164 pid_t pid1;
165 pid_t pid2;
166 enum {ENUM1} enum1;
167 queue_pid_t queue;
168 };
169 struct KnownCpuinfoFlags {
170 bool flag1:1;
171 bool flag2:1;
172 bool flag3:1;
173 };
174 struct KnownCpuinfoShdata {
175 struct KnownCpuinfoFlags flags;
176 struct timespec time1;
177 atomic_int_least64_t int1;
178 queue_lewi_mask_request_t queue;
179 cpu_set_t mask1;
180 cpu_set_t mask2;
181 struct KnownCpuinfo info[];
182 };
183
184 1 int version = shmem_cpuinfo__version();
185 1 size_t size = shmem_cpuinfo__size();
186 1 size_t known_size = sizeof(struct KnownCpuinfoShdata)
187 1 + sizeof(struct KnownCpuinfo) * mu_get_system_size();
188 1 fprintf(stderr, "shmem_cpuinfo version %d, size: %zu, known_size: %zu\n",
189 version, size, known_size);
190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_CPUINFO_VERSION );
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
192 1 }
193
194 1 static void check_lewi_async_version(void) {
195 enum {KNOWN_LEWI_ASYNC_VERSION = 3 };
196
197 struct DLB_ALIGN_CACHE KnownLewiProcess {
198 pid_t pid;
199 unsigned int uint1;
200 unsigned int uint2;
201 };
202
203 struct KnownLewiAsyncShdata {
204 unsigned int uint1;
205 unsigned int uint2;
206 queue_lewi_reqs_t reqs;
207 unsigned int uint3;
208 unsigned int uint4;
209 struct KnownLewiProcess processes[];
210 };
211
212 1 int version = shmem_lewi_async__version();
213 1 size_t size = shmem_lewi_async__size();
214 1 size_t known_size = sizeof(struct KnownLewiAsyncShdata)
215 1 + sizeof(struct KnownLewiProcess) * mu_get_system_size();
216 1 fprintf(stderr, "shmem_lewi_async version %d, size: %zu, known_size: %zu\n",
217 version, size, known_size);
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_LEWI_ASYNC_VERSION );
219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
220 1 }
221
222 1 static void check_procinfo_version(void) {
223 enum { KNOWN_PROCINFO_VERSION = 10 };
224
225 struct DLB_ALIGN_CACHE KnownProcinfo {
226 pid_t pid;
227 bool bool1;
228 bool bool2;
229 cpu_set_t mask1;
230 cpu_set_t mask2;
231 cpu_set_t mask3;
232 unsigned int int1;
233 // Cpu Usage fields:
234 double double1;
235 double double2;
236 #ifdef DLB_LOAD_AVERAGE
237 // Load average fields:
238 float float1[3];
239 struct timespec time;
240 #endif
241 };
242 struct KnownProcinfoFlags {
243 bool flag1:1;
244 bool flag2:1;
245 bool flag3:1;
246 };
247
248 struct KnownProcinfoShdata {
249 struct KnownProcinfoFlags flags;
250 struct timespec time;
251 cpu_set_t mask1;
252 int int1;
253 int int2;
254 struct KnownProcinfo info[];
255 };
256
257 1 int version = shmem_procinfo__version();
258 1 size_t size = shmem_procinfo__size();
259 1 size_t known_size = sizeof(struct KnownProcinfoShdata)
260 1 + sizeof(struct KnownProcinfo) * mu_get_system_size();
261 1 fprintf(stderr, "shmem_procinfo version %d, size: %zu, known_size: %zu\n",
262 version, size, known_size);
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_PROCINFO_VERSION );
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
265 1 }
266
267 1 static void check_talp_version(void) {
268 enum { KNOWN_TALP_VERSION = 4 };
269
270 struct DLB_ALIGN_CACHE TalpRegion {
271 char name[DLB_MONITOR_NAME_MAX];
272 atomic_int_least64_t int1;
273 atomic_int_least64_t int2;
274 pid_t pid;
275 float float1;
276 };
277
278 struct KnownTalpShdata {
279 bool bool1;
280 int int1;
281 int int2;
282 struct TalpRegion talp_region[];
283 };
284
285 1 int version = shmem_talp__version();
286 1 size_t size = shmem_talp__size();
287 1 size_t known_size = sizeof(struct KnownTalpShdata)
288 1 + sizeof(struct TalpRegion) * mu_get_system_size();
289 1 fprintf(stderr, "shmem_talp version %d, size: %zu, known_size: %zu\n",
290 version, size, known_size);
291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( version == KNOWN_TALP_VERSION );
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( size == known_size );
293 1 }
294
295 1 int main(int argc, char **argv) {
296 1 check_shmem_sync_version();
297 1 check_async_version();
298 1 check_barrier_version();
299 1 check_cpuinfo_version();
300 1 check_lewi_async_version();
301 1 check_procinfo_version();
302 1 check_talp_version();
303
304 1 return 0;
305 }
306