| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2023 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 "support/queues.h" | ||
| 21 | #include "support/mask_utils.h" | ||
| 22 | #include "apis/dlb_errors.h" | ||
| 23 | |||
| 24 | #include <stdio.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <assert.h> | ||
| 28 | |||
| 29 | /* Notes: | ||
| 30 | * - Queue sizes are actually QUEUE_*_SIZE - 1 because head != tail | ||
| 31 | * - push operations allow pid == 0 but it may cause confusion with enum NOBODY | ||
| 32 | */ | ||
| 33 | |||
| 34 | typedef struct aux_struct_t { | ||
| 35 | int a; | ||
| 36 | int b; | ||
| 37 | } aux_struct_t; | ||
| 38 | |||
| 39 | #define GENERIC_QUEUE_SIZE 10 | ||
| 40 | |||
| 41 | struct fold_weighted_sum_accum_t { | ||
| 42 | unsigned int step; | ||
| 43 | unsigned int sum; | ||
| 44 | }; | ||
| 45 | |||
| 46 | 10 | void fold_weighted_sum(void *accum, void *curr) { | |
| 47 | 10 | struct fold_weighted_sum_accum_t* a = accum; | |
| 48 | 10 | a->sum += ((aux_struct_t*)curr)->a * a->step; | |
| 49 | 10 | a->step--; | |
| 50 | 10 | } | |
| 51 | |||
| 52 | struct fold_check_all_int_accum_t { | ||
| 53 | int reference; | ||
| 54 | bool all_check; | ||
| 55 | }; | ||
| 56 | |||
| 57 | 2 | void fold_check_all(void *accum, void *curr) { | |
| 58 | 2 | struct fold_check_all_int_accum_t* a = accum; | |
| 59 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (a->all_check) { |
| 60 | 2 | a->all_check = a->reference == *((int*) curr); | |
| 61 | } | ||
| 62 | 2 | } | |
| 63 | |||
| 64 | 1 | int main(int argc, char *argv[]) { | |
| 65 | unsigned int i; | ||
| 66 | pid_t pid; | ||
| 67 | |||
| 68 | enum { SYS_SIZE = 16 }; | ||
| 69 | 1 | mu_init(); | |
| 70 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 71 | |||
| 72 | /* queue_lewi_reqs_t */ | ||
| 73 | { | ||
| 74 | unsigned int howmany; | ||
| 75 | queue_lewi_reqs_t queue; | ||
| 76 | 1 | queue_lewi_reqs_init(&queue); | |
| 77 | |||
| 78 | /* Fill queue with requests from different pids */ | ||
| 79 | 1 | howmany = 3; | |
| 80 |
2/2✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1 times.
|
256 | for (i=0; i<QUEUE_LEWI_REQS_SIZE-1; ++i) { |
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | assert( queue_lewi_reqs_size(&queue) == i ); |
| 82 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | assert( queue_lewi_reqs_push(&queue, i+1, howmany) == DLB_SUCCESS ); |
| 83 | } | ||
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == QUEUE_LEWI_REQS_SIZE-1 ); |
| 85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, i+1, howmany) == DLB_ERR_REQST ); |
| 86 | |||
| 87 | /* Get values */ | ||
| 88 |
2/2✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1 times.
|
256 | for (i=0; i<QUEUE_LEWI_REQS_SIZE-1; ++i) { |
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 255 times.
|
255 | assert( queue_lewi_reqs_get(&queue, i+1) == howmany ); |
| 90 | } | ||
| 91 | |||
| 92 | /* Remove non-existing PID */ | ||
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_remove(&queue, i*2) == 0 ); |
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == QUEUE_LEWI_REQS_SIZE-1 ); |
| 95 | |||
| 96 | /* Empty queue (forwards until N/2) */ | ||
| 97 | 1 | unsigned int queue_size = QUEUE_LEWI_REQS_SIZE-1; | |
| 98 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 1 times.
|
129 | for (i=0; i<QUEUE_LEWI_REQS_SIZE/2; ++i) { |
| 99 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
|
128 | assert( queue_lewi_reqs_remove(&queue, i+1) == howmany ); |
| 100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
|
128 | assert( queue_lewi_reqs_size(&queue) == --queue_size ); |
| 101 | } | ||
| 102 | |||
| 103 | /* Empty queue (backwards until N/2) */ | ||
| 104 |
2/2✓ Branch 0 taken 127 times.
✓ Branch 1 taken 1 times.
|
128 | for (i=QUEUE_LEWI_REQS_SIZE-2; i>=QUEUE_LEWI_REQS_SIZE/2; --i) { |
| 105 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 127 times.
|
127 | assert( queue_lewi_reqs_remove(&queue, i+1) == howmany ); |
| 106 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 127 times.
|
127 | assert( queue_lewi_reqs_size(&queue) == --queue_size ); |
| 107 | } | ||
| 108 | |||
| 109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue_size == 0 ); |
| 110 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 111 | |||
| 112 | /* Remove non-existing PID */ | ||
| 113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_remove(&queue, i*2) == 0 ); |
| 114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 115 | |||
| 116 | /* PID 0 is not valid */ | ||
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 0, 1) == DLB_NOUPDT ); |
| 118 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 119 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_remove(&queue, 0) == 0 ); |
| 120 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 121 | |||
| 122 | /* Pushing en existing entry updates the value, or removes if 0 */ | ||
| 123 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 4 ) == DLB_SUCCESS ); |
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 1 ); |
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 2 ) == DLB_SUCCESS ); |
| 126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 1 ); |
| 127 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 0 ) == DLB_SUCCESS ); |
| 128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 129 | |||
| 130 | /* Push multiple requests from the same pid, size should be stable */ | ||
| 131 | 1 | pid = 12345; | |
| 132 | 1 | howmany = 5; | |
| 133 |
2/2✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
|
513 | for (i=0; i<QUEUE_LEWI_REQS_SIZE*2; ++i) { |
| 134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 512 times.
|
512 | assert( queue_lewi_reqs_push(&queue, pid, howmany) == DLB_SUCCESS ); |
| 135 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 512 times.
|
512 | assert( queue_lewi_reqs_size(&queue) == 1 ); |
| 136 | } | ||
| 137 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_get(&queue, pid) == howmany*QUEUE_LEWI_REQS_SIZE*2 ); |
| 138 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 1 ); |
| 139 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_remove(&queue, pid) == howmany*QUEUE_LEWI_REQS_SIZE*2 ); |
| 140 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 141 | |||
| 142 | /* Push request and ask more than it's in the queue */ | ||
| 143 | { | ||
| 144 | lewi_request_t request; | ||
| 145 | unsigned int num_requests; | ||
| 146 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 5) == DLB_SUCCESS ); |
| 147 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_pop_ncpus(&queue, 42, &request, |
| 148 | &num_requests, 1) == 42-5 ); | ||
| 149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_requests == 1 ); |
| 150 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( request.pid == 111 && request.howmany == 5); |
| 151 | } | ||
| 152 | |||
| 153 | /* Push requests with ncpus '3', '5', '1' and pop 6. After that queue should | ||
| 154 | * contain [1, 2], and output requests should contain [2, 3, 1] */ | ||
| 155 | { | ||
| 156 | enum { max_requests = 3 }; | ||
| 157 | lewi_request_t requests[max_requests]; | ||
| 158 | unsigned int num_requests; | ||
| 159 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 3) == DLB_SUCCESS ); |
| 160 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 222, 5) == DLB_SUCCESS ); |
| 161 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 333, 1) == DLB_SUCCESS ); |
| 162 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_pop_ncpus(&queue, 6, requests, &num_requests, |
| 163 | max_requests) == 0 ); | ||
| 164 | /* Output order is messed but it's not relevant */ | ||
| 165 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_requests == 3 ); |
| 166 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[0].pid == 333 && requests[0].howmany == 1 ); |
| 167 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[1].pid == 111 && requests[1].howmany == 2 ); |
| 168 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[2].pid == 222 && requests[2].howmany == 3 ); |
| 169 | /* Remove remaining entries */ | ||
| 170 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (i=0; i<3; ++i) { |
| 171 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | assert( queue_lewi_reqs_pop_ncpus(&queue, 1, requests, &num_requests, |
| 172 | max_requests) == 0 ); | ||
| 173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | assert( num_requests == 1 ); |
| 174 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | assert( (requests[0].pid == 111 || requests[0].pid == 222) |
| 175 | && requests[0].howmany == 1 ); | ||
| 176 | } | ||
| 177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_pop_ncpus(&queue, 1, requests, &num_requests, |
| 178 | max_requests) == 1 ); | ||
| 179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_requests == 0 ); |
| 180 | } | ||
| 181 | |||
| 182 | /* Try to pop more requests than available */ | ||
| 183 | { | ||
| 184 | enum { max_requests = 3 }; | ||
| 185 | lewi_request_t requests[max_requests]; | ||
| 186 | unsigned int num_requests; | ||
| 187 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 188 | |||
| 189 | /* With only one element */ | ||
| 190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 4 ) == DLB_SUCCESS ); |
| 191 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_pop_ncpus(&queue, 10, requests, &num_requests, |
| 192 | max_requests) == 6 ); | ||
| 193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_requests == 1 ); |
| 194 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[0].pid == 111 && requests[0].howmany == 4 ); |
| 195 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 196 | |||
| 197 | /* With more than one element */ | ||
| 198 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 111, 4 ) == DLB_SUCCESS ); |
| 199 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_push(&queue, 222, 5 ) == DLB_SUCCESS ); |
| 200 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_pop_ncpus(&queue, 10, requests, &num_requests, |
| 201 | max_requests) == 1 ); | ||
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_requests == 2 ); |
| 203 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[0].pid == 111 && requests[0].howmany == 4 ); |
| 204 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( requests[1].pid == 222 && requests[1].howmany == 5 ); |
| 205 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_lewi_reqs_size(&queue) == 0 ); |
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | /* queue_proc_reqs_t */ | ||
| 210 | { | ||
| 211 | queue_proc_reqs_t queue; | ||
| 212 | 1 | queue_proc_reqs_init(&queue); | |
| 213 | |||
| 214 | /* Fill queue with requests from different pids */ | ||
| 215 |
2/2✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 1 times.
|
4096 | for (i=0; i<QUEUE_PROC_REQS_SIZE-1; ++i) { |
| 216 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4095 times.
|
4095 | assert( queue_proc_reqs_size(&queue) == i ); |
| 217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4095 times.
|
4095 | assert( queue_proc_reqs_push(&queue, i+1, 1, NULL) == DLB_NOTED ); |
| 218 | } | ||
| 219 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == QUEUE_PROC_REQS_SIZE-1 ); |
| 220 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, i+1, 1, NULL) == DLB_ERR_REQST ); |
| 221 | |||
| 222 | /* Empty queue */ | ||
| 223 |
2/2✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 1 times.
|
4096 | for (i=0; i<QUEUE_PROC_REQS_SIZE-1; ++i) { |
| 224 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4095 times.
|
4095 | assert( queue_proc_reqs_size(&queue) == QUEUE_PROC_REQS_SIZE-1-i ); |
| 225 | 4095 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 226 | } | ||
| 227 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 0 ); |
| 228 | |||
| 229 | /* Push multiple requests from the same pid, size should be stable */ | ||
| 230 | 1 | pid = 12345; | |
| 231 |
2/2✓ Branch 0 taken 8192 times.
✓ Branch 1 taken 1 times.
|
8193 | for (i=0; i<QUEUE_PROC_REQS_SIZE*2; ++i) { |
| 232 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8192 times.
|
8192 | assert( queue_proc_reqs_push(&queue, pid, 5, NULL) == DLB_NOTED ); |
| 233 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8192 times.
|
8192 | assert( queue_proc_reqs_size(&queue) == 1 ); |
| 234 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8192 times.
|
8192 | assert( queue_proc_reqs_front(&queue)->howmany == 5*(i+1) ); |
| 235 | } | ||
| 236 | |||
| 237 | /* Push some new elements and remove the ones in the middle */ | ||
| 238 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 111, 40, NULL) == DLB_NOTED ); |
| 239 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 2 ); |
| 240 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 222, 43, NULL) == DLB_NOTED ); |
| 241 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 242 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 111, 40, NULL) == DLB_NOTED ); |
| 243 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 4 ); |
| 244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 333, 53, NULL) == DLB_NOTED ); |
| 245 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 5 ); |
| 246 | // remove pid 222 | ||
| 247 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-3].pid == 222 ); |
| 248 | 1 | queue_proc_reqs_remove(&queue, 222); | |
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-3].pid == 0 ); |
| 250 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 5 ); |
| 251 | // remove pid 111 | ||
| 252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-4].pid == 111 ); |
| 253 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-2].pid == 111 ); |
| 254 | 1 | queue_proc_reqs_remove(&queue, 111); | |
| 255 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-4].pid == 0 ); |
| 256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[queue.head-2].pid == 0 ); |
| 257 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 5 ); |
| 258 | |||
| 259 | /* Pop all requests from first element to update tail */ | ||
| 260 |
2/2✓ Branch 0 taken 40960 times.
✓ Branch 1 taken 1 times.
|
40961 | for (i=0; i<QUEUE_PROC_REQS_SIZE*10; ++i) { |
| 261 | 40960 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40960 times.
|
40960 | assert( pid == 12345 ); |
| 263 | } | ||
| 264 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 1 ); |
| 265 | 1 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 266 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 333 ); |
| 267 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 1 ); |
| 268 | |||
| 269 | /* Remove element pushing value 0 */ | ||
| 270 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 333, 0, NULL) == DLB_SUCCESS ); |
| 271 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 0 ); |
| 272 | } | ||
| 273 | |||
| 274 | /* queue_proc_reqs_t with allowed CPUs */ | ||
| 275 | { | ||
| 276 | cpu_set_t allowed; | ||
| 277 | queue_proc_reqs_t queue; | ||
| 278 | 1 | queue_proc_reqs_init(&queue); | |
| 279 | |||
| 280 | /* P1 requests 2 CPUs allowing only {0-3} */ | ||
| 281 | 1 | mu_parse_mask("0-3", &allowed); | |
| 282 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 111, 2, &allowed) == DLB_NOTED ); |
| 283 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 1 ); |
| 284 | |||
| 285 | /* Pop CPU 4 is not successful, but CPU 3 is */ | ||
| 286 | 1 | queue_proc_reqs_get(&queue, &pid, 4); | |
| 287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 0 ); |
| 288 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 1 ); |
| 289 | 1 | queue_proc_reqs_get(&queue, &pid, 3); | |
| 290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 111 ); |
| 291 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 1 ); /* 1 request pending */ |
| 292 | 1 | queue_proc_reqs_get(&queue, &pid, 3); | |
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 111 ); |
| 294 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 0 ); /* 0 requests pending */ |
| 295 | |||
| 296 | /* Push some requests */ | ||
| 297 | 1 | mu_parse_mask("0-7", &allowed); | |
| 298 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 111, 2, &allowed) == DLB_NOTED ); |
| 299 | 1 | mu_parse_mask("8-15", &allowed); | |
| 300 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 222, 1, &allowed) == DLB_NOTED ); |
| 301 | 1 | mu_parse_mask("0-15", &allowed); | |
| 302 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_push(&queue, 333, 1, &allowed) == DLB_NOTED ); |
| 303 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 304 | |||
| 305 | /* Pop requests */ | ||
| 306 | 1 | queue_proc_reqs_get(&queue, &pid, 10); | |
| 307 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 222 ); |
| 308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 309 | 1 | queue_proc_reqs_get(&queue, &pid, 10); | |
| 310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 333 ); |
| 311 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 312 | 1 | queue_proc_reqs_get(&queue, &pid, 10); | |
| 313 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 0 ); |
| 314 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 315 | 1 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 111 ); |
| 317 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 3 ); |
| 318 | 1 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 111 ); |
| 320 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 0 ); |
| 321 | 1 | queue_proc_reqs_get(&queue, &pid, 0); | |
| 322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( pid == 0 ); |
| 323 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_proc_reqs_size(&queue) == 0 ); |
| 324 | } | ||
| 325 | |||
| 326 | /* queue_pids_t */ | ||
| 327 | { | ||
| 328 | queue_pids_t queue; | ||
| 329 | queue_pids_t aux_queue; | ||
| 330 | 1 | queue_pids_init(&queue); | |
| 331 | |||
| 332 | /* Fill queue with requests from different pids */ | ||
| 333 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (i=0; i<QUEUE_PIDS_SIZE-1; ++i) { |
| 334 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | assert( queue_pids_size(&queue) == i ); |
| 335 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | assert( queue_pids_push(&queue, i+1) == DLB_NOTED ); |
| 336 | } | ||
| 337 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == QUEUE_PIDS_SIZE-1 ); |
| 338 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, i+1) == DLB_ERR_REQST ); |
| 339 | |||
| 340 | /* Empty queue */ | ||
| 341 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (i=0; i<QUEUE_PIDS_SIZE-1; ++i) { |
| 342 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | assert( queue_pids_size(&queue) == QUEUE_PIDS_SIZE-1-i ); |
| 343 | 7 | queue_pids_pop(&queue, &pid); | |
| 344 | } | ||
| 345 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 0 ); |
| 346 | |||
| 347 | /* Push some new elements and remove the ones in the middle */ | ||
| 348 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, 111) == DLB_NOTED ); |
| 349 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 1 ); |
| 350 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, 222) == DLB_NOTED ); |
| 351 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 2 ); |
| 352 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, 222) == DLB_NOTED ); |
| 353 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 3 ); |
| 354 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, 111) == DLB_NOTED ); |
| 355 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 4 ); |
| 356 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_push(&queue, 333) == DLB_NOTED ); |
| 357 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 5 ); |
| 358 | 1 | memcpy(&aux_queue, &queue, sizeof(queue)); | |
| 359 | // remove pid 222 | ||
| 360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[0] == 222 ); |
| 361 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[1] == 222 ); |
| 362 | 1 | queue_pids_remove(&queue, 222); | |
| 363 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[0] == 0 ); |
| 364 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[1] == 0 ); |
| 365 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 5 ); |
| 366 | // remove pid 111 | ||
| 367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[2] == 111 ); |
| 368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[7] == 111 ); |
| 369 | 1 | queue_pids_remove(&queue, 111); | |
| 370 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[2] == 0 ); |
| 371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[7] == 0 ); |
| 372 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 1 ); |
| 373 | // hack: restore state to remove 111 first | ||
| 374 | 1 | memcpy(&queue, &aux_queue, sizeof(queue)); | |
| 375 | // remove pid 111 | ||
| 376 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[2] == 111 ); |
| 377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[7] == 111 ); |
| 378 | 1 | queue_pids_remove(&queue, 111); | |
| 379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[2] == 0 ); |
| 380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[7] == 0 ); |
| 381 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 4 ); |
| 382 | // remove pid 222 | ||
| 383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[0] == 222 ); |
| 384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[1] == 222 ); |
| 385 | 1 | queue_pids_remove(&queue, 222); | |
| 386 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[0] == 0 ); |
| 387 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[1] == 0 ); |
| 388 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 1 ); |
| 389 | // remove pid 333 | ||
| 390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[3] == 333 ); |
| 391 | 1 | queue_pids_remove(&queue, 333); | |
| 392 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( queue.queue[3] == 0 ); |
| 393 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue_pids_size(&queue) == 0 ); |
| 394 | } | ||
| 395 | |||
| 396 | /* queue_t with alloc */ | ||
| 397 | { | ||
| 398 | 1 | queue_t *queue = queue__init(sizeof(aux_struct_t), GENERIC_QUEUE_SIZE, | |
| 399 | NULL, QUEUE_ALLOC_OVERWRITE); | ||
| 400 | |||
| 401 | /* Fill queue */ | ||
| 402 | 1 | unsigned int queue_capacity = queue__get_capacity(queue); | |
| 403 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=0; i<queue_capacity; i++) { |
| 404 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_size(queue) == i); |
| 405 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_capacity(queue) == GENERIC_QUEUE_SIZE); |
| 406 | |||
| 407 | 10 | aux_struct_t element = { | |
| 408 | .a = i, | ||
| 409 | 10 | .b = queue_capacity - i, | |
| 410 | }; | ||
| 411 | |||
| 412 | 10 | queue__push_head(queue, &element); | |
| 413 | } | ||
| 414 | |||
| 415 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=queue_capacity; i>0; i--) { |
| 416 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_size(queue) == i); |
| 417 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_capacity(queue) == GENERIC_QUEUE_SIZE); |
| 418 | |||
| 419 | aux_struct_t read_element; | ||
| 420 | 10 | aux_struct_t reff_element = { | |
| 421 | 10 | .a = i - 1, | |
| 422 | 10 | .b = queue_capacity - i + 1, | |
| 423 | }; | ||
| 424 | |||
| 425 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert( queue__take_head(queue, &read_element) == DLB_SUCCESS ); |
| 426 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | assert( |
| 427 | read_element.a == reff_element.a && | ||
| 428 | read_element.b == reff_element.b | ||
| 429 | ); | ||
| 430 | } | ||
| 431 | |||
| 432 | aux_struct_t dummy; | ||
| 433 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue__take_head(queue, &dummy) == DLB_NOUPDT ); |
| 434 | |||
| 435 | 1 | queue__destroy(queue); | |
| 436 | } | ||
| 437 | |||
| 438 | /* queue_t with external storage */ | ||
| 439 | { | ||
| 440 | aux_struct_t storage[GENERIC_QUEUE_SIZE]; | ||
| 441 | 1 | queue_t *queue = queue__init(sizeof(aux_struct_t), GENERIC_QUEUE_SIZE, storage, QUEUE_ALLOC_REALLOC); | |
| 442 | |||
| 443 | // QUEUEU_ALLOC_REALLOC is incompatible with an external storage. | ||
| 444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(queue == NULL); |
| 445 | } | ||
| 446 | { | ||
| 447 | aux_struct_t storage[GENERIC_QUEUE_SIZE]; | ||
| 448 | |||
| 449 | 1 | queue_t *queue = queue__init(sizeof(int), GENERIC_QUEUE_SIZE, storage, QUEUE_ALLOC_FIXED); | |
| 450 | |||
| 451 | // Assert that the queue is empty at the begining | ||
| 452 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 453 | |||
| 454 | 1 | int element = 42; | |
| 455 | int element_taken; | ||
| 456 | |||
| 457 | // Assert that the queue is not empty after some data is added | ||
| 458 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_head(queue, &element) != NULL); |
| 459 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(!queue__is_empty(queue)); |
| 460 | |||
| 461 | // Assert that the queue is empty once the data is taken from the head | ||
| 462 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__take_head(queue, &element_taken) == DLB_SUCCESS); |
| 463 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(element == element_taken); |
| 465 | |||
| 466 | // Assert that the queue is empty once the data is taken from the tail | ||
| 467 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_head(queue, &element) != NULL); |
| 468 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(!queue__is_empty(queue)); |
| 469 | |||
| 470 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__take_tail(queue, &element_taken) == DLB_SUCCESS); |
| 471 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 472 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(element == element_taken); |
| 473 | |||
| 474 | // Check that when we take data into a NULL pointer, data is removed from the queue. | ||
| 475 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_head(queue, &element) != NULL); |
| 476 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__take_head(queue, NULL) == DLB_SUCCESS); |
| 477 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 478 | |||
| 479 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_head(queue, &element) != NULL); |
| 480 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__take_tail(queue, NULL) == DLB_SUCCESS); |
| 481 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 482 | |||
| 483 | // Check that when queue is full no more data can be pushed | ||
| 484 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_empty(queue)); |
| 485 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i = 0; i < GENERIC_QUEUE_SIZE; i++) { |
| 486 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__push_head(queue, &element) != NULL); |
| 487 | } | ||
| 488 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__is_at_capacity(queue)); |
| 489 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_head(queue, &element) == NULL); |
| 490 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(queue__push_tail(queue, &element) == NULL); |
| 491 | |||
| 492 | } | ||
| 493 | { | ||
| 494 | aux_struct_t storage[GENERIC_QUEUE_SIZE]; | ||
| 495 | |||
| 496 | 1 | queue_t *queue = queue__init(sizeof(aux_struct_t), GENERIC_QUEUE_SIZE, storage, QUEUE_ALLOC_FIXED); | |
| 497 | |||
| 498 | /* Fill queue */ | ||
| 499 | 1 | unsigned int queue_capacity = queue__get_capacity(queue); | |
| 500 | 1 | queue_capacity -= 1; | |
| 501 | 1 | queue_capacity /= 2; | |
| 502 | |||
| 503 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i=0; i<queue_capacity; i++) { |
| 504 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(queue__get_size(queue) == i*2); |
| 505 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(queue__get_capacity(queue) == GENERIC_QUEUE_SIZE); |
| 506 | |||
| 507 | 4 | aux_struct_t element = { | |
| 508 | .a = i, | ||
| 509 | 4 | .b = queue_capacity - i, | |
| 510 | }; | ||
| 511 | |||
| 512 | 4 | queue__push_head(queue, &element); | |
| 513 | 4 | queue__push_tail(queue, &element); | |
| 514 | } | ||
| 515 | |||
| 516 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i=queue_capacity; i>0; i--) { |
| 517 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(queue__get_size(queue) == i*2); |
| 518 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(queue__get_capacity(queue) == GENERIC_QUEUE_SIZE); |
| 519 | |||
| 520 | aux_struct_t *peek_element_head, *peek_element_tail; | ||
| 521 | |||
| 522 | aux_struct_t take_element_head, take_element_tail; | ||
| 523 | 4 | aux_struct_t reff_element = { | |
| 524 | 4 | .a = i - 1, | |
| 525 | 4 | .b = queue_capacity - i + 1, | |
| 526 | }; | ||
| 527 | |||
| 528 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( queue__peek_head(queue, (void**) &peek_element_head) == DLB_SUCCESS ); |
| 529 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | assert( |
| 530 | peek_element_head->a == reff_element.a && | ||
| 531 | peek_element_head->b == reff_element.b | ||
| 532 | ); | ||
| 533 | |||
| 534 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( queue__peek_tail(queue, (void**) &peek_element_tail) == DLB_SUCCESS ); |
| 535 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | assert( |
| 536 | peek_element_tail->a == reff_element.a && | ||
| 537 | peek_element_tail->b == reff_element.b | ||
| 538 | ); | ||
| 539 | |||
| 540 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( queue__take_head(queue, &take_element_head) == DLB_SUCCESS ); |
| 541 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | assert( |
| 542 | take_element_head.a == reff_element.a && | ||
| 543 | take_element_head.b == reff_element.b | ||
| 544 | ); | ||
| 545 | |||
| 546 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( queue__take_tail(queue, &take_element_tail) == DLB_SUCCESS ); |
| 547 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | assert( |
| 548 | take_element_tail.a == reff_element.a && | ||
| 549 | take_element_tail.b == reff_element.b | ||
| 550 | ); | ||
| 551 | } | ||
| 552 | |||
| 553 | aux_struct_t dummy; | ||
| 554 | aux_struct_t *dummy_ptr; | ||
| 555 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue__peek_head(queue, (void**) &dummy_ptr) == DLB_NOUPDT ); |
| 556 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue__take_head(queue, &dummy) == DLB_NOUPDT ); |
| 557 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue__peek_tail(queue, (void**) &dummy_ptr) == DLB_NOUPDT ); |
| 558 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( queue__take_tail(queue, &dummy) == DLB_NOUPDT ); |
| 559 | |||
| 560 | /* | ||
| 561 | * Check full queue when the allocator is QUEUE_ALLOC_FIXED. | ||
| 562 | */ | ||
| 563 | 1 | queue_capacity = queue__get_capacity(queue); | |
| 564 | { | ||
| 565 | 1 | aux_struct_t element = { | |
| 566 | .a = i, | ||
| 567 | 1 | .b = queue_capacity - i, | |
| 568 | }; | ||
| 569 | |||
| 570 | 1 | aux_struct_t *elem = queue__push_tail(queue, &element); | |
| 571 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(elem != NULL); |
| 572 | } | ||
| 573 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
|
10 | for (i=1; i<queue_capacity; i++) { |
| 574 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | assert(queue__get_capacity(queue) == GENERIC_QUEUE_SIZE); |
| 575 | |||
| 576 | 9 | aux_struct_t element = { | |
| 577 | .a = i, | ||
| 578 | 9 | .b = queue_capacity - i, | |
| 579 | }; | ||
| 580 | |||
| 581 | 9 | aux_struct_t *elem = queue__push_head(queue, &element); | |
| 582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | assert(elem != NULL); |
| 583 | } | ||
| 584 | { | ||
| 585 | 1 | aux_struct_t element = { | |
| 586 | .a = i, | ||
| 587 | 1 | .b = queue_capacity - i, | |
| 588 | }; | ||
| 589 | |||
| 590 | 1 | aux_struct_t *elem = queue__push_tail(queue, &element); | |
| 591 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(elem == NULL); |
| 592 | } | ||
| 593 | |||
| 594 | 1 | queue__destroy(queue); | |
| 595 | } | ||
| 596 | |||
| 597 | /* queue_t realloc and iterators */ | ||
| 598 | { | ||
| 599 | |||
| 600 | 1 | queue_t *queue = queue__init(sizeof(aux_struct_t), 0, | |
| 601 | NULL, QUEUE_ALLOC_REALLOC); | ||
| 602 | |||
| 603 | /* Fill queue */ | ||
| 604 | 1 | unsigned int queue_capacity = GENERIC_QUEUE_SIZE; | |
| 605 | |||
| 606 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=0; i<queue_capacity; i++) { |
| 607 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_size(queue) == i); |
| 608 | |||
| 609 | 10 | aux_struct_t element = { | |
| 610 | .a = i, | ||
| 611 | 10 | .b = queue_capacity - i, | |
| 612 | }; | ||
| 613 | |||
| 614 | 10 | queue__push_head(queue, &element); | |
| 615 | } | ||
| 616 | |||
| 617 | { | ||
| 618 | 1 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 619 | 1 | struct aux_struct_t * got = queue_iter__get_nth(&iter, 3); | |
| 620 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(got->a == 6); |
| 621 | } | ||
| 622 | |||
| 623 | { | ||
| 624 | 1 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 625 | 1 | struct fold_weighted_sum_accum_t sum = { | |
| 626 | 1 | .step = queue__get_size(queue), | |
| 627 | .sum = 0, | ||
| 628 | }; | ||
| 629 | 1 | queue_iter__foreach(&iter, fold_weighted_sum, &sum); | |
| 630 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(sum.sum == 330); |
| 631 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(sum.step == 0); |
| 632 | } | ||
| 633 | |||
| 634 | 1 | queue__destroy(queue); | |
| 635 | } | ||
| 636 | // Test pushing from the begining and end to make sure unordered reallocation works | ||
| 637 | { | ||
| 638 | |||
| 639 | 1 | queue_t *queue = queue__init(sizeof(int), 0, | |
| 640 | NULL, QUEUE_ALLOC_REALLOC); | ||
| 641 | |||
| 642 | /* Fill queue */ | ||
| 643 | 1 | unsigned int queue_capacity = GENERIC_QUEUE_SIZE/2; | |
| 644 | |||
| 645 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (i=0; i <= queue_capacity; i++) { |
| 646 | 6 | int element = queue_capacity - i; | |
| 647 | 6 | queue__push_tail(queue, &element); | |
| 648 | } | ||
| 649 | |||
| 650 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i=1; i<queue_capacity; i++) { |
| 651 | 4 | int element = queue_capacity + i; | |
| 652 | 4 | queue__push_head(queue, &element); | |
| 653 | } | ||
| 654 | |||
| 655 | int check_array[GENERIC_QUEUE_SIZE]; | ||
| 656 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=0; i<GENERIC_QUEUE_SIZE; i++) { |
| 657 | 10 | check_array[i] = GENERIC_QUEUE_SIZE - i - 1; | |
| 658 | } | ||
| 659 | |||
| 660 | { | ||
| 661 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i = 0; i < GENERIC_QUEUE_SIZE; i++) { |
| 662 | 10 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 663 | 10 | int* got = queue_iter__get_nth(&iter, i); | |
| 664 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | assert(*got == check_array[i]); |
| 665 | } | ||
| 666 | |||
| 667 | // Check getting value past boud from iterator | ||
| 668 | 1 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 669 | 1 | int* got = queue_iter__get_nth(&iter, queue__get_size(queue)+42); | |
| 670 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(got == NULL); |
| 671 | } | ||
| 672 | |||
| 673 | 1 | queue__destroy(queue); | |
| 674 | } | ||
| 675 | { | ||
| 676 | |||
| 677 | 1 | queue_t *queue = queue__init(sizeof(int), 0, | |
| 678 | NULL, QUEUE_ALLOC_REALLOC); | ||
| 679 | |||
| 680 | /* Fill queue */ | ||
| 681 | 1 | unsigned int queue_capacity = GENERIC_QUEUE_SIZE/2; | |
| 682 | |||
| 683 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (i=0; i <= queue_capacity; i++) { |
| 684 | 6 | int element = queue_capacity - i; | |
| 685 | 6 | queue__push_tail(queue, &element); | |
| 686 | } | ||
| 687 | |||
| 688 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (i=1; i<queue_capacity; i++) { |
| 689 | 4 | int element = queue_capacity + i; | |
| 690 | 4 | queue__push_head(queue, &element); | |
| 691 | } | ||
| 692 | |||
| 693 | int check_array[GENERIC_QUEUE_SIZE]; | ||
| 694 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=0; i<GENERIC_QUEUE_SIZE; i++) { |
| 695 | 10 | check_array[i] = GENERIC_QUEUE_SIZE - i - 1; | |
| 696 | } | ||
| 697 | |||
| 698 | { | ||
| 699 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i = 0; i < GENERIC_QUEUE_SIZE; i++) { |
| 700 | 10 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 701 | 10 | int* got = queue_iter__get_nth(&iter, i); | |
| 702 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | assert(*got == check_array[i]); |
| 703 | } | ||
| 704 | } | ||
| 705 | |||
| 706 | 1 | queue__destroy(queue); | |
| 707 | } | ||
| 708 | /* Check the circular buffere feature */ | ||
| 709 | { | ||
| 710 | |||
| 711 | 1 | queue_t *queue = queue__init(sizeof(int), 2, | |
| 712 | NULL, QUEUE_ALLOC_OVERWRITE); | ||
| 713 | |||
| 714 | 1 | int element = 42; | |
| 715 | 1 | queue__push_head(queue, &element); | |
| 716 | 1 | queue__push_head(queue, &element); | |
| 717 | |||
| 718 | int* element_peeked; | ||
| 719 | 1 | queue__peek_head(queue, (void*) &element_peeked); | |
| 720 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(element == *element_peeked); |
| 721 | |||
| 722 | 1 | queue__peek_tail(queue, (void*) &element_peeked); | |
| 723 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(element == *element_peeked); |
| 724 | |||
| 725 | 1 | element = 4242; | |
| 726 | 1 | queue__push_head(queue, &element); | |
| 727 | 1 | queue__push_head(queue, &element); | |
| 728 | |||
| 729 | 1 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(queue); | |
| 730 | |||
| 731 | 1 | struct fold_check_all_int_accum_t check_all = { | |
| 732 | .reference = element, | ||
| 733 | .all_check = true, | ||
| 734 | }; | ||
| 735 | |||
| 736 | 1 | queue_iter__foreach(&iter, fold_check_all, &check_all); | |
| 737 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert(check_all.all_check); |
| 738 | } | ||
| 739 | |||
| 740 | /* queue_t realloc with head & tail != 0 */ | ||
| 741 | { | ||
| 742 | |||
| 743 | 1 | queue_t *queue = queue__init(sizeof(aux_struct_t), 20, | |
| 744 | NULL, QUEUE_ALLOC_OVERWRITE); | ||
| 745 | |||
| 746 | /* Fill queue */ | ||
| 747 | 1 | unsigned int queue_capacity = GENERIC_QUEUE_SIZE; | |
| 748 | |||
| 749 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=0; i<queue_capacity; i++) { |
| 750 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | assert(queue__get_size(queue) == i); |
| 751 | |||
| 752 | 10 | aux_struct_t element = { | |
| 753 | .a = i, | ||
| 754 | 10 | .b = queue_capacity - i, | |
| 755 | }; | ||
| 756 | |||
| 757 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | if (i % 2) queue__push_head(queue, &element); |
| 758 | 5 | else queue__push_tail(queue, &element); | |
| 759 | } | ||
| 760 | |||
| 761 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for (i=queue_capacity; i>0; i--) { |
| 762 | aux_struct_t take_element; | ||
| 763 | 10 | aux_struct_t reff_element = { | |
| 764 | 10 | .a = i - 1, | |
| 765 | 10 | .b = queue_capacity - i + 1, | |
| 766 | }; | ||
| 767 | |||
| 768 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | if ((i-1) % 2) queue__take_head(queue, &take_element); |
| 769 | 5 | else queue__take_tail(queue, &take_element); | |
| 770 | |||
| 771 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | assert( |
| 772 | take_element.a == reff_element.a && | ||
| 773 | take_element.b == reff_element.b | ||
| 774 | ); | ||
| 775 | } | ||
| 776 | |||
| 777 | 1 | queue__destroy(queue); | |
| 778 | } | ||
| 779 | |||
| 780 | 1 | mu_finalize(); | |
| 781 | |||
| 782 | 1 | return 0; | |
| 783 | } | ||
| 784 |