GCC Code Coverage Report


Directory: ./
File: tests/unit/03_policies/lewi_mask_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 29 31 93.5%
Functions: 2 3 66.7%
Branches: 18 36 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 "assert_loop.h"
21 #include "unique_shmem.h"
22
23 #include "apis/dlb_errors.h"
24 #include "LB_core/spd.h"
25 #include "LB_policies/lewi_mask.h"
26 #include "LB_comm/shmem_procinfo.h"
27 #include "LB_comm/shmem_cpuinfo.h"
28 #include "LB_comm/shmem_async.h"
29 #include "LB_numThreads/numThreads.h"
30 #include "support/debug.h"
31
32 #include <sched.h>
33 #include <unistd.h>
34 #include <assert.h>
35 #include <string.h>
36
37 static volatile int enable_times = 0;
38 static volatile int disable_times = 0;
39
40 2 static void cb_enable_cpu(int cpuid, void *arg) {
41 2 __sync_add_and_fetch(&enable_times, 1);
42 2 }
43
44 ✗ static void cb_disable_cpu(int cpuid, void *arg) {
45 ✗ __sync_add_and_fetch(&disable_times, 1);
46 }
47
48 1 int main( int argc, char **argv ) {
49 1 char options[64] = "--verbose=shmem --mode=async --shm-key=";
50 1 strcat(options, SHMEM_KEY);
51
52 subprocess_descriptor_t spd;
53 1 spd.id = getpid();
54 1 options_init(&spd.options, options);
55 1 debug_init(&spd.options);
56 1 pm_init(&spd.pm);
57
58 1 int mycpu = sched_getcpu();
59 1 sched_getaffinity(0, sizeof(cpu_set_t), &spd.process_mask);
60
61 // Initialize shmems and callbacks
62
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(spd.id, 0, &spd.process_mask, NULL, spd.options.shm_key,
63 spd.options.shm_size_multiplier) == DLB_SUCCESS );
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(spd.id, 0, &spd.process_mask, spd.options.shm_key,
65 spd.options.lewi_color) == DLB_SUCCESS );
66
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_init(spd.id, &spd.pm, &spd.process_mask,
67 spd.options.shm_key, spd.options.shm_size_multiplier) == DLB_SUCCESS );
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( pm_callback_set(&spd.pm, dlb_callback_enable_cpu,
69 (dlb_callback_t)cb_enable_cpu, NULL) == DLB_SUCCESS );
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( pm_callback_set(&spd.pm, dlb_callback_disable_cpu,
71 (dlb_callback_t)cb_disable_cpu, NULL) == DLB_SUCCESS );
72
73 // Init
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_Init(&spd) == DLB_SUCCESS );
75
76 // Reclaim a non-lent CPU (this should not trigger a callback)
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_ReclaimCpu(&spd, mycpu) == DLB_NOUPDT );
78
79 // Lend (this should not trigger a callback)
80
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_LendCpu(&spd, mycpu) == DLB_SUCCESS );
81
82 // Reclaim a lent CPU (callback enable)
83
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_ReclaimCpu(&spd, mycpu) == DLB_SUCCESS );
84
85 // Lend
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_LendCpu(&spd, mycpu) == DLB_SUCCESS );
87
88 // Acquire a lent CPU (callback enable)
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_AcquireCpu(&spd, mycpu) == DLB_SUCCESS );
90
91 // Finalize
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( lewi_mask_Finalize(&spd) == DLB_SUCCESS );
93
94 // Poll a limited number of times if at least enable_callback was called once
95
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
1 assert_loop( enable_times > 0 );
96
97 // Finalize shmems
98
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(spd.id, spd.options.shm_key, spd.options.lewi_color)
99 == DLB_SUCCESS );
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(spd.id, false, spd.options.shm_key,
101 spd.options.shm_size_multiplier) == DLB_SUCCESS );
102
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_async_finalize(spd.id) == DLB_SUCCESS );
103
104 1 return 0;
105 }
106