| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2021 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.h" | ||
| 23 | #include "LB_comm/shmem_procinfo.h" | ||
| 24 | #include "apis/dlb_errors.h" | ||
| 25 | #include "apis/dlb_types.h" | ||
| 26 | #include "support/mask_utils.h" | ||
| 27 | |||
| 28 | #include <sched.h> | ||
| 29 | #include <sys/types.h> | ||
| 30 | #include <unistd.h> | ||
| 31 | #include <string.h> | ||
| 32 | #include <pthread.h> | ||
| 33 | #include <assert.h> | ||
| 34 | |||
| 35 | // PreInit tests | ||
| 36 | |||
| 37 | struct thread_data { | ||
| 38 | pid_t pid; | ||
| 39 | cpu_set_t *mask; | ||
| 40 | bool terminate; | ||
| 41 | }; | ||
| 42 | |||
| 43 | static pthread_barrier_t barrier; | ||
| 44 | |||
| 45 | 4 | static void* poll_drom(void *arg) { | |
| 46 | 4 | pid_t pid = ((struct thread_data*)arg)->pid; | |
| 47 | 4 | cpu_set_t *mask = ((struct thread_data*)arg)->mask; | |
| 48 | 4 | bool *terminate = &((struct thread_data*)arg)->terminate; | |
| 49 | |||
| 50 | 4 | pthread_barrier_wait(&barrier); | |
| 51 | |||
| 52 | int err; | ||
| 53 | cpu_set_t local_mask; | ||
| 54 | 4 | CPU_ZERO(&local_mask); | |
| 55 | |||
| 56 | 6 | while ((err = shmem_procinfo__polldrom(pid, NULL, &local_mask)) != DLB_SUCCESS | |
| 57 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
6 | && !*terminate) { |
| 58 | 2 | usleep(1000); | |
| 59 | } | ||
| 60 | |||
| 61 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (err == DLB_SUCCESS) { |
| 62 | 4 | memcpy(mask, &local_mask, sizeof(cpu_set_t)); | |
| 63 | } | ||
| 64 | |||
| 65 | 4 | return NULL; | |
| 66 | } | ||
| 67 | |||
| 68 | 1 | int main( int argc, char **argv ) { | |
| 69 | |||
| 70 | enum { SHMEM_SIZE_MULTIPLIER = 1 }; | ||
| 71 | |||
| 72 | // This test needs at least room for 4 CPUs | ||
| 73 | enum { SYS_SIZE = 4 }; | ||
| 74 | 1 | mu_init(); | |
| 75 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 76 | |||
| 77 | 1 | const cpu_set_t original_p1_mask = { .__bits = {0x3} }; /* [0011] */ | |
| 78 | 1 | const cpu_set_t original_p2_mask = { .__bits = {0xc} }; /* [1100] */ | |
| 79 | |||
| 80 | // Initialize sub-process 1 | ||
| 81 | 1 | pid_t p1_pid = 111; | |
| 82 | cpu_set_t p1_mask; | ||
| 83 | 1 | memcpy(&p1_mask, &original_p1_mask, sizeof(cpu_set_t)); | |
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p1_pid, 0, &p1_mask, NULL, SHMEM_KEY, |
| 85 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 86 | |||
| 87 | // Initialize sub-process 2 | ||
| 88 | 1 | pid_t p2_pid = 222; | |
| 89 | cpu_set_t p2_mask; | ||
| 90 | 1 | memcpy(&p2_mask, &original_p2_mask, sizeof(cpu_set_t)); | |
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, 0, &p2_mask, NULL, SHMEM_KEY, |
| 92 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 93 | |||
| 94 | // Initialize external | ||
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); |
| 96 | |||
| 97 | // Sub-process 3 | ||
| 98 | 1 | pid_t p3_pid = 333; | |
| 99 | 1 | cpu_set_t p3_mask = { .__bits = {0x6}}; /* [0110] */ | |
| 100 | |||
| 101 | 1 | dlb_drom_flags_t no_flags = DLB_DROM_FLAGS_NONE; | |
| 102 | |||
| 103 | // no stealing | ||
| 104 | { | ||
| 105 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_mask, no_flags) == DLB_ERR_PERM ); |
| 106 | } | ||
| 107 | |||
| 108 | // stealing | ||
| 109 | { | ||
| 110 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_mask, DLB_STEAL_CPUS) == DLB_SUCCESS ); |
| 111 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p3_pid, /* return-stolen */ true) == DLB_SUCCESS ); |
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &original_p1_mask) ); |
| 114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p2_pid, NULL, &p2_mask) == DLB_SUCCESS ); |
| 115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &original_p2_mask) ); |
| 116 | } | ||
| 117 | |||
| 118 | // stealing all CPUs (this is no longer ERROR) | ||
| 119 | { | ||
| 120 | 1 | cpu_set_t p3_new_mask = { .__bits = {0xf} }; /* [1111] */ | |
| 121 | |||
| 122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_new_mask, DLB_STEAL_CPUS) |
| 123 | == DLB_SUCCESS ); | ||
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p1_mask) == 0 ); |
| 126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p2_pid, NULL, &p2_mask) == DLB_SUCCESS ); |
| 127 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p2_mask) == 0 ); |
| 128 | |||
| 129 | // roll back | ||
| 130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p3_pid, /* return_stolen */ true) == DLB_SUCCESS ); |
| 131 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 132 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &original_p1_mask) ); |
| 133 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p2_pid, NULL, &p2_mask) == DLB_SUCCESS ); |
| 134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &original_p2_mask) ); |
| 135 | } | ||
| 136 | |||
| 137 | // stealing with dirty process (ERROR) | ||
| 138 | { | ||
| 139 | cpu_set_t p3_new_mask; | ||
| 140 | 1 | mu_parse_mask("0", &p3_new_mask); | |
| 141 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_new_mask, DLB_STEAL_CPUS) |
| 142 | == DLB_SUCCESS ); | ||
| 143 | 1 | mu_parse_mask("0-1", &p3_new_mask); | |
| 144 | /* error because p1 is still dirty */ | ||
| 145 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__setprocessmask(p3_pid, &p3_new_mask, DLB_STEAL_CPUS, NULL) |
| 146 | == DLB_ERR_PERM ); | ||
| 147 | |||
| 148 | // roll back | ||
| 149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p3_pid, /* return_stolen */ true) == DLB_SUCCESS ); |
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &original_p1_mask) ); |
| 152 | } | ||
| 153 | |||
| 154 | // synchronous | ||
| 155 | { | ||
| 156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_mask, |
| 157 | (dlb_drom_flags_t)(DLB_STEAL_CPUS | DLB_SYNC_QUERY)) == DLB_ERR_TIMEOUT ); | ||
| 158 | } | ||
| 159 | |||
| 160 | // synchronous while p1 and p2 are polling | ||
| 161 | { | ||
| 162 | 1 | pthread_barrier_init(&barrier, NULL, 3); | |
| 163 | |||
| 164 | 1 | struct thread_data td1 = { .pid = p1_pid, .mask = &p1_mask, .terminate = false }; | |
| 165 | pthread_t thread1; | ||
| 166 | 1 | pthread_create(&thread1, NULL, poll_drom, &td1); | |
| 167 | |||
| 168 | 1 | struct thread_data td2 = { .pid = p2_pid, .mask = &p2_mask, .terminate = false }; | |
| 169 | pthread_t thread2; | ||
| 170 | 1 | pthread_create(&thread2, NULL, poll_drom, &td2); | |
| 171 | |||
| 172 | 1 | pthread_barrier_wait(&barrier); | |
| 173 | |||
| 174 | // preinitialize and check masks | ||
| 175 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_mask, |
| 176 | (dlb_drom_flags_t)(DLB_STEAL_CPUS | DLB_SYNC_QUERY)) == DLB_SUCCESS ); | ||
| 177 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&p1_mask) == 1 && CPU_ISSET(0, &p1_mask) ); |
| 178 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&p2_mask) == 1 && CPU_ISSET(3, &p2_mask) ); |
| 179 |
7/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | assert( CPU_COUNT(&p3_mask) == 2 && CPU_ISSET(1, &p3_mask) && CPU_ISSET(2, &p3_mask) ); |
| 180 | |||
| 181 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (pthread_tryjoin_np(thread1, NULL) != 0 |
| 182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | || pthread_tryjoin_np(thread2, NULL) != 0) { |
| 183 | ✗ | return EXIT_FAILURE; | |
| 184 | } | ||
| 185 | 1 | pthread_barrier_destroy(&barrier); | |
| 186 | |||
| 187 | // postfinalize and recover | ||
| 188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p3_pid, /* return-stolen */ true) == DLB_SUCCESS ); |
| 189 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 190 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &original_p1_mask) ); |
| 191 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p2_pid, NULL, &p2_mask) == DLB_SUCCESS ); |
| 192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &original_p2_mask) ); |
| 193 | } | ||
| 194 | |||
| 195 | // synchronous while p1 and p2 are polling. All CPUs, no longer ERROR | ||
| 196 | { | ||
| 197 | 1 | pthread_barrier_init(&barrier, NULL, 3); | |
| 198 | |||
| 199 | 1 | struct thread_data td1 = { .pid = p1_pid, .mask = &p1_mask, .terminate = false }; | |
| 200 | pthread_t thread1; | ||
| 201 | 1 | pthread_create(&thread1, NULL, poll_drom, &td1); | |
| 202 | |||
| 203 | 1 | struct thread_data td2 = { .pid = p2_pid, .mask = &p2_mask, .terminate = false }; | |
| 204 | pthread_t thread2; | ||
| 205 | 1 | pthread_create(&thread2, NULL, poll_drom, &td2); | |
| 206 | |||
| 207 | 1 | cpu_set_t p3_new_mask = { .__bits = {0xf} }; /* [1111] */ | |
| 208 | |||
| 209 | 1 | pthread_barrier_wait(&barrier); | |
| 210 | |||
| 211 | // preinitialize and check masks | ||
| 212 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p3_pid, &p3_new_mask, |
| 213 | (dlb_drom_flags_t)(DLB_STEAL_CPUS | DLB_SYNC_QUERY)) == DLB_SUCCESS ); | ||
| 214 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p1_mask) == 0 ); |
| 215 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p2_mask) == 0 ); |
| 216 | cpu_set_t mask; | ||
| 217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p3_pid, &mask, no_flags) == DLB_SUCCESS ); |
| 218 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&mask, &p3_new_mask) ); |
| 219 | |||
| 220 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (pthread_tryjoin_np(thread1, NULL) != 0 |
| 221 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | || pthread_tryjoin_np(thread2, NULL) != 0) { |
| 222 | ✗ | return EXIT_FAILURE; | |
| 223 | } | ||
| 224 | 1 | pthread_barrier_destroy(&barrier); | |
| 225 | |||
| 226 | // postfinalize and recover | ||
| 227 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p3_pid, /* return-stolen */ true) == DLB_SUCCESS ); |
| 228 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p1_pid, NULL, &p1_mask) == DLB_SUCCESS ); |
| 229 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &original_p1_mask) ); |
| 230 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__polldrom(p2_pid, NULL, &p2_mask) == DLB_SUCCESS ); |
| 231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &original_p2_mask) ); |
| 232 | } | ||
| 233 | |||
| 234 | // Finalize sub-processes | ||
| 235 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p1_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 236 | == DLB_SUCCESS ); | ||
| 237 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 238 | == DLB_SUCCESS ); | ||
| 239 | |||
| 240 | // Partial CPU inheritance: [0-3] -> [1-3],[0] -> [2-3],[0],[1] | ||
| 241 | { | ||
| 242 | cpu_set_t mask; | ||
| 243 | cpu_set_t expected_mask; | ||
| 244 | |||
| 245 | // parent process (p1) pre-initializes full mask | ||
| 246 | 1 | mu_parse_mask("0-3", &p1_mask); | |
| 247 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 248 | |||
| 249 | // p2 inherits CPU 0 | ||
| 250 | 1 | mu_parse_mask("0", &p2_mask); | |
| 251 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 252 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 253 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &mask) ); |
| 254 | |||
| 255 | // p1 still owns CPUs [1-3] | ||
| 256 | 1 | mu_parse_mask("1-3", &expected_mask); | |
| 257 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p1_pid, &mask, no_flags) == DLB_SUCCESS ); |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&mask, &expected_mask) ); |
| 259 | |||
| 260 | // p3 inherits CPU 1 | ||
| 261 | 1 | mu_parse_mask("1", &p3_mask); | |
| 262 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p3_pid, p1_pid, &p3_mask, &mask, SHMEM_KEY, |
| 263 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p3_mask, &mask) ); |
| 265 | |||
| 266 | // p1 still owns CPUs [2-3] | ||
| 267 | 1 | mu_parse_mask("2-3", &expected_mask); | |
| 268 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p1_pid, &mask, no_flags) == DLB_SUCCESS ); |
| 269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&mask, &expected_mask) ); |
| 270 | |||
| 271 | // CPUs [2-3] are still not inherited, clean up is necessary | ||
| 272 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p1_pid, false) == DLB_SUCCESS ); |
| 273 | |||
| 274 | // finalize | ||
| 275 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 276 | == DLB_SUCCESS ); | ||
| 277 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p3_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 278 | == DLB_SUCCESS ); | ||
| 279 | } | ||
| 280 | |||
| 281 | // Inheritance + expansion: [0-2] -> [0-3] | ||
| 282 | { | ||
| 283 | cpu_set_t mask; | ||
| 284 | |||
| 285 | // parent process (p1) pre-initializes [0-2] | ||
| 286 | 1 | mu_parse_mask("0-2", &p1_mask); | |
| 287 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 288 | |||
| 289 | // p2 wants to register [0-3] | ||
| 290 | 1 | mu_parse_mask("0-3", &p2_mask); | |
| 291 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 292 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &mask) ); |
| 294 | |||
| 295 | // p1 is not registered anymore | ||
| 296 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p1_pid, &mask, no_flags) == DLB_ERR_NOPROC ); |
| 297 | |||
| 298 | // finalize | ||
| 299 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 300 | == DLB_SUCCESS ); | ||
| 301 | } | ||
| 302 | |||
| 303 | // Inheritance + expansion: [0-2],[3] -> [0-3] (ERROR) | ||
| 304 | { | ||
| 305 | cpu_set_t mask; | ||
| 306 | |||
| 307 | // parent process (p1) pre-initializes [0-2] | ||
| 308 | 1 | mu_parse_mask("0-2", &p1_mask); | |
| 309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 310 | |||
| 311 | // p3 registers CPU [3] | ||
| 312 | 1 | mu_parse_mask("3", &p3_mask); | |
| 313 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p3_pid, 0, &p3_mask, NULL, SHMEM_KEY, |
| 314 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 315 | |||
| 316 | // p2 wants to register [0-3], ERROR | ||
| 317 | 1 | mu_parse_mask("0-3", &p2_mask); | |
| 318 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 319 | SHMEM_SIZE_MULTIPLIER) == DLB_ERR_PERM ); | ||
| 320 | |||
| 321 | // CPUs [0-2] have not been successfully inherited, clean up | ||
| 322 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__postfinalize(p1_pid, false) == DLB_SUCCESS ); |
| 323 | |||
| 324 | // finalize | ||
| 325 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p3_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 326 | == DLB_SUCCESS ); | ||
| 327 | } | ||
| 328 | |||
| 329 | // Partial inheritance + expansion: [0,2] -> [2],[0-1] -> [0-1],[2-3] | ||
| 330 | { | ||
| 331 | cpu_set_t mask; | ||
| 332 | |||
| 333 | // parent process (p1) pre-initializes [0,2] | ||
| 334 | 1 | mu_parse_mask("0,2", &p1_mask); | |
| 335 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 336 | |||
| 337 | // p2 wants to register [0-1] | ||
| 338 | 1 | mu_parse_mask("0-1", &p2_mask); | |
| 339 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 340 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &mask) ); |
| 342 | |||
| 343 | // p3 wants to register [2-3] | ||
| 344 | 1 | mu_parse_mask("2-3", &p3_mask); | |
| 345 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p3_pid, p1_pid, &p3_mask, &mask, SHMEM_KEY, |
| 346 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 347 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p3_mask, &mask) ); |
| 348 | |||
| 349 | // p1 is not registered anymore | ||
| 350 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p1_pid, &mask, no_flags) == DLB_ERR_NOPROC ); |
| 351 | |||
| 352 | // finalize | ||
| 353 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 354 | == DLB_SUCCESS ); | ||
| 355 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p3_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 356 | == DLB_SUCCESS ); | ||
| 357 | } | ||
| 358 | |||
| 359 | // Inheritance beyond the initial mask: [0] -> [0] -> [0], [1] | ||
| 360 | { | ||
| 361 | cpu_set_t mask; | ||
| 362 | |||
| 363 | // parent process (p1) pre-initializes [0] | ||
| 364 | 1 | mu_parse_mask("0", &p1_mask); | |
| 365 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 366 | |||
| 367 | // p2 wants to register [0] | ||
| 368 | 1 | mu_parse_mask("0", &p2_mask); | |
| 369 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 370 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &mask) ); |
| 372 | |||
| 373 | // p3 wants to register [1] (with p1_pid as preinit!) | ||
| 374 | 1 | mu_parse_mask("1", &p3_mask); | |
| 375 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p3_pid, p1_pid, &p3_mask, &mask, SHMEM_KEY, |
| 376 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 377 | /* mask is only updated if DLB_NOTED */ | ||
| 378 | |||
| 379 | // check that only p2 and p3 are registered | ||
| 380 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p1_pid, &mask, no_flags) == DLB_ERR_NOPROC ); |
| 381 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p2_pid, &mask, no_flags) == DLB_SUCCESS ); |
| 382 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p2_mask, &mask) ); |
| 383 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__getprocessmask(p3_pid, &mask, no_flags) == DLB_SUCCESS ); |
| 384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p3_mask, &mask) ); |
| 385 | |||
| 386 | // finalize | ||
| 387 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 388 | == DLB_SUCCESS ); | ||
| 389 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p3_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 390 | == DLB_SUCCESS ); | ||
| 391 | } | ||
| 392 | |||
| 393 | // Inheritance with an empty mask | ||
| 394 | { | ||
| 395 | cpu_set_t mask; | ||
| 396 | |||
| 397 | // parent process (p1) pre-initializes [0] | ||
| 398 | 1 | mu_parse_mask("0", &p1_mask); | |
| 399 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__preinit(p1_pid, &p1_mask, no_flags) == DLB_SUCCESS ); |
| 400 | |||
| 401 | // p2 wants to register with an empty mask | ||
| 402 | 1 | CPU_ZERO(&p2_mask); | |
| 403 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, p1_pid, &p2_mask, &mask, SHMEM_KEY, |
| 404 | SHMEM_SIZE_MULTIPLIER) == DLB_NOTED ); | ||
| 405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( CPU_EQUAL(&p1_mask, &mask) ); |
| 406 | |||
| 407 | // finalize | ||
| 408 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 409 | == DLB_SUCCESS ); | ||
| 410 | } | ||
| 411 | |||
| 412 | // Finalize external | ||
| 413 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo_ext__finalize() == DLB_SUCCESS ); |
| 414 | |||
| 415 | 1 | mu_finalize(); | |
| 416 | |||
| 417 | 1 | return 0; | |
| 418 | } | ||
| 419 |