GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/talp_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 58 58 100.0%
Functions: 1 1 100.0%
Branches: 56 110 50.9%

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 "unique_shmem.h"
21
22 #include "LB_comm/shmem.h"
23 #include "LB_comm/shmem_talp.h"
24 #include "apis/dlb_errors.h"
25 #include "support/mask_utils.h"
26
27 #include <sched.h>
28 #include <sys/types.h>
29 #include <stdint.h>
30 #include <assert.h>
31
32 enum { KNOWN_DEFAULT_REGIONS_PER_PROC = 100 };
33
34 1 int main(int argc, char *argv[]) {
35 1 pid_t p1_pid = 111;
36 1 pid_t p2_pid = 222;
37
38
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__finalize(42) == DLB_ERR_NOSHMEM );
39
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__register(42, 1, "", NULL) == DLB_ERR_NOSHMEM );
40
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_pidlist(NULL, NULL, 0) == DLB_ERR_NOSHMEM );
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_regionlist(NULL, NULL, 0, NULL) == DLB_ERR_NOSHMEM );
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_times(0, NULL, NULL) == DLB_ERR_NOSHMEM );
43
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(0, 0, 0) == DLB_ERR_NOSHMEM );
44
45 /* Initialize shared memories for p1_pid and p2_pid */
46
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__init(SHMEM_KEY, KNOWN_DEFAULT_REGIONS_PER_PROC) == DLB_SUCCESS );
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__init(SHMEM_KEY, KNOWN_DEFAULT_REGIONS_PER_PROC) == DLB_SUCCESS );
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__exists() );
49
50 /* Register some TALP regions */
51 1 int region_id1 = -1;
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__register(p1_pid, 1, "Custom region 1", &region_id1) == DLB_SUCCESS );
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( region_id1 == 0 );
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(region_id1, 111111, 222222) == DLB_SUCCESS );
55 1 int64_t mpi_time = -1;
56 1 int64_t useful_time = -1;
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_times(region_id1, &mpi_time, &useful_time) == DLB_SUCCESS );
58
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( mpi_time == 111111 && useful_time == 222222);
59 1 int region_id2 = -1 ;
60
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__register(p1_pid, 1, "Region 2", &region_id2) == DLB_SUCCESS );
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( region_id2 == 1 );
62
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(region_id2, INT64_MAX, 42) == DLB_SUCCESS );
63 1 int region_id3 = -1;
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__register(p2_pid, 1, "Custom region 1", &region_id3) == DLB_SUCCESS );
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( region_id3 == 2 );
66
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(region_id3, 0, 4242) == DLB_SUCCESS );
67
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(3, 0, 0) == DLB_ERR_NOENT );
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_times(3, NULL, NULL) == DLB_ERR_NOENT );
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(-1, 0, 0) == DLB_ERR_NOENT );
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_times(-1, NULL, NULL) == DLB_ERR_NOENT );
71
72 /* Get region */
73 talp_region_list_t region;
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_region(&region, 42, "Fake region") == DLB_ERR_NOPROC );
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_region(&region, p1_pid, "Custom region 1") == DLB_SUCCESS );
76
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 assert( region.pid == p1_pid
77 && region.region_id == 0
78 && region.mpi_time == 111111
79 && region.useful_time == 222222 );
80
81 enum { max_len = 8 };
82 int nelems;
83
84 /* Get pidlist */
85 pid_t pidlist[max_len];
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_pidlist(pidlist, &nelems, max_len) == DLB_SUCCESS );
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nelems == 2 );
88
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( pidlist[0] == p1_pid && pidlist[1] == p2_pid );
89
90 /* Get region id list */
91 talp_region_list_t region_list[max_len];
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_regionlist(region_list, &nelems, max_len,
93 "Custom region 1") == DLB_SUCCESS );
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nelems == 2 );
95
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( region_list[0].pid == p1_pid && region_list[0].region_id == 0 );
96
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( region_list[1].pid == p2_pid && region_list[1].region_id == 2 );
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_regionlist(region_list, &nelems, max_len,
98 "Region 2") == DLB_SUCCESS );
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nelems == 1 );
100
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 assert( region_list[0].pid == p1_pid && region_list[0].region_id == 1 );
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_regionlist(region_list, &nelems, max_len,
102 "nonexistent region") == DLB_SUCCESS );
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( nelems == 0 );
104
105 /* Fill up memory from id 3 until mu_get_system_size * KNOWN_DEFAULT_REGIONS_PER_PROC */
106 int i;
107 1 int expected_memory_capacity = mu_get_system_size() * KNOWN_DEFAULT_REGIONS_PER_PROC;
108 int region_id;
109
2/2
✓ Branch 0 taken 197 times.
✓ Branch 1 taken 1 times.
198 for (i=3; i<expected_memory_capacity; ++i) {
110 char name[32];
111 197 snprintf(name, 32, "Region %d", i);
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 197 times.
197 assert( shmem_talp__register(p1_pid, 1, name, &region_id) == DLB_SUCCESS );
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
197 assert( region_id == i );
114 }
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__register(p1_pid, 1, "No mem", &region_id) == DLB_ERR_NOMEM );
116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__set_times(i, 0, 0) == DLB_ERR_NOMEM );
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__get_times(i, NULL, NULL) == DLB_ERR_NOMEM );
118
119 /* Finalize shared memories */
120
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__finalize(p1_pid) == DLB_SUCCESS );
121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_talp__finalize(p2_pid) == DLB_SUCCESS );
122
123 1 return 0;
124 }
125