GCC Code Coverage Report


Directory: ./
File: tests/unit/04_core/mngo_regions_00.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 1 1 100.0%
Branches: 20 34 58.8%

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 #include <assert.h>
21 #include <string.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <stdbool.h>
25
26 #include "dlb_errors.h"
27 #include "dlb_types.h"
28 #include "mngo/mngo_regions.h"
29 #include "support/mask_utils.h"
30
31 #define TEST_FAIL(...) do { \
32 fprintf(stderr, "[FAIL] %s: %d in %s: ", __FILE__, __LINE__, __func__); \
33 fprintf(stderr, __VA_ARGS__); \
34 fprintf(stderr, "\n"); \
35 } while (0)
36
37 const char* region_names[4] = {
38 "0",
39 "1",
40 "2",
41 "3",
42 };
43
44 #define NUM_TEST_REGIONS 4
45
46 1 int main(int argc, char *argv[]) {
47 mngo_regions_manager_t region_manager;
48
49 cpu_set_t process_mask;
50 1 mu_parse_mask("0-3", &process_mask);
51
52 1 mngo_state_t default_state = (const mngo_state_t) {
53 .lewi_on = false,
54 };
55 1 memcpy(&default_state.drom_mask, &process_mask, sizeof(cpu_set_t));
56
57 1 mngo_regions__manager_init(&region_manager, &default_state);
58
59 1 mngo_state_t *current_state = mngo_regions__get_current_resources(&region_manager);
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(default_state.lewi_on == current_state->lewi_on);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(memcmp(&default_state.drom_mask, &current_state->drom_mask, sizeof(cpu_set_t)) == 0);
62
63
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < NUM_TEST_REGIONS; i++) {
64 4 dlb_mngo_region_t *region = mngo_regions__alloc(&region_manager);
65 4 region->name = region_names[i];
66 }
67
68 // Check check on empty stack returns false
69
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 assert(!mngo_regions__check_top(
70 &region_manager,
71 mngo_regions__find(&region_manager, region_names[0])));
72
73 /**
74 * Check that regions survive reallocation.
75 *
76 * Basically the point of this test is to check if the region_0 pointer is still valid after
77 * the reallocation that happens at the alloc. (Note: the reallocation happens because the
78 * queue_t capacity grows by powers of four, if this ever changed this test is no longer valid)
79 */
80 1 dlb_mngo_region_t * region_0 = mngo_regions__find(&region_manager, region_names[0]);
81
82
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(DLB_SUCCESS == mngo_regions__push_active(&region_manager, region_0));
83
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(mngo_regions__check_top(&region_manager, region_0));
84
85 // This alloc will create an allocation as we now had 4 regions
86 1 dlb_mngo_region_t *dummy_region = mngo_regions__alloc(&region_manager);
87 1 dummy_region->name = "dummy";
88
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert(mngo_regions__check_top(&region_manager, region_0));
90
91 /**
92 * Check normal ussage
93 */
94
95 // Check push active regions
96
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < NUM_TEST_REGIONS; i++) {
97 4 dlb_mngo_region_t *region = mngo_regions__find(&region_manager, region_names[i]);
98
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(DLB_SUCCESS == mngo_regions__push_active(&region_manager, region));
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(mngo_regions__check_top(&region_manager, region));
100 }
101
102 // Check pop active regions
103
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = NUM_TEST_REGIONS-1; i >= 0; i--) {
104 4 dlb_mngo_region_t *region = mngo_regions__find(&region_manager, region_names[i]);
105
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(mngo_regions__check_top(&region_manager, region));
106
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 assert(DLB_SUCCESS == mngo_regions__pop_active(&region_manager, region));
107 }
108
109 // Make the stack [0, 1]
110
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 assert(DLB_SUCCESS == mngo_regions__push_active(
111 &region_manager,
112 mngo_regions__find(&region_manager, region_names[0])));
113
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 assert(DLB_SUCCESS == mngo_regions__push_active(
114 &region_manager,
115 mngo_regions__find(&region_manager, region_names[1])));
116
117 // Check that if the region is not on the top of the stack returns false
118
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 assert(!mngo_regions__check_top(&region_manager,
119 mngo_regions__find(&region_manager, region_names[0])));
120 // Check that if the region is not on the stack returns false
121
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 assert(!mngo_regions__check_top(&region_manager,
122 mngo_regions__find(&region_manager, region_names[3])));
123
124 1 mngo_regions__manager_finalize(&region_manager);
125 }
126