| 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 | /* Test that shared memories are cleaned when the process aborts. | ||
| 21 | * The fork is necessary to call the assert_noshm in the destructor | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "unique_shmem.h" | ||
| 25 | #include "test_process.h" | ||
| 26 | |||
| 27 | #include "LB_comm/shmem_cpuinfo.h" | ||
| 28 | #include "LB_core/spd.h" | ||
| 29 | #include "support/debug.h" | ||
| 30 | #include "support/options.h" | ||
| 31 | #include "apis/dlb_errors.h" | ||
| 32 | |||
| 33 | #include <sched.h> | ||
| 34 | #include <unistd.h> | ||
| 35 | #include <assert.h> | ||
| 36 | #include <signal.h> | ||
| 37 | #include <sys/wait.h> | ||
| 38 | |||
| 39 | 1 | int main(int argc, char **argv) { | |
| 40 | // Create a child process | ||
| 41 | 1 | pid_t pid = fork(); | |
| 42 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( pid >= 0 ); |
| 43 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (pid == 0) { |
| 44 | cpu_set_t process_mask; | ||
| 45 | 1 | sched_getaffinity(0, sizeof(cpu_set_t), &process_mask); | |
| 46 | |||
| 47 | // Initialize spd to include PID in the PANIC message | ||
| 48 | subprocess_descriptor_t spd; | ||
| 49 | 1 | spd_enter_dlb(&spd); | |
| 50 | 1 | spd.id = getpid(); | |
| 51 | 1 | options_init(&spd.options, NULL); | |
| 52 | 1 | debug_init(&spd.options); | |
| 53 | |||
| 54 | // Create shared memory | ||
| 55 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__init(pid, 0, &process_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 56 | |||
| 57 | 1 | dlb_test__gcov_dump(); | |
| 58 | ✗ | fatal("This fatal should clean shmems"); | |
| 59 | } | ||
| 60 | |||
| 61 | // Wait child and end execution correctly in order to call destructors | ||
| 62 | int wstatus; | ||
| 63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( waitpid(pid, &wstatus, 0) > 0 ); |
| 64 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGABRT ); |
| 65 | |||
| 66 | 1 | return 0; | |
| 67 | } | ||
| 68 |