| 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 "mngo/mngo_balancer.h" | ||
| 21 | |||
| 22 | #include <assert.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <stdbool.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <sys/wait.h> | ||
| 28 | |||
| 29 | 1 | int main(int argc, char *argv[]) { | |
| 30 | |||
| 31 | /* Test precompute_levels */ | ||
| 32 | 1 | int deltas[4] = {2, -2, 3, 4}; | |
| 33 | { | ||
| 34 | 1 | int *count_add = calloc(5, sizeof(int)); | |
| 35 | 1 | int *count_sub = calloc(5, sizeof(int)); | |
| 36 | |||
| 37 | 1 | mngo_balancer_testing__precompute_levels(deltas, 4, count_add, count_sub, 5); | |
| 38 | |||
| 39 | 1 | int count_add_correct[5] = {3, 3, 3, 2, 1}; | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_add, count_add_correct, 5) != 0) { |
| 41 | ✗ | assert(false && "count_add unexpected result"); | |
| 42 | }; | ||
| 43 | |||
| 44 | 1 | int count_sub_correct[5] = {1, 1, 1, 0, 0}; | |
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_sub, count_sub_correct, 5) != 0) { |
| 46 | ✗ | assert(false && "count_sub unexpected result"); | |
| 47 | }; | ||
| 48 | |||
| 49 | 1 | free(count_add); | |
| 50 | 1 | free(count_sub); | |
| 51 | } | ||
| 52 | |||
| 53 | { | ||
| 54 | 1 | int *count_add = calloc(7, sizeof(int)); | |
| 55 | 1 | int *count_sub = calloc(7, sizeof(int)); | |
| 56 | |||
| 57 | 1 | mngo_balancer_testing__precompute_levels(deltas, 4, count_add, count_sub, 7); | |
| 58 | |||
| 59 | 1 | int count_add_correct[7] = {3, 3, 3, 2, 1, 0, 0}; | |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_add, count_add_correct, 7) != 0) { |
| 61 | ✗ | assert(false && "count_add unexpected result"); | |
| 62 | }; | ||
| 63 | |||
| 64 | 1 | int count_sub_correct[7] = {1, 1, 1, 0, 0, 0, 0}; | |
| 65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_sub, count_sub_correct, 7) != 0) { |
| 66 | ✗ | assert(false && "count_sub unexpected result"); | |
| 67 | }; | ||
| 68 | |||
| 69 | /* Test pack_levels */ | ||
| 70 | { | ||
| 71 | 1 | int self_deltas[7] = {1, 1, 1, 0, 0, 0, 0}; | |
| 72 | 1 | mngo_balancer_testing__pack_levels(2, count_sub, self_deltas, 2); | |
| 73 | |||
| 74 | 1 | int count_sub_packed_correct[7] = {2, 2, 0, 0, 0, 0, 0}; | |
| 75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_sub, count_sub_packed_correct, 7) != 0) { |
| 76 | ✗ | assert(false && "apply pack_levels wrong levels"); | |
| 77 | }; | ||
| 78 | |||
| 79 | 1 | int correct_self_deltas[7] = {1, 2, 0, 0, 0, 0, 0}; | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(self_deltas, correct_self_deltas, 7) != 0) { |
| 81 | ✗ | assert(false && "apply pack_levels wrong deltas"); | |
| 82 | }; | ||
| 83 | } | ||
| 84 | |||
| 85 | { | ||
| 86 | 1 | int self_deltas[7] = {1, 1, 1, 0, 0, 0, 0}; | |
| 87 | 1 | int correct_self_deltas[7] = {1, 1, 1, 0, 0, 0, 0}; | |
| 88 | 1 | mngo_balancer_testing__pack_levels(3, count_add, self_deltas, 4); | |
| 89 | |||
| 90 | 1 | int count_add_packed_correct[7] = {3, 3, 3, 3, 0, 0, 0}; | |
| 91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(count_add, count_add_packed_correct, 7) != 0) { |
| 92 | ✗ | assert(false && "apply pack_levels wrong levels"); | |
| 93 | }; | ||
| 94 | |||
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (memcmp(self_deltas, correct_self_deltas, 7) != 0) { |
| 96 | ✗ | assert(false && "apply pack_levels wrong deltas"); | |
| 97 | }; | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | 1 | free(count_add); | |
| 102 | 1 | free(count_sub); | |
| 103 | } | ||
| 104 | |||
| 105 | { | ||
| 106 | 1 | bool i_am_a_giver = false; | |
| 107 | 1 | int my_abs_delta = 2; | |
| 108 | |||
| 109 | 1 | int count_add[3] = {2, 2, 1}; | |
| 110 | 1 | int count_sub[3] = {3, 3, 0}; | |
| 111 | 1 | int count_size = 3; | |
| 112 | 1 | int my_delta = mngo_balancer_testing__coherent_redistribution( | |
| 113 | 1 | i_am_a_giver, my_abs_delta, count_add, count_sub, count_size-1); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(my_delta == 2); |
| 115 | } | ||
| 116 | |||
| 117 | { | ||
| 118 | 1 | bool i_am_a_giver = true; | |
| 119 | 1 | int my_abs_delta = 2; | |
| 120 | |||
| 121 | 1 | int count_add[3] = {3, 3, 0}; | |
| 122 | 1 | int count_sub[3] = {2, 2, 1}; | |
| 123 | 1 | int count_size = 3; | |
| 124 | 1 | int my_delta = mngo_balancer_testing__coherent_redistribution( | |
| 125 | 1 | i_am_a_giver, my_abs_delta, count_add, count_sub, count_size-1); | |
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(my_delta == -2); |
| 127 | } | ||
| 128 | |||
| 129 | { | ||
| 130 | 1 | bool i_am_a_giver = false; | |
| 131 | 1 | int my_abs_delta = 1; | |
| 132 | |||
| 133 | 1 | int count_add[3] = {2, 2, 0}; | |
| 134 | 1 | int count_sub[3] = {3, 3, 0}; | |
| 135 | 1 | int count_size = 3; | |
| 136 | 1 | int my_delta = mngo_balancer_testing__coherent_redistribution( | |
| 137 | 1 | i_am_a_giver, my_abs_delta, count_add, count_sub, count_size-1); | |
| 138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(my_delta == 0); |
| 139 | } | ||
| 140 | |||
| 141 | { | ||
| 142 | 1 | bool i_am_a_giver = true; | |
| 143 | 1 | int my_abs_delta = 1; | |
| 144 | |||
| 145 | 1 | int count_add[3] = {2, 2, 1}; | |
| 146 | 1 | int count_sub[3] = {3, 3, 0}; | |
| 147 | 1 | int count_size = 3; | |
| 148 | 1 | int my_delta = mngo_balancer_testing__coherent_redistribution( | |
| 149 | 1 | i_am_a_giver, my_abs_delta, count_add, count_sub, count_size-1); | |
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(my_delta == -1); |
| 151 | } | ||
| 152 | } | ||
| 153 |