GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/cpuinfo_procinfo_sync_01.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 1 1 100.0%
Branches: 28 56 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 "unique_shmem.h"
21
22 #include "LB_comm/shmem_procinfo.h"
23 #include "LB_comm/shmem_cpuinfo.h"
24 #include "apis/dlb_errors.h"
25 #include "support/mask_utils.h"
26
27 #include <sched.h>
28 #include <assert.h>
29
30 /* array_cpuinfo_task_t */
31 #define ARRAY_T cpuinfo_task_t
32 #define ARRAY_KEY_T pid_t
33 #include "support/array_template.h"
34
35 1 int main( int argc, char **argv ) {
36
37 enum { SHMEM_SIZE_MULTIPLIER = 1 };
38
39 /* This test needs at least room for 4 CPUs */
40 enum { SYS_SIZE = 4 };
41 1 mu_init();
42 1 mu_testing_set_sys_size(SYS_SIZE);
43
44 /* Multi init - finalize */
45 cpu_set_t empty_mask;
46 1 CPU_ZERO(&empty_mask);
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(42, 0, &empty_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(42, 0, &empty_mask, NULL,
49 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo_ext__init(SHMEM_KEY, 0) == DLB_SUCCESS );
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
52
53
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo_ext__finalize() == DLB_SUCCESS );
54
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__finalize() == DLB_SUCCESS );
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(42, SHMEM_KEY, 0) == DLB_SUCCESS );
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(42, false,
57 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
58
59 /* CPU stealing */
60 {
61 /* Process 1 initializes with mask 0-3 */
62 1 pid_t p1_pid = 111;
63 cpu_set_t p1_mask;
64 1 mu_parse_mask("0-3", &p1_mask);
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(p1_pid, 0, &p1_mask, NULL,
66 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
67
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
68
69 /* Process 2 enters and steals CPU 3 */
70 1 pid_t p2_pid = 222;
71 cpu_set_t p2_mask;
72 1 mu_parse_mask("3", &p2_mask);
73 /* DLB_DROM_PreInit: */
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo_ext__preinit(p2_pid, &p2_mask, DLB_STEAL_CPUS) == DLB_SUCCESS );
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo_ext__preinit(p2_pid, &p2_mask, DLB_STEAL_CPUS) == DLB_SUCCESS );
76 /* DLB_Init: (with p2_pid as preinit_pid) */
77 cpu_set_t new_mask;
78
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__init(p2_pid, p2_pid, &p2_mask, &new_mask,
79 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_NOTED );
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( CPU_EQUAL(&new_mask, &p2_mask) );
81
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p2_pid, p2_pid, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
82
83 /* Process 1 polls DROM */
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__polldrom(p1_pid, NULL, &new_mask) == DLB_SUCCESS );
85 array_cpuinfo_task_t tasks;
86 1 array_cpuinfo_task_t_init(&tasks, SYS_SIZE);
87 1 shmem_cpuinfo__update_ownership(p1_pid, &new_mask, &tasks);
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
89
3/6
✓ 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.
1 assert( tasks.items[0].pid == p1_pid
90 && tasks.items[0].cpuid == 3
91 && tasks.items[0].action == DISABLE_CPU );
92 1 array_cpuinfo_task_t_clear(&tasks);
93
94 /* All CPUs are correctly guested */
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 0) == DLB_SUCCESS );
96
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 1) == DLB_SUCCESS );
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 2) == DLB_SUCCESS );
98
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_SUCCESS );
99
100 /* Finalize shmems */
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
102
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(p2_pid, false,
103 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
105
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_procinfo__finalize(p1_pid, false,
106 SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS );
107 }
108
109 1 mu_finalize();
110
111 1 return 0;
112 }
113