GCC Code Coverage Report


Directory: ./
File: tests/unit/04_core/mngo_drom_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 18 24 75.0%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2026 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
21 #include "LB_comm/shmem_mngo.h"
22 #include "LB_core/DLB_kernel.h"
23 #include "LB_core/spd.h"
24 #include "dlb_errors.h"
25 #include "mngo/mngo.h"
26 #include "mngo/mngo_drom.h"
27 #include "support/mask_utils.h"
28 #include "unique_shmem.h"
29 #include "test_process.h"
30 #include <sched.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/wait.h>
35
36 /* TLS global variable to store the spd pointer */
37 extern __thread subprocess_descriptor_t *thread_spd;
38
39 static char options[128];
40
41 4 int test__mngo_drom_balance(const char *original_mask, size_t id, float self_pe, float node_pe, int expected_cpu_count) {
42
43 4 int error = DLB_SUCCESS;
44
45 enum { SHMEM_SIZE_MULTIPLIER = 1 };
46
47 cpu_set_t process_mask;
48 4 mu_parse_mask(original_mask, &process_mask);
49
50 4 subprocess_descriptor_t spd = {.id = id};
51 4 thread_spd = &spd;
52
53
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(Initialize(&spd, id, 2, &process_mask, options) == DLB_SUCCESS);
54 4 mngo_init(&spd);
55
56 cpu_set_t new_cpu_mask;
57 4 mngo_drom__balance(&spd, self_pe, node_pe, &new_cpu_mask);
58
59 4 shmem_mngo_barrier_wait();
60 4 mngo_fini(&spd);
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(Finish(&spd) == DLB_SUCCESS);
62
63 4 return error;
64 }
65
66 1 int main(int argc, char *argv[]) {
67 enum { SYS_SIZE = 4 };
68 1 mu_testing_set_sys_size(SYS_SIZE);
69
70 1 fprintf(stderr, "Testing normal ussage of `mngo_state__load`:\n");
71
72 1 strcpy(options, "--mngo --mngo-mode=regions --drom --shm-key=");
73 1 strcat(options, SHMEM_KEY);
74
75 // Balanced test
76
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
1 FORK(test__mngo_drom_balance("0-1", 1, 0.50, 0.50, 2));
77
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
1 FORK(test__mngo_drom_balance("2-3", 2, 0.50, 0.50, 2));
78
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 times.
3 WAITALL;
79
80 // Imbalanced test
81
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
1 FORK(test__mngo_drom_balance("0-1", 1, 0.20, 0.60, 1));
82
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
1 FORK(test__mngo_drom_balance("2-3", 2, 1.00, 0.60, 3));
83
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 times.
3 WAITALL;
84
85 1 return 0;
86 }
87