| 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 "apis/dlb_sp.h" | ||
| 23 | #include "support/mask_utils.h" | ||
| 24 | |||
| 25 | #include <sched.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <unistd.h> | ||
| 28 | #include <stdlib.h> | ||
| 29 | #include <assert.h> | ||
| 30 | |||
| 31 | static dlb_handler_t handler; | ||
| 32 | static cpu_set_t process_mask; | ||
| 33 | |||
| 34 | ✗ | static void cb_enable_cpu(int cpuid, void *arg) { | |
| 35 | ✗ | CPU_SET(cpuid, &process_mask); | |
| 36 | } | ||
| 37 | |||
| 38 | ✗ | static void cb_disable_cpu(int cpuid, void *arg) { | |
| 39 | ✗ | DLB_LendCpu_sp(handler, cpuid); | |
| 40 | ✗ | CPU_CLR(cpuid, &process_mask); | |
| 41 | } | ||
| 42 | |||
| 43 | 1 | int main( int argc, char **argv ) { | |
| 44 | 1 | CPU_ZERO(&process_mask); | |
| 45 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_SET(0, &process_mask); |
| 46 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_SET(1, &process_mask); |
| 47 | |||
| 48 | 1 | char options[64] = "--no-lewi --shm-key="; | |
| 49 | 1 | strcat(options, SHMEM_KEY); | |
| 50 | |||
| 51 | 1 | handler = DLB_Init_sp(0, &process_mask, options); | |
| 52 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CallbackSet_sp(handler, dlb_callback_disable_cpu, |
| 53 | (dlb_callback_t)cb_disable_cpu, NULL) == DLB_SUCCESS); | ||
| 54 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CallbackSet_sp(handler, dlb_callback_enable_cpu, |
| 55 | (dlb_callback_t)cb_enable_cpu, NULL) == DLB_SUCCESS); | ||
| 56 | dlb_callback_t cb; | ||
| 57 | void *arg; | ||
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CallbackGet_sp(handler, dlb_callback_enable_cpu, &cb, &arg) == DLB_SUCCESS ); |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( cb == (dlb_callback_t)cb_enable_cpu ); |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( arg == NULL ); |
| 61 | |||
| 62 | // Basic enable-disable test | ||
| 63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Disable_sp(handler) == DLB_SUCCESS ); |
| 64 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Lend_sp(handler) == DLB_ERR_NOLEWI ); |
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Enable_sp(handler) == DLB_SUCCESS ); |
| 66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_SetMaxParallelism_sp(handler, 1) == DLB_ERR_NOLEWI ); |
| 67 | |||
| 68 | // Lend | ||
| 69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Lend_sp(handler) == DLB_ERR_NOLEWI ); |
| 70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_LendCpu_sp(handler, 0) == DLB_ERR_NOLEWI ); |
| 71 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_LendCpus_sp(handler, 1) == DLB_ERR_NOLEWI ); |
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_LendCpuMask_sp(handler, &process_mask) == DLB_ERR_NOLEWI ); |
| 73 | |||
| 74 | // Reclaim | ||
| 75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Reclaim_sp(handler) == DLB_ERR_NOLEWI ); |
| 76 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReclaimCpu_sp(handler, 0) == DLB_ERR_NOLEWI ); |
| 77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReclaimCpus_sp(handler, 1) == DLB_ERR_NOLEWI ); |
| 78 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReclaimCpuMask_sp(handler, &process_mask) == DLB_ERR_NOLEWI ); |
| 79 | |||
| 80 | // Acquire | ||
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpu_sp(handler, 0) == DLB_ERR_NOLEWI ); |
| 82 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpus_sp(handler, 1) == DLB_ERR_NOLEWI ); |
| 83 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpuMask_sp(handler, &process_mask) == DLB_ERR_NOLEWI ); |
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpusInMask_sp(handler, 1, &process_mask) == DLB_ERR_NOLEWI ); |
| 85 | |||
| 86 | // Borrow | ||
| 87 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Borrow_sp(handler) == DLB_ERR_NOLEWI ); |
| 88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_BorrowCpu_sp(handler, 0) == DLB_ERR_NOLEWI ); |
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_BorrowCpus_sp(handler, 1) == DLB_ERR_NOLEWI ); |
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_BorrowCpuMask_sp(handler, &process_mask) == DLB_ERR_NOLEWI ); |
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_BorrowCpusInMask_sp(handler, 1, &process_mask) == DLB_ERR_NOLEWI ); |
| 92 | |||
| 93 | // Return | ||
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Return_sp(handler) == DLB_ERR_NOLEWI ); |
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReturnCpu_sp(handler, 0) == DLB_ERR_NOLEWI ); |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReturnCpuMask_sp(handler, &process_mask) == DLB_ERR_NOLEWI ); |
| 97 | |||
| 98 | // Misc | ||
| 99 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_PollDROM_sp(handler, NULL, NULL) == DLB_ERR_NOCOMP ); |
| 100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_SetVariable_sp(handler, "--drom", "1") == DLB_ERR_PERM ); |
| 101 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_SetVariable_sp(handler, "--debug-opts", "foo") == DLB_SUCCESS ); |
| 102 | char value[32]; | ||
| 103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_GetVariable_sp(handler, "--drom", value) == DLB_SUCCESS ); |
| 104 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_PrintVariables_sp(handler, 0) == DLB_SUCCESS ); |
| 105 | |||
| 106 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize_sp(handler) == DLB_SUCCESS ); |
| 107 | |||
| 108 | // Test DLB_Init with empty masks (to not get DLB_ERR_PERM) until shmem is full | ||
| 109 | 1 | strcat(options, " --drom"); /* enable DROM to force shmem_cpuinfo__init */ | |
| 110 | int i; | ||
| 111 | 1 | int shmem_capacity = mu_get_system_size(); | |
| 112 | 1 | dlb_handler_t *handlers = malloc(sizeof(dlb_handler_t) * shmem_capacity); | |
| 113 | cpu_set_t empty_mask; | ||
| 114 | 1 | CPU_ZERO(&empty_mask); | |
| 115 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (i=0; i<shmem_capacity; ++i) { |
| 116 | 2 | handlers[i] = DLB_Init_sp(0, &empty_mask, options); | |
| 117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( handlers[i] != NULL ); |
| 118 | } | ||
| 119 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init_sp(0, &empty_mask, options) == NULL ); |
| 120 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (i=0; i<shmem_capacity; ++i) { |
| 121 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Finalize_sp(handlers[i]) == DLB_SUCCESS ); |
| 122 | } | ||
| 123 | 1 | free(handlers); | |
| 124 | |||
| 125 | // Test DLB_ERR_PERM | ||
| 126 | 1 | handler = DLB_Init_sp(0, &process_mask, options); | |
| 127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( handler != NULL ); |
| 128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init_sp(0, &process_mask, options) == NULL ); |
| 129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize_sp(handler) == DLB_SUCCESS ); |
| 130 | |||
| 131 | 1 | return 0; | |
| 132 | } | ||
| 133 |