GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/shmem_01.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 1 1 100.0%
Branches: 6 12 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.h"
23 #include "support/mask_utils.h"
24
25 #include <assert.h>
26 #include <unistd.h>
27 #include <sys/wait.h>
28
29 /* Create two shmems with different key */
30
31 enum { SHMEM_VERSION = 42 };
32
33 struct data {
34 int foo;
35 };
36
37 1 int main(int argc, char **argv) {
38 struct data *shdata1, *shdata2;
39 shmem_handler_t *handler1, *handler2;
40
41 // Create a shmem
42 1 handler1 = shmem_init((void**)&shdata1,
43 1 &(const shmem_props_t) {
44 .size = sizeof(struct data),
45 .name = "cpuinfo",
46 .key = SHMEM_KEY,
47 .version = SHMEM_VERSION,
48 });
49 1 shdata1->foo = 1;
50
51 // Try to create another shmem with the same name, it maps another region but same content
52 1 handler2 = shmem_init((void**)&shdata2,
53 1 &(const shmem_props_t) {
54 .size = sizeof(struct data),
55 .name = "cpuinfo",
56 .key = SHMEM_KEY,
57 .version = SHMEM_VERSION,
58 });
59
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( handler2 != NULL && handler1 != handler2 );
60
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( shdata2 != NULL && shdata1 != shdata2 );
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( shdata1->foo == shdata2->foo );
62
63 // Create a shmem with custom key
64 1 handler2 = shmem_init((void**)&shdata2,
65 1 &(const shmem_props_t) {
66 .size = sizeof(struct data),
67 .name = "cpuinfo",
68 .key = "42",
69 .version = SHMEM_VERSION,
70 });
71 1 shdata2->foo = 2;
72 assert( &shdata1 != &shdata2 );
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( shdata1->foo != shdata2->foo );
74
75 1 shmem_finalize(handler1, NULL);
76 1 shmem_finalize(handler2, NULL);
77
78 1 return 0;
79 }
80