GCC Code Coverage Report


Directory: ./
File: tests/unit/04_core/lewi_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 33 37 89.2%
Functions: 3 5 60.0%
Branches: 12 24 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_core/DLB_kernel.h"
23 #include "LB_core/spd.h"
24 #include "LB_core/thread_ctx.h"
25 #include "LB_numThreads/numThreads.h"
26 #include "apis/dlb_errors.h"
27 #include "support/mask_utils.h"
28
29 #include <pthread.h>
30 #include <sched.h>
31 #include <string.h>
32
33 /* Test generic LeWI functions through DLB_kernel */
34
35 /* Callbacks to count how many times they have been called */
36 static int ntimes = 0;
37 4 static void cb_enable_cpu(int cpuid, void *arg) {
38 4 ++ntimes;
39 4 }
40 ✗ static void cb_disable_cpu(int cpuid, void *arg) {
41 ✗ ++ntimes;
42 }
43 ✗ static void cb_set_num_threads(int num_threads, void *arg) {
44 ✗ ++ntimes;
45 }
46
47 2 static void* observer_func(void *arg) {
48 /* Set up observer flag */
49 2 thread_ctx_set_observer(true);
50
51 2 int prev_ntimes = ntimes;
52 2 sync_call_flags_t flags = (const sync_call_flags_t) {
53 .is_mpi = true,
54 .is_blocking = true,
55 .is_collective = true,
56 .do_lewi = true,
57 };
58 2 into_sync_call(flags);
59 2 out_of_sync_call(flags);
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( prev_ntimes == ntimes );
61
62 2 return NULL;
63 }
64
65
66 2 int main(int argc, char *argv[]) {
67
68 2 char options[64] = "--lewi --shm-key=";
69 2 strcat(options, SHMEM_KEY);
70
71 subprocess_descriptor_t spd;
72 2 spd_enter_dlb(&spd);
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( Initialize(&spd, 111, 0, NULL, options) == DLB_SUCCESS );
74
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( pm_callback_set(&spd.pm, dlb_callback_enable_cpu,
76 (dlb_callback_t)cb_enable_cpu, NULL) == DLB_SUCCESS );
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( pm_callback_set(&spd.pm, dlb_callback_disable_cpu,
78 (dlb_callback_t)cb_disable_cpu, NULL) == DLB_SUCCESS );
79
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( pm_callback_set(&spd.pm, dlb_callback_set_num_threads,
80 (dlb_callback_t)cb_set_num_threads, NULL) == DLB_SUCCESS );
81
82
83 /* Test lewi_enabled */
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( set_lewi_enabled(&spd, false) == DLB_SUCCESS );
85
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( set_lewi_enabled(&spd, false) == DLB_NOUPDT );
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( lend(&spd) == DLB_ERR_DISBLD );
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( set_lewi_enabled(&spd, true) == DLB_SUCCESS );
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( set_lewi_enabled(&spd, true) == DLB_NOUPDT );
89
90 /* Test that MPI functions invoque callbacks */
91 2 int prev_ntimes = ntimes;
92 2 sync_call_flags_t flags = (const sync_call_flags_t) {
93 .is_mpi = true,
94 .is_blocking = true,
95 .is_collective = true,
96 .do_lewi = true,
97 };
98 2 into_sync_call(flags);
99 2 out_of_sync_call(flags);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( prev_ntimes < ntimes );
101
102 /* Test that MPI functions called from an observer thread do not invoque
103 * callbacks */
104 pthread_t observer_pthread;
105 2 pthread_create(&observer_pthread, NULL, observer_func, &spd);
106 2 pthread_join(observer_pthread, NULL);
107
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( Finish(&spd) == DLB_SUCCESS );
109
110 2 return 0;
111 }
112