| 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 "LB_comm/shmem_mngo.h" | ||
| 21 | #include "LB_core/DLB_kernel.h" | ||
| 22 | #include "LB_core/spd.h" | ||
| 23 | #include "test_process.h" | ||
| 24 | #include "dlb_errors.h" | ||
| 25 | #include "mngo/mngo.h" | ||
| 26 | #include "mngo/mngo_resources.h" | ||
| 27 | #include "support/mask_utils.h" | ||
| 28 | #include "unique_shmem.h" | ||
| 29 | #include <stdio.h> | ||
| 30 | #include <stdlib.h> | ||
| 31 | #include <string.h> | ||
| 32 | #include <sys/wait.h> | ||
| 33 | |||
| 34 | /* TLS global variable to store the spd pointer */ | ||
| 35 | extern __thread subprocess_descriptor_t *thread_spd; | ||
| 36 | |||
| 37 | static char options[128]; | ||
| 38 | |||
| 39 | extern int _mpis_per_node; | ||
| 40 | |||
| 41 | 6 | void initialize(size_t id, const char *mask, subprocess_descriptor_t *spd) { | |
| 42 | enum { SHMEM_SIZE_MULTIPLIER = 1 }; | ||
| 43 | |||
| 44 | cpu_set_t process_mask; | ||
| 45 | 6 | mu_parse_mask(mask, &process_mask); | |
| 46 | 6 | spd->id = id; | |
| 47 | 6 | thread_spd = spd; | |
| 48 | |||
| 49 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | assert(Initialize(spd, id, 2, &process_mask, options) == DLB_SUCCESS); |
| 50 | 6 | mngo_init(spd); | |
| 51 | |||
| 52 | 6 | usleep(500); // Allow some time for the other processes to initialize their memory | |
| 53 | 6 | } | |
| 54 | |||
| 55 | 6 | void finalize(subprocess_descriptor_t *spd) { | |
| 56 | 6 | mngo_fini(spd); | |
| 57 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | assert(Finish(spd) == DLB_SUCCESS); |
| 58 | 6 | } | |
| 59 | |||
| 60 | 4 | int test__mngo_state_change_drom_mask(const char *original_mask, const char *new_mask, size_t id) { | |
| 61 | |||
| 62 | subprocess_descriptor_t spd; | ||
| 63 | 4 | initialize(id, original_mask, &spd); | |
| 64 | |||
| 65 | cpu_set_t new_process_mask; | ||
| 66 | 4 | mu_parse_mask(new_mask, &new_process_mask); | |
| 67 | 4 | mngo_state_t new_state = { | |
| 68 | .lewi_on = false, | ||
| 69 | }; | ||
| 70 | 4 | memcpy(&new_state.drom_mask, &new_process_mask, sizeof(cpu_set_t)); | |
| 71 | |||
| 72 | 4 | int error = mngo_state__load(&spd, &new_state); | |
| 73 | |||
| 74 | 4 | shmem_mngo_barrier_wait(); | |
| 75 | 4 | finalize(&spd); | |
| 76 | |||
| 77 | 4 | return error; | |
| 78 | } | ||
| 79 | |||
| 80 | 2 | int test__mngo_state_lewi(const char *mask, size_t id) { | |
| 81 | subprocess_descriptor_t spd; | ||
| 82 | 2 | initialize(id, mask, &spd); | |
| 83 | |||
| 84 | 2 | mngo_state_t new_state = { | |
| 85 | .lewi_on = true, | ||
| 86 | }; | ||
| 87 | |||
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert(!spd.lewi_enabled); |
| 89 | 2 | int error = mngo_state__load(&spd, &new_state); | |
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert(spd.lewi_enabled); |
| 91 | |||
| 92 | 2 | shmem_mngo_barrier_wait(); | |
| 93 | 2 | finalize(&spd); | |
| 94 | |||
| 95 | 2 | return error; | |
| 96 | } | ||
| 97 | |||
| 98 | 1 | int main(int argc, char *argv[]) { | |
| 99 | enum { SYS_SIZE = 4 }; | ||
| 100 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 101 | |||
| 102 | 1 | fprintf(stderr, "Testing normal ussage of `mngo_state__load`:\n"); | |
| 103 | 1 | strcpy(options, "--mngo --mngo-mode=regions --drom --verbose=mngo,drom,barrier --shm-key="); | |
| 104 | 1 | strcat(options, SHMEM_KEY); | |
| 105 | 1 | test_shmem_mngo__modify_barrier_participants(2); | |
| 106 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_change_drom_mask("0-1", "0-1,3", 1)); |
| 107 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_change_drom_mask("2-3", "2", 2)); |
| 108 |
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; |
| 109 | |||
| 110 | 1 | fprintf(stderr, "Testing normal ussage of `mngo_state__load` (verbose):\n"); | |
| 111 | 1 | strcpy(options, "--mngo --mngo-mode=regions --drom --verbose=mngo,drom,barrier --shm-key="); | |
| 112 | 1 | strcat(options, SHMEM_KEY); | |
| 113 | 1 | test_shmem_mngo__modify_barrier_participants(2); | |
| 114 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_change_drom_mask("0-1", "0-1,3", 1)); |
| 115 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_change_drom_mask("2-3", "2", 2)); |
| 116 |
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; |
| 117 | |||
| 118 | #if 0 | ||
| 119 | fprintf(stderr, "Testing bad ussage of `mngo_state__load` (verbose):\n"); | ||
| 120 | test_shmem_mngo__modify_barrier_participants(2); | ||
| 121 | FORK(assert(test__mngo_state_change_drom_mask("0-1", "0-1,3", 1) == DLB_ERR_PERM)); | ||
| 122 | FORK(assert(test__mngo_state_change_drom_mask("2-3", "2-3", 2) == DLB_SUCCESS)); | ||
| 123 | WAITALL; | ||
| 124 | #endif | ||
| 125 | |||
| 126 | 1 | strcpy(options, "--mngo --mngo-mode=regions --lewi --shm-key="); | |
| 127 | 1 | strcat(options, SHMEM_KEY); | |
| 128 | 1 | test_shmem_mngo__modify_barrier_participants(2); | |
| 129 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_lewi("0-1", 1)); |
| 130 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo_state_lewi("2-3", 2)); |
| 131 |
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; |
| 132 | 1 | return 0; | |
| 133 | } | ||
| 134 |