| 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 "support/mask_utils.h" | ||
| 24 | |||
| 25 | #include <assert.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | #include <sys/wait.h> | ||
| 28 | |||
| 29 | /* Create two shmems with different color */ | ||
| 30 | |||
| 31 | enum { SHMEM_VERSION = 42 }; | ||
| 32 | |||
| 33 | struct data { | ||
| 34 | int foo; | ||
| 35 | }; | ||
| 36 | |||
| 37 | 1 | int main(int argc, char **argv) { | |
| 38 | struct data *shdata1, *shdata2; | ||
| 39 | shmem_handler_t *handler1, *handler2; | ||
| 40 | |||
| 41 | // Create a shmem | ||
| 42 | 1 | handler1 = shmem_init((void**)&shdata1, | |
| 43 | 1 | &(const shmem_props_t) { | |
| 44 | .size = sizeof(struct data), | ||
| 45 | .name = "test", | ||
| 46 | .key = SHMEM_KEY, | ||
| 47 | .version = SHMEM_VERSION, | ||
| 48 | .color = 1, | ||
| 49 | }); | ||
| 50 | 1 | shdata1->foo = 1; | |
| 51 | |||
| 52 | // Try to create another shmem with the same name and same color | ||
| 53 | 1 | handler2 = shmem_init((void**)&shdata2, | |
| 54 | 1 | &(const shmem_props_t) { | |
| 55 | .size = sizeof(struct data), | ||
| 56 | .name = "test", | ||
| 57 | .key = SHMEM_KEY, | ||
| 58 | .version = SHMEM_VERSION, | ||
| 59 | .color = 1, | ||
| 60 | }); | ||
| 61 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( handler2 != NULL && handler1 != handler2 ); |
| 62 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( shdata2 != NULL && shdata1 != shdata2 ); |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( shdata1->foo == shdata2->foo ); |
| 64 | |||
| 65 | // Create another shmem with same name name, but different color (different regions) | ||
| 66 | 1 | handler2 = shmem_init((void**)&shdata2, | |
| 67 | 1 | &(const shmem_props_t) { | |
| 68 | .size = sizeof(struct data), | ||
| 69 | .name = "test", | ||
| 70 | .key = SHMEM_KEY, | ||
| 71 | .version = SHMEM_VERSION, | ||
| 72 | .color = 2, | ||
| 73 | }); | ||
| 74 | 1 | shdata2->foo = 2; | |
| 75 | assert( &shdata1 != &shdata2 ); | ||
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( shdata1->foo != shdata2->foo ); |
| 77 | |||
| 78 | 1 | shmem_finalize(handler1, NULL); | |
| 79 | 1 | shmem_finalize(handler2, NULL); | |
| 80 | |||
| 81 | 1 | return 0; | |
| 82 | } | ||
| 83 |