1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright 2008 Chris Johns (chrisj@rtems.org) |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | /** |
---|
29 | * BD Buffer test. |
---|
30 | * |
---|
31 | * Please add more tests |
---|
32 | */ |
---|
33 | |
---|
34 | #ifdef HAVE_CONFIG_H |
---|
35 | #include "config.h" |
---|
36 | #endif |
---|
37 | |
---|
38 | #include <errno.h> |
---|
39 | #include <fcntl.h> |
---|
40 | #include <setjmp.h> |
---|
41 | #include <stdio.h> |
---|
42 | #include <stdlib.h> |
---|
43 | #include <string.h> |
---|
44 | #include <sys/types.h> |
---|
45 | #include <sys/stat.h> |
---|
46 | #include <inttypes.h> |
---|
47 | #include <unistd.h> |
---|
48 | |
---|
49 | #include <rtems.h> |
---|
50 | #include <rtems/chain.h> |
---|
51 | #include <rtems/error.h> |
---|
52 | #include <rtems/bdbuf.h> |
---|
53 | |
---|
54 | #include <bsp.h> |
---|
55 | |
---|
56 | #include "tmacros.h" |
---|
57 | |
---|
58 | const char rtems_test_name[] = "BLOCK 6"; |
---|
59 | |
---|
60 | /* forward declarations to avoid warnings */ |
---|
61 | static rtems_task Init(rtems_task_argument argument); |
---|
62 | |
---|
63 | #define BDBUF_DISKS 2 |
---|
64 | #define BDBUF_SIZE 1024 |
---|
65 | |
---|
66 | #if 0 |
---|
67 | const rtems_bdbuf_config rtems_bdbuf_configuration = |
---|
68 | { |
---|
69 | 5, /* max_read_ahead_blocks */ |
---|
70 | 5, /* max_write_blocks */ |
---|
71 | 15, /* swapout_priority */ |
---|
72 | 250, /* swapout_period */ |
---|
73 | 1000, /* swap_block_hold */ |
---|
74 | 0, /* swapout_workers */ |
---|
75 | 15, /* swapout_worker_priority */ |
---|
76 | 1024 * 1024, /* size */ |
---|
77 | 512, /* buffer_min */ |
---|
78 | 4096 /* buffer_max */ |
---|
79 | }; |
---|
80 | #endif |
---|
81 | |
---|
82 | /** |
---|
83 | * The bdbuf disk driver base name. |
---|
84 | */ |
---|
85 | #define BDBUF_DISK_DEVICE_BASE_NAME "/dev/bddisk" |
---|
86 | |
---|
87 | /** |
---|
88 | * The actions the disk driver handles. |
---|
89 | */ |
---|
90 | typedef enum bdbuf_disk_action |
---|
91 | { |
---|
92 | BDBUF_DISK_NOOP, |
---|
93 | BDBUF_DISK_WAIT, |
---|
94 | BDBUF_DISK_SLEEP, |
---|
95 | BDBUF_DISK_BLOCKS_INORDER |
---|
96 | } bdbuf_disk_action; |
---|
97 | |
---|
98 | /** |
---|
99 | * The BDBUF Disk driver. |
---|
100 | */ |
---|
101 | typedef struct bdbuf_disk |
---|
102 | { |
---|
103 | const char* name; |
---|
104 | uint32_t minor; |
---|
105 | rtems_id lock; |
---|
106 | uint32_t block_size; |
---|
107 | uint32_t block_count; |
---|
108 | bdbuf_disk_action driver_action; |
---|
109 | const char* watcher_name; |
---|
110 | rtems_id watcher; |
---|
111 | int watch_count; |
---|
112 | const char* waiting_name; |
---|
113 | rtems_id waiting; |
---|
114 | uint32_t driver_sleep; |
---|
115 | rtems_disk_device* dd; |
---|
116 | } bdbuf_disk; |
---|
117 | |
---|
118 | /* |
---|
119 | * A disk drive for each pool. |
---|
120 | */ |
---|
121 | static bdbuf_disk bdbuf_disks[BDBUF_DISKS]; |
---|
122 | |
---|
123 | /** |
---|
124 | * Task control. |
---|
125 | */ |
---|
126 | typedef struct bdbuf_task_control |
---|
127 | { |
---|
128 | bool die; |
---|
129 | const char* name; |
---|
130 | rtems_id task; |
---|
131 | rtems_id master; |
---|
132 | int test; |
---|
133 | bdbuf_disk *bdd; |
---|
134 | bool passed; |
---|
135 | } bdbuf_task_control; |
---|
136 | |
---|
137 | #define BDBUF_TEST_TASKS (3) |
---|
138 | |
---|
139 | #define BDBUF_TEST_STACK_SIZE (2 * RTEMS_MINIMUM_STACK_SIZE) |
---|
140 | |
---|
141 | /** |
---|
142 | * Seconds as milli-seconds. |
---|
143 | */ |
---|
144 | #define BDBUF_SECONDS(msec) ((msec) * 1000UL) |
---|
145 | |
---|
146 | /** |
---|
147 | * Print the status code description and return true if true. |
---|
148 | * |
---|
149 | * @param sc The RTEMS status code. |
---|
150 | * @retval true The status code is successful. |
---|
151 | * @retval false The status code is not successful. |
---|
152 | */ |
---|
153 | static bool |
---|
154 | bdbuf_test_print_sc (rtems_status_code sc, bool newline) |
---|
155 | { |
---|
156 | if (newline) |
---|
157 | printf ("%s\n", rtems_status_text (sc)); |
---|
158 | else |
---|
159 | printf ("%s", rtems_status_text (sc)); |
---|
160 | return sc == RTEMS_SUCCESSFUL; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * BDBuf disk device driver lock. |
---|
165 | */ |
---|
166 | static bool |
---|
167 | bdbuf_disk_lock (bdbuf_disk* bdd) |
---|
168 | { |
---|
169 | rtems_status_code sc; |
---|
170 | sc = rtems_semaphore_obtain (bdd->lock, RTEMS_WAIT, 0); |
---|
171 | if (sc != RTEMS_SUCCESSFUL) |
---|
172 | { |
---|
173 | printf ("disk ioctl: lock failed: "); |
---|
174 | bdbuf_test_print_sc (sc, true); |
---|
175 | return false; |
---|
176 | } |
---|
177 | return true; |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * BDBuf disk device driver unlock. |
---|
182 | */ |
---|
183 | static bool |
---|
184 | bdbuf_disk_unlock (bdbuf_disk* bdd) |
---|
185 | { |
---|
186 | rtems_status_code sc; |
---|
187 | sc = rtems_semaphore_release (bdd->lock); |
---|
188 | if (sc != RTEMS_SUCCESSFUL) |
---|
189 | { |
---|
190 | printf ("disk ioctl: unlock failed: "); |
---|
191 | bdbuf_test_print_sc (sc, true); |
---|
192 | return false; |
---|
193 | } |
---|
194 | return true; |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * BDBUf wait for the wait event. |
---|
199 | */ |
---|
200 | static rtems_status_code |
---|
201 | bdbuf_wait (const char* who, unsigned long timeout) |
---|
202 | { |
---|
203 | rtems_status_code sc; |
---|
204 | rtems_event_set out; |
---|
205 | sc = rtems_event_receive (RTEMS_EVENT_0, |
---|
206 | RTEMS_WAIT | RTEMS_EVENT_ANY, |
---|
207 | RTEMS_MICROSECONDS_TO_TICKS (timeout * 1000), |
---|
208 | &out); |
---|
209 | if (sc != RTEMS_SUCCESSFUL) |
---|
210 | { |
---|
211 | printf ("%s: wait: receive failed: ", who); |
---|
212 | bdbuf_test_print_sc (sc, true); |
---|
213 | } |
---|
214 | else if ((out & RTEMS_EVENT_0) == 0) |
---|
215 | { |
---|
216 | printf ("%s: wait: received wrong event: %08" PRIxrtems_event_set, who, out); |
---|
217 | } |
---|
218 | return sc; |
---|
219 | } |
---|
220 | |
---|
221 | /** |
---|
222 | * BDBUf send wait event. |
---|
223 | */ |
---|
224 | static bool |
---|
225 | bdbuf_send_wait_event (const char* task, const char* msg, rtems_id id) |
---|
226 | { |
---|
227 | printf ("%s: %s: %08" PRIxrtems_id ": ", task, msg, id); |
---|
228 | return bdbuf_test_print_sc (rtems_event_send (id, RTEMS_EVENT_0), true); |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * BDBUf wait for the wait event. |
---|
233 | */ |
---|
234 | static rtems_status_code |
---|
235 | bdbuf_watch (unsigned long timeout) |
---|
236 | { |
---|
237 | rtems_status_code sc; |
---|
238 | rtems_event_set out; |
---|
239 | sc = rtems_event_receive (RTEMS_EVENT_1, |
---|
240 | RTEMS_WAIT | RTEMS_EVENT_ANY, |
---|
241 | RTEMS_MICROSECONDS_TO_TICKS (timeout * 1000), |
---|
242 | &out); |
---|
243 | if (sc != RTEMS_SUCCESSFUL) |
---|
244 | { |
---|
245 | printf ("watch: receive failed: "); |
---|
246 | bdbuf_test_print_sc (sc, true); |
---|
247 | } |
---|
248 | else if ((out & RTEMS_EVENT_1) == 0) |
---|
249 | { |
---|
250 | printf ("watch: received wrong event: %08" PRIxrtems_event_set, out); |
---|
251 | } |
---|
252 | return sc; |
---|
253 | } |
---|
254 | |
---|
255 | /** |
---|
256 | * BDBUf send wait event. |
---|
257 | */ |
---|
258 | static bool |
---|
259 | bdbuf_send_watch_event (const char* task, const char* msg, rtems_id id) |
---|
260 | { |
---|
261 | printf ("%s: %s: %08" PRIxrtems_id ": ", task, msg, id); |
---|
262 | return bdbuf_test_print_sc (rtems_event_send (id, RTEMS_EVENT_1), true); |
---|
263 | } |
---|
264 | |
---|
265 | /** |
---|
266 | * Set up a disk driver watch. |
---|
267 | */ |
---|
268 | static void |
---|
269 | bdbuf_set_disk_driver_watch (bdbuf_task_control* tc, int count) |
---|
270 | { |
---|
271 | /* |
---|
272 | * Set up a disk watch and wait for the write to happen. |
---|
273 | */ |
---|
274 | bdbuf_disk_lock (tc->bdd); |
---|
275 | tc->bdd->watcher_name = tc->name; |
---|
276 | tc->bdd->watcher = tc->task; |
---|
277 | tc->bdd->watch_count = count; |
---|
278 | bdbuf_disk_unlock (tc->bdd); |
---|
279 | } |
---|
280 | |
---|
281 | /** |
---|
282 | * Clear the disk driver watch. |
---|
283 | */ |
---|
284 | static void |
---|
285 | bdbuf_clear_disk_driver_watch (bdbuf_task_control* tc) |
---|
286 | { |
---|
287 | /* |
---|
288 | * Set up a disk watch and wait for the write to happen. |
---|
289 | */ |
---|
290 | bdbuf_disk_lock (tc->bdd); |
---|
291 | tc->bdd->watcher_name = 0; |
---|
292 | tc->bdd->watcher = 0; |
---|
293 | tc->bdd->watch_count = 0; |
---|
294 | bdbuf_disk_unlock (tc->bdd); |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * Wait for the disk driver watch. |
---|
299 | */ |
---|
300 | static bool |
---|
301 | bdbuf_disk_driver_watch_wait (bdbuf_task_control* tc, unsigned long msecs) |
---|
302 | { |
---|
303 | bool passed = true; |
---|
304 | rtems_status_code sc = bdbuf_watch (msecs); |
---|
305 | if (sc != RTEMS_SUCCESSFUL) |
---|
306 | { |
---|
307 | printf ("%s: driver watch: driver wait: ", tc->name); |
---|
308 | passed = bdbuf_test_print_sc (sc, true); |
---|
309 | } |
---|
310 | bdbuf_clear_disk_driver_watch (tc); |
---|
311 | return passed; |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * Set the disk driver action. |
---|
316 | */ |
---|
317 | static void |
---|
318 | bdbuf_set_disk_driver_action (bdbuf_task_control* tc, bdbuf_disk_action action) |
---|
319 | { |
---|
320 | /* |
---|
321 | * Set up a disk action. |
---|
322 | */ |
---|
323 | bdbuf_disk_lock (tc->bdd); |
---|
324 | tc->bdd->driver_action = action; |
---|
325 | bdbuf_disk_unlock (tc->bdd); |
---|
326 | } |
---|
327 | |
---|
328 | /** |
---|
329 | * BDBUF Sleep. |
---|
330 | */ |
---|
331 | static bool |
---|
332 | bdbuf_sleep (unsigned long msecs) |
---|
333 | { |
---|
334 | rtems_status_code sc; |
---|
335 | sc = rtems_task_wake_after (RTEMS_MICROSECONDS_TO_TICKS (msecs * 1000)); |
---|
336 | if (sc != RTEMS_SUCCESSFUL) |
---|
337 | { |
---|
338 | printf ("sleep wake after failed: "); |
---|
339 | bdbuf_test_print_sc (sc, true); |
---|
340 | return false; |
---|
341 | } |
---|
342 | return true; |
---|
343 | } |
---|
344 | |
---|
345 | /** |
---|
346 | * Initialise a task control. |
---|
347 | */ |
---|
348 | static void |
---|
349 | bdbuf_task_control_init (int task, |
---|
350 | bdbuf_task_control* tc, |
---|
351 | rtems_id master) |
---|
352 | { |
---|
353 | char name[6]; |
---|
354 | sprintf (name, "bdt%d", task); |
---|
355 | |
---|
356 | tc->die = false; |
---|
357 | tc->name = strdup (name); /* leaks */ |
---|
358 | tc->task = 0; |
---|
359 | tc->master = master; |
---|
360 | tc->test = 0; |
---|
361 | tc->bdd = NULL; |
---|
362 | tc->passed = false; |
---|
363 | } |
---|
364 | |
---|
365 | static bool |
---|
366 | bdbuf_disk_ioctl_watcher (bdbuf_disk* bdd, int update) |
---|
367 | { |
---|
368 | /* |
---|
369 | * Always wake the watcher. |
---|
370 | */ |
---|
371 | if (bdd->watcher) |
---|
372 | { |
---|
373 | if (bdd->watch_count) |
---|
374 | { |
---|
375 | if (update > bdd->watch_count) |
---|
376 | bdd->watch_count -= update; |
---|
377 | else |
---|
378 | bdd->watch_count = 0; |
---|
379 | } |
---|
380 | |
---|
381 | if (bdd->watch_count == 0) |
---|
382 | { |
---|
383 | bdbuf_send_watch_event (bdd->watcher_name, |
---|
384 | "disk ioctl: wake watcher", |
---|
385 | bdd->watcher); |
---|
386 | bdd->watcher = 0; |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | return true; |
---|
391 | } |
---|
392 | |
---|
393 | |
---|
394 | static bool |
---|
395 | bdbuf_disk_ioctl_process (bdbuf_disk* bdd, rtems_blkdev_request* req) |
---|
396 | { |
---|
397 | bool result = true; |
---|
398 | int b; |
---|
399 | |
---|
400 | /* |
---|
401 | * Perform the requested action. |
---|
402 | */ |
---|
403 | switch (bdd->driver_action) |
---|
404 | { |
---|
405 | case BDBUF_DISK_NOOP: |
---|
406 | break; |
---|
407 | |
---|
408 | case BDBUF_DISK_WAIT: |
---|
409 | if (bdd->waiting) |
---|
410 | printf ("disk ioctl: bad waiter: %s:%08" PRIxrtems_id "\n", |
---|
411 | bdd->waiting_name, bdd->waiting); |
---|
412 | bdd->waiting_name = "bdd"; |
---|
413 | |
---|
414 | bdd->waiting = rtems_task_self (); |
---|
415 | |
---|
416 | if (bdbuf_disk_unlock (bdd)) |
---|
417 | result = bdbuf_wait (bdd->name, 0) == RTEMS_SUCCESSFUL; |
---|
418 | else |
---|
419 | result = false; |
---|
420 | |
---|
421 | /* |
---|
422 | * Ignore any error if one happens. |
---|
423 | */ |
---|
424 | bdbuf_disk_lock (bdd); |
---|
425 | break; |
---|
426 | |
---|
427 | case BDBUF_DISK_SLEEP: |
---|
428 | printf ("disk ioctl: sleeping: %" PRId32 " msecs\n", |
---|
429 | bdd->driver_sleep); |
---|
430 | result = bdbuf_sleep (bdd->driver_sleep); |
---|
431 | break; |
---|
432 | |
---|
433 | case BDBUF_DISK_BLOCKS_INORDER: |
---|
434 | printf ("disk ioctl: multi-block order check: count = %" PRId32 "\n", |
---|
435 | req->bufnum); |
---|
436 | for (b = 0; b < (req->bufnum - 1); b++) |
---|
437 | if (req->bufs[b].block >= req->bufs[b + 1].block) |
---|
438 | printf ("disk ioctl: out of order: index:%d "\ |
---|
439 | "(%" PRIdrtems_blkdev_bnum " >= %" PRIdrtems_blkdev_bnum "\n", |
---|
440 | b, req->bufs[b].block, req->bufs[b + 1].block); |
---|
441 | break; |
---|
442 | |
---|
443 | default: |
---|
444 | printf ("disk ioctl: invalid action: %d\n", |
---|
445 | bdd->driver_action); |
---|
446 | result = false; |
---|
447 | break; |
---|
448 | } |
---|
449 | |
---|
450 | return result; |
---|
451 | } |
---|
452 | |
---|
453 | static bool |
---|
454 | bdbuf_disk_ioctl_leave (bdbuf_disk* bdd, int buffer_count) |
---|
455 | { |
---|
456 | /* |
---|
457 | * Handle the watcher. |
---|
458 | */ |
---|
459 | bdbuf_disk_ioctl_watcher (bdd, buffer_count); |
---|
460 | |
---|
461 | return true; |
---|
462 | } |
---|
463 | |
---|
464 | /** |
---|
465 | * BDBuf disk IOCTL handler. |
---|
466 | * |
---|
467 | * @param dd Disk device. |
---|
468 | * @param req IOCTL request code. |
---|
469 | * @param argp IOCTL argument. |
---|
470 | * @retval The IOCTL return value |
---|
471 | */ |
---|
472 | static int |
---|
473 | bdbuf_disk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp) |
---|
474 | { |
---|
475 | rtems_blkdev_request *r = argp; |
---|
476 | bdbuf_disk *bdd = rtems_disk_get_driver_data (dd); |
---|
477 | |
---|
478 | errno = 0; |
---|
479 | |
---|
480 | if (!bdbuf_disk_lock (bdd)) |
---|
481 | { |
---|
482 | errno = EIO; |
---|
483 | } |
---|
484 | else |
---|
485 | { |
---|
486 | switch (req) |
---|
487 | { |
---|
488 | case RTEMS_BLKIO_REQUEST: |
---|
489 | switch (r->req) |
---|
490 | { |
---|
491 | case RTEMS_BLKDEV_REQ_READ: |
---|
492 | if (!bdbuf_disk_ioctl_process (bdd, r)) |
---|
493 | rtems_blkdev_request_done(r, RTEMS_IO_ERROR); |
---|
494 | else |
---|
495 | { |
---|
496 | rtems_blkdev_sg_buffer* sg = r->bufs; |
---|
497 | uint32_t block = RTEMS_BLKDEV_START_BLOCK (r); |
---|
498 | uint32_t b; |
---|
499 | int32_t remains; |
---|
500 | |
---|
501 | remains = r->bufnum * bdd->block_size; |
---|
502 | |
---|
503 | for (b = 0; b < r->bufnum; b++, block++, sg++) |
---|
504 | { |
---|
505 | uint32_t length = sg->length; |
---|
506 | |
---|
507 | if (sg->length != bdd->block_size) |
---|
508 | if (length > bdd->block_size) |
---|
509 | length = bdd->block_size; |
---|
510 | |
---|
511 | memset (sg->buffer, block, length); |
---|
512 | |
---|
513 | remains -= length; |
---|
514 | } |
---|
515 | |
---|
516 | rtems_blkdev_request_done (r, RTEMS_SUCCESSFUL); |
---|
517 | } |
---|
518 | bdbuf_disk_ioctl_leave (bdd, r->bufnum); |
---|
519 | break; |
---|
520 | |
---|
521 | case RTEMS_BLKDEV_REQ_WRITE: |
---|
522 | if (!bdbuf_disk_ioctl_process (bdd, r)) |
---|
523 | rtems_blkdev_request_done(r, RTEMS_IO_ERROR); |
---|
524 | else |
---|
525 | rtems_blkdev_request_done(r, RTEMS_SUCCESSFUL); |
---|
526 | bdbuf_disk_ioctl_leave (bdd, r->bufnum); |
---|
527 | break; |
---|
528 | |
---|
529 | default: |
---|
530 | errno = EINVAL; |
---|
531 | break; |
---|
532 | } |
---|
533 | break; |
---|
534 | |
---|
535 | default: |
---|
536 | rtems_blkdev_ioctl (dd, req, argp); |
---|
537 | break; |
---|
538 | } |
---|
539 | |
---|
540 | if (!bdbuf_disk_unlock (bdd)) |
---|
541 | errno = EIO; |
---|
542 | } |
---|
543 | |
---|
544 | return errno == 0 ? 0 : -1; |
---|
545 | } |
---|
546 | |
---|
547 | static rtems_status_code |
---|
548 | bdbuf_disk_initialize(void) |
---|
549 | { |
---|
550 | uint32_t minor; |
---|
551 | |
---|
552 | printf ("register disks\n"); |
---|
553 | |
---|
554 | for (minor = 0; minor < BDBUF_DISKS; minor++) |
---|
555 | { |
---|
556 | char name[sizeof (BDBUF_DISK_DEVICE_BASE_NAME) + 10]; |
---|
557 | bdbuf_disk* bdd = &bdbuf_disks[minor]; |
---|
558 | rtems_status_code sc; |
---|
559 | int fd; |
---|
560 | int rv; |
---|
561 | |
---|
562 | snprintf (name, sizeof (name), |
---|
563 | BDBUF_DISK_DEVICE_BASE_NAME "%" PRIu32, minor); |
---|
564 | |
---|
565 | bdd->name = strdup (name); |
---|
566 | bdd->minor = minor; |
---|
567 | |
---|
568 | printf ("disk init: %s\n", bdd->name); |
---|
569 | printf ("disk lock: "); |
---|
570 | |
---|
571 | sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'D', 'K'), 1, |
---|
572 | RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | |
---|
573 | RTEMS_INHERIT_PRIORITY, 0, &bdd->lock); |
---|
574 | if (!bdbuf_test_print_sc (sc, true)) |
---|
575 | return RTEMS_IO_ERROR; |
---|
576 | |
---|
577 | bdd->block_size = 512 * (minor + 1); |
---|
578 | bdd->block_count = BDBUF_SIZE * (minor + 1); |
---|
579 | |
---|
580 | sc = rtems_blkdev_create(name, bdd->block_size, bdd->block_count, |
---|
581 | bdbuf_disk_ioctl, bdd); |
---|
582 | if (sc != RTEMS_SUCCESSFUL) |
---|
583 | { |
---|
584 | printf ("disk init: create phys failed: "); |
---|
585 | bdbuf_test_print_sc (sc, true); |
---|
586 | return sc; |
---|
587 | } |
---|
588 | |
---|
589 | fd = open(name, O_RDWR); |
---|
590 | rtems_test_assert(fd >= 0); |
---|
591 | |
---|
592 | rv = rtems_disk_fd_get_disk_device(fd, &bdd->dd); |
---|
593 | rtems_test_assert(rv == 0); |
---|
594 | |
---|
595 | rv = close(fd); |
---|
596 | rtems_test_assert(rv == 0); |
---|
597 | } |
---|
598 | |
---|
599 | return RTEMS_SUCCESSFUL; |
---|
600 | } |
---|
601 | |
---|
602 | static bool |
---|
603 | bdbuf_tests_create_task (bdbuf_task_control* tc, |
---|
604 | rtems_task_priority priority, |
---|
605 | rtems_task_entry entry_point) |
---|
606 | { |
---|
607 | rtems_status_code sc; |
---|
608 | |
---|
609 | printf ("creating task: %s: priority: %" PRIdrtems_task_priority ": ", |
---|
610 | tc->name, priority); |
---|
611 | |
---|
612 | sc = rtems_task_create (rtems_build_name (tc->name[0], tc->name[1], |
---|
613 | tc->name[2], tc->name[3]), |
---|
614 | priority, |
---|
615 | BDBUF_TEST_STACK_SIZE, |
---|
616 | RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, |
---|
617 | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR, |
---|
618 | &tc->task); |
---|
619 | if (!bdbuf_test_print_sc (sc, true)) |
---|
620 | return false; |
---|
621 | |
---|
622 | printf ("starting task: %s: ", tc->name); |
---|
623 | |
---|
624 | sc = rtems_task_start (tc->task, entry_point, (rtems_task_argument) tc); |
---|
625 | |
---|
626 | return bdbuf_test_print_sc (sc, true); |
---|
627 | } |
---|
628 | |
---|
629 | /** |
---|
630 | * Get the block 0 buffer twice. The first time it is requested it |
---|
631 | * will be taken from the empty list and returned to the LRU list. |
---|
632 | * The second time it will be removed from the LRU list. |
---|
633 | */ |
---|
634 | static void |
---|
635 | bdbuf_tests_task_0_test_1 (bdbuf_task_control* tc) |
---|
636 | { |
---|
637 | rtems_status_code sc; |
---|
638 | bool passed; |
---|
639 | int i; |
---|
640 | rtems_bdbuf_buffer* bd; |
---|
641 | |
---|
642 | /* |
---|
643 | * Set task control's passed to false to handle a timeout. |
---|
644 | */ |
---|
645 | tc->passed = false; |
---|
646 | passed = true; |
---|
647 | |
---|
648 | for (i = 0; (i < 2) && passed; i++) |
---|
649 | { |
---|
650 | printf ("%s: rtems_bdbuf_get[0]: ", tc->name); |
---|
651 | sc = rtems_bdbuf_get (tc->bdd->dd, 0, &bd); |
---|
652 | if (!bdbuf_test_print_sc (sc, true)) |
---|
653 | { |
---|
654 | passed = false; |
---|
655 | break; |
---|
656 | } |
---|
657 | |
---|
658 | printf ("%s: rtems_bdbuf_release[0]: ", tc->name); |
---|
659 | sc = rtems_bdbuf_release (bd); |
---|
660 | if (!bdbuf_test_print_sc (sc, true)) |
---|
661 | { |
---|
662 | passed = false; |
---|
663 | break; |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | tc->passed = passed; |
---|
668 | tc->test = 0; |
---|
669 | } |
---|
670 | |
---|
671 | /** |
---|
672 | * Get the blocks 0 -> 4 and hold them. Wake the master to tell it was have the |
---|
673 | * buffers then wait for the master to tell us to release a single buffer. |
---|
674 | * Task 1 will be block waiting for each buffer. It is a higher priority. |
---|
675 | */ |
---|
676 | static void |
---|
677 | bdbuf_tests_task_0_test_2 (bdbuf_task_control* tc) |
---|
678 | { |
---|
679 | rtems_status_code sc; |
---|
680 | bool passed; |
---|
681 | int i; |
---|
682 | rtems_bdbuf_buffer* bd; |
---|
683 | rtems_chain_control buffers; |
---|
684 | |
---|
685 | /* |
---|
686 | * Set task control's passed to false to handle a timeout. |
---|
687 | */ |
---|
688 | tc->passed = false; |
---|
689 | passed = true; |
---|
690 | |
---|
691 | /* |
---|
692 | * Get the blocks 0 -> 4 and hold them. |
---|
693 | */ |
---|
694 | rtems_chain_initialize_empty (&buffers); |
---|
695 | |
---|
696 | for (i = 0; (i < 5) && passed; i++) |
---|
697 | { |
---|
698 | printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i); |
---|
699 | sc = rtems_bdbuf_get (tc->bdd->dd, i, &bd); |
---|
700 | if (!bdbuf_test_print_sc (sc, true)) |
---|
701 | passed = false; |
---|
702 | |
---|
703 | rtems_chain_append (&buffers, &bd->link); |
---|
704 | } |
---|
705 | |
---|
706 | /* |
---|
707 | * Wake the master to tell it we have the buffers. |
---|
708 | */ |
---|
709 | bdbuf_send_wait_event (tc->name, "wake master", tc->master); |
---|
710 | |
---|
711 | if (passed) |
---|
712 | { |
---|
713 | /* |
---|
714 | * For each buffer we hold wait until the master wakes us |
---|
715 | * and then return it. Task 2 will block waiting for this |
---|
716 | * buffer. It is a higher priority task. |
---|
717 | */ |
---|
718 | for (i = 0; (i < 5) && passed; i++) |
---|
719 | { |
---|
720 | sc = bdbuf_wait (tc->name, BDBUF_SECONDS (5)); |
---|
721 | if (sc != RTEMS_SUCCESSFUL) |
---|
722 | { |
---|
723 | printf ("%s: wait failed: ", tc->name); |
---|
724 | bdbuf_test_print_sc (sc, true); |
---|
725 | passed = false; |
---|
726 | break; |
---|
727 | } |
---|
728 | else |
---|
729 | { |
---|
730 | printf ("%s: rtems_bdbuf_release[%d]: unblocks task 1\n", |
---|
731 | tc->name, i); |
---|
732 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
733 | sc = rtems_bdbuf_release (bd); |
---|
734 | printf ("%s: rtems_bdbuf_release[%d]: ", tc->name, i); |
---|
735 | if (!bdbuf_test_print_sc (sc, true)) |
---|
736 | { |
---|
737 | passed = false; |
---|
738 | break; |
---|
739 | } |
---|
740 | } |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | tc->passed = passed; |
---|
745 | tc->test = 0; |
---|
746 | } |
---|
747 | |
---|
748 | /** |
---|
749 | * Read the block 5 from the disk modify it then release it modified. |
---|
750 | */ |
---|
751 | static void |
---|
752 | bdbuf_tests_task_0_test_3 (bdbuf_task_control* tc) |
---|
753 | { |
---|
754 | rtems_status_code sc; |
---|
755 | bool passed; |
---|
756 | rtems_bdbuf_buffer* bd; |
---|
757 | |
---|
758 | /* |
---|
759 | * Set task control's passed to false to handle a timeout. |
---|
760 | */ |
---|
761 | tc->passed = false; |
---|
762 | passed = true; |
---|
763 | |
---|
764 | bdbuf_disk_lock (tc->bdd); |
---|
765 | tc->bdd->driver_action = BDBUF_DISK_NOOP; |
---|
766 | bdbuf_disk_unlock (tc->bdd); |
---|
767 | |
---|
768 | /* |
---|
769 | * Read the buffer and then release it. |
---|
770 | */ |
---|
771 | printf ("%s: rtems_bdbuf_read[5]: ", tc->name); |
---|
772 | sc = rtems_bdbuf_read (tc->bdd->dd, 5, &bd); |
---|
773 | if ((passed = bdbuf_test_print_sc (sc, true))) |
---|
774 | { |
---|
775 | printf ("%s: rtems_bdbuf_release_modified[5]: ", tc->name); |
---|
776 | sc = rtems_bdbuf_release_modified (bd); |
---|
777 | passed = bdbuf_test_print_sc (sc, true); |
---|
778 | } |
---|
779 | |
---|
780 | /* |
---|
781 | * Read the buffer again and then just release. The buffer should |
---|
782 | * be maintained as modified. |
---|
783 | */ |
---|
784 | printf ("%s: rtems_bdbuf_read[5]: ", tc->name); |
---|
785 | sc = rtems_bdbuf_read (tc->bdd->dd, 5, &bd); |
---|
786 | if ((passed = bdbuf_test_print_sc (sc, true))) |
---|
787 | { |
---|
788 | printf ("%s: rtems_bdbuf_release[5]: ", tc->name); |
---|
789 | sc = rtems_bdbuf_release (bd); |
---|
790 | passed = bdbuf_test_print_sc (sc, true); |
---|
791 | } |
---|
792 | |
---|
793 | /* |
---|
794 | * Set up a disk watch and wait for the write to happen. |
---|
795 | */ |
---|
796 | bdbuf_set_disk_driver_watch (tc, 1); |
---|
797 | passed = bdbuf_disk_driver_watch_wait (tc, BDBUF_SECONDS (5)); |
---|
798 | |
---|
799 | tc->passed = passed; |
---|
800 | tc->test = 0; |
---|
801 | } |
---|
802 | |
---|
803 | static size_t |
---|
804 | bdbuf_test_buffer_count (void) |
---|
805 | { |
---|
806 | return rtems_bdbuf_configuration.size / rtems_bdbuf_configuration.buffer_min; |
---|
807 | } |
---|
808 | |
---|
809 | /** |
---|
810 | * Get all the blocks in the pool and hold them. Wake the master to tell it was |
---|
811 | * have the buffers then wait for the master to tell us to release them. |
---|
812 | */ |
---|
813 | static void |
---|
814 | bdbuf_tests_task_0_test_4 (bdbuf_task_control* tc) |
---|
815 | { |
---|
816 | rtems_status_code sc; |
---|
817 | bool passed; |
---|
818 | size_t i; |
---|
819 | rtems_bdbuf_buffer* bd; |
---|
820 | rtems_chain_control buffers; |
---|
821 | size_t num = bdbuf_test_buffer_count (); |
---|
822 | |
---|
823 | /* |
---|
824 | * Set task control's passed to false to handle a timeout. |
---|
825 | */ |
---|
826 | tc->passed = false; |
---|
827 | passed = true; |
---|
828 | |
---|
829 | /* |
---|
830 | * Clear any disk settings. |
---|
831 | */ |
---|
832 | bdbuf_clear_disk_driver_watch (tc); |
---|
833 | bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP); |
---|
834 | |
---|
835 | /* |
---|
836 | * Get the blocks 0 -> 4 and hold them. |
---|
837 | */ |
---|
838 | rtems_chain_initialize_empty (&buffers); |
---|
839 | |
---|
840 | for (i = 0; (i < num) && passed; i++) |
---|
841 | { |
---|
842 | printf ("%s: rtems_bdbuf_read[%zd]: ", tc->name, i); |
---|
843 | sc = rtems_bdbuf_read (tc->bdd->dd, i, &bd); |
---|
844 | if (!bdbuf_test_print_sc (sc, true)) |
---|
845 | passed = false; |
---|
846 | |
---|
847 | rtems_chain_append (&buffers, &bd->link); |
---|
848 | } |
---|
849 | |
---|
850 | /* |
---|
851 | * Wake the master to tell it we have the buffers. |
---|
852 | */ |
---|
853 | bdbuf_send_wait_event (tc->name, "wake master", tc->master); |
---|
854 | |
---|
855 | if (passed) |
---|
856 | { |
---|
857 | bdbuf_sleep (250); |
---|
858 | |
---|
859 | bdbuf_set_disk_driver_watch (tc, num / 2); |
---|
860 | |
---|
861 | /* |
---|
862 | * Release half the buffers, wait 500msecs then release the |
---|
863 | * remainder. This tests the swap out timer on each buffer. |
---|
864 | */ |
---|
865 | printf ("%s: rtems_bdbuf_release_modified[0]: unblocks task 1\n", |
---|
866 | tc->name); |
---|
867 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
868 | sc = rtems_bdbuf_release_modified (bd); |
---|
869 | printf ("%s: rtems_bdbuf_release_modified[0]: ", tc->name); |
---|
870 | passed = bdbuf_test_print_sc (sc, true); |
---|
871 | if (passed) |
---|
872 | { |
---|
873 | for (i = 1; (i < (num / 2)) && passed; i++) |
---|
874 | { |
---|
875 | printf ("%s: rtems_bdbuf_release_modified[%zd]: " \ |
---|
876 | "unblocks task 1\n", tc->name, i); |
---|
877 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
878 | sc = rtems_bdbuf_release_modified (bd); |
---|
879 | printf ("%s: rtems_bdbuf_release_modified[%zd]: ", tc->name, i); |
---|
880 | passed = bdbuf_test_print_sc (sc, true); |
---|
881 | if (!passed) |
---|
882 | break; |
---|
883 | } |
---|
884 | |
---|
885 | if (passed) |
---|
886 | { |
---|
887 | passed = bdbuf_disk_driver_watch_wait (tc, BDBUF_SECONDS (5)); |
---|
888 | |
---|
889 | if (passed) |
---|
890 | { |
---|
891 | bdbuf_sleep (500); |
---|
892 | |
---|
893 | bdbuf_set_disk_driver_watch (tc, num / 2); |
---|
894 | |
---|
895 | for (i = 0; (i < (num / 2)) && passed; i++) |
---|
896 | { |
---|
897 | printf ("%s: rtems_bdbuf_release_modified[%zd]: ", |
---|
898 | tc->name, i + (num / 2)); |
---|
899 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
900 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), |
---|
901 | true); |
---|
902 | if (!passed) |
---|
903 | break; |
---|
904 | } |
---|
905 | |
---|
906 | passed = bdbuf_disk_driver_watch_wait (tc, BDBUF_SECONDS (5)); |
---|
907 | |
---|
908 | if (passed) |
---|
909 | { |
---|
910 | if (!rtems_chain_is_empty (&buffers)) |
---|
911 | { |
---|
912 | passed = false; |
---|
913 | printf ("%s: buffer chain not empty\n", tc->name); |
---|
914 | } |
---|
915 | } |
---|
916 | } |
---|
917 | } |
---|
918 | } |
---|
919 | } |
---|
920 | |
---|
921 | tc->passed = passed; |
---|
922 | tc->test = 0; |
---|
923 | } |
---|
924 | |
---|
925 | static void |
---|
926 | bdbuf_tests_task_0_test_5 (bdbuf_task_control* tc) |
---|
927 | { |
---|
928 | bdbuf_tests_task_0_test_4 (tc); |
---|
929 | } |
---|
930 | |
---|
931 | static void |
---|
932 | bdbuf_tests_task_0_test_6 (bdbuf_task_control* tc) |
---|
933 | { |
---|
934 | rtems_status_code sc; |
---|
935 | bool passed; |
---|
936 | int i; |
---|
937 | rtems_bdbuf_buffer* bd; |
---|
938 | rtems_chain_control buffers; |
---|
939 | |
---|
940 | /* |
---|
941 | * Set task control's passed to false to handle a timeout. |
---|
942 | */ |
---|
943 | tc->passed = false; |
---|
944 | passed = true; |
---|
945 | |
---|
946 | /* |
---|
947 | * Clear any disk settings. |
---|
948 | */ |
---|
949 | bdbuf_clear_disk_driver_watch (tc); |
---|
950 | bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP); |
---|
951 | |
---|
952 | /* |
---|
953 | * Get the blocks 0 -> 4 and hold them. |
---|
954 | */ |
---|
955 | rtems_chain_initialize_empty (&buffers); |
---|
956 | |
---|
957 | for (i = 0; (i < 5) && passed; i++) |
---|
958 | { |
---|
959 | printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i); |
---|
960 | sc = rtems_bdbuf_get (tc->bdd->dd, i, &bd); |
---|
961 | if (!bdbuf_test_print_sc (sc, true)) |
---|
962 | passed = false; |
---|
963 | |
---|
964 | rtems_chain_append (&buffers, &bd->link); |
---|
965 | } |
---|
966 | |
---|
967 | for (i = 0; (i < 4) && passed; i++) |
---|
968 | { |
---|
969 | printf ("%s: rtems_bdbuf_release_modified[%d]: ", |
---|
970 | tc->name, i); |
---|
971 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
972 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), |
---|
973 | true); |
---|
974 | } |
---|
975 | |
---|
976 | if (passed) |
---|
977 | { |
---|
978 | printf ("%s: rtems_bdbuf_sync[%d]: ", tc->name, i); |
---|
979 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
980 | |
---|
981 | passed = bdbuf_test_print_sc (rtems_bdbuf_sync (bd), true); |
---|
982 | } |
---|
983 | |
---|
984 | tc->passed = passed; |
---|
985 | tc->test = 0; |
---|
986 | } |
---|
987 | |
---|
988 | static void |
---|
989 | bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc) |
---|
990 | { |
---|
991 | rtems_status_code sc; |
---|
992 | bool passed; |
---|
993 | int i; |
---|
994 | rtems_bdbuf_buffer* bd; |
---|
995 | rtems_chain_control buffers; |
---|
996 | |
---|
997 | /* |
---|
998 | * Set task control's passed to false to handle a timeout. |
---|
999 | */ |
---|
1000 | tc->passed = false; |
---|
1001 | passed = true; |
---|
1002 | |
---|
1003 | /* |
---|
1004 | * Clear any disk settings. |
---|
1005 | */ |
---|
1006 | bdbuf_clear_disk_driver_watch (tc); |
---|
1007 | bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP); |
---|
1008 | |
---|
1009 | /* |
---|
1010 | * Get the blocks 0 -> 4 and hold them. |
---|
1011 | */ |
---|
1012 | rtems_chain_initialize_empty (&buffers); |
---|
1013 | |
---|
1014 | for (i = 0; (i < 5) && passed; i++) |
---|
1015 | { |
---|
1016 | printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i); |
---|
1017 | sc = rtems_bdbuf_get (tc->bdd->dd, i, &bd); |
---|
1018 | if (!bdbuf_test_print_sc (sc, true)) |
---|
1019 | passed = false; |
---|
1020 | |
---|
1021 | rtems_chain_append (&buffers, &bd->link); |
---|
1022 | } |
---|
1023 | |
---|
1024 | for (i = 0; (i < 5) && passed; i++) |
---|
1025 | { |
---|
1026 | printf ("%s: rtems_bdbuf_release_modified[%d]: ", |
---|
1027 | tc->name, i); |
---|
1028 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
1029 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), |
---|
1030 | true); |
---|
1031 | } |
---|
1032 | |
---|
1033 | if (passed) |
---|
1034 | { |
---|
1035 | printf ("%s: rtems_bdbuf_syncdev[%" PRIu32 ": ", |
---|
1036 | tc->name, |
---|
1037 | tc->bdd->minor); |
---|
1038 | passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (tc->bdd->dd), true); |
---|
1039 | } |
---|
1040 | |
---|
1041 | tc->passed = passed; |
---|
1042 | tc->test = 0; |
---|
1043 | } |
---|
1044 | |
---|
1045 | static void |
---|
1046 | bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc) |
---|
1047 | { |
---|
1048 | rtems_status_code sc; |
---|
1049 | bool passed; |
---|
1050 | int i; |
---|
1051 | rtems_bdbuf_buffer* bd; |
---|
1052 | rtems_chain_control buffers; |
---|
1053 | rtems_chain_node* node; |
---|
1054 | rtems_chain_node* pnode; |
---|
1055 | |
---|
1056 | /* |
---|
1057 | * Set task control's passed to false to handle a timeout. |
---|
1058 | */ |
---|
1059 | tc->passed = false; |
---|
1060 | passed = true; |
---|
1061 | |
---|
1062 | /* |
---|
1063 | * Clear any disk settings. |
---|
1064 | */ |
---|
1065 | bdbuf_clear_disk_driver_watch (tc); |
---|
1066 | bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP); |
---|
1067 | |
---|
1068 | /* |
---|
1069 | * Get the blocks 0 -> 4 and hold them. |
---|
1070 | */ |
---|
1071 | rtems_chain_initialize_empty (&buffers); |
---|
1072 | |
---|
1073 | for (i = 0; (i < 5) && passed; i++) |
---|
1074 | { |
---|
1075 | printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i); |
---|
1076 | sc = rtems_bdbuf_get (tc->bdd->dd, i, &bd); |
---|
1077 | if (!bdbuf_test_print_sc (sc, true)) |
---|
1078 | passed = false; |
---|
1079 | |
---|
1080 | rtems_chain_append (&buffers, &bd->link); |
---|
1081 | } |
---|
1082 | |
---|
1083 | node = rtems_chain_tail (&buffers); |
---|
1084 | node = node->previous; |
---|
1085 | |
---|
1086 | bd = (rtems_bdbuf_buffer*) node; |
---|
1087 | pnode = node->previous; |
---|
1088 | rtems_chain_extract (node); |
---|
1089 | node = pnode; |
---|
1090 | printf ("%s: rtems_bdbuf_release_modified[4]: ", tc->name); |
---|
1091 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), true); |
---|
1092 | |
---|
1093 | bd = (rtems_bdbuf_buffer*) node; |
---|
1094 | pnode = node->previous; |
---|
1095 | rtems_chain_extract (node); |
---|
1096 | node = pnode; |
---|
1097 | printf ("%s: rtems_bdbuf_release_modified[3]: ", tc->name); |
---|
1098 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), true); |
---|
1099 | |
---|
1100 | for (i = 0; (i < 3) && passed; i++) |
---|
1101 | { |
---|
1102 | printf ("%s: rtems_bdbuf_release_modified[%d]: ", |
---|
1103 | tc->name, i); |
---|
1104 | bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers); |
---|
1105 | passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), |
---|
1106 | true); |
---|
1107 | } |
---|
1108 | |
---|
1109 | if (passed) |
---|
1110 | { |
---|
1111 | /* |
---|
1112 | * Check the block order. |
---|
1113 | */ |
---|
1114 | bdbuf_set_disk_driver_action (tc, BDBUF_DISK_BLOCKS_INORDER); |
---|
1115 | |
---|
1116 | printf ("%s: rtems_bdbuf_syncdev[%" PRIu32 "]: checking order\n", |
---|
1117 | tc->name, |
---|
1118 | tc->bdd->minor); |
---|
1119 | sc = rtems_bdbuf_syncdev (tc->bdd->dd); |
---|
1120 | printf ("%s: rtems_bdbuf_syncdev[%" PRIu32 "]: ", |
---|
1121 | tc->name, |
---|
1122 | tc->bdd->minor); |
---|
1123 | passed = bdbuf_test_print_sc (sc, true); |
---|
1124 | } |
---|
1125 | |
---|
1126 | tc->passed = passed; |
---|
1127 | tc->test = 0; |
---|
1128 | } |
---|
1129 | |
---|
1130 | static void |
---|
1131 | bdbuf_tests_task_0 (rtems_task_argument arg) |
---|
1132 | { |
---|
1133 | bdbuf_task_control* tc = (bdbuf_task_control*) arg; |
---|
1134 | |
---|
1135 | while (!tc->die) |
---|
1136 | { |
---|
1137 | switch (tc->test) |
---|
1138 | { |
---|
1139 | case 0: |
---|
1140 | /* |
---|
1141 | * Wait for the next test. |
---|
1142 | */ |
---|
1143 | bdbuf_wait (tc->name, 0); |
---|
1144 | break; |
---|
1145 | |
---|
1146 | case 1: |
---|
1147 | bdbuf_tests_task_0_test_1 (tc); |
---|
1148 | break; |
---|
1149 | |
---|
1150 | case 2: |
---|
1151 | bdbuf_tests_task_0_test_2 (tc); |
---|
1152 | break; |
---|
1153 | |
---|
1154 | case 3: |
---|
1155 | bdbuf_tests_task_0_test_3 (tc); |
---|
1156 | break; |
---|
1157 | |
---|
1158 | case 4: |
---|
1159 | bdbuf_tests_task_0_test_4 (tc); |
---|
1160 | break; |
---|
1161 | |
---|
1162 | case 5: |
---|
1163 | bdbuf_tests_task_0_test_5 (tc); |
---|
1164 | break; |
---|
1165 | |
---|
1166 | case 6: |
---|
1167 | bdbuf_tests_task_0_test_6 (tc); |
---|
1168 | break; |
---|
1169 | |
---|
1170 | case 7: |
---|
1171 | bdbuf_tests_task_0_test_7 (tc); |
---|
1172 | break; |
---|
1173 | |
---|
1174 | case 8: |
---|
1175 | bdbuf_tests_task_0_test_8 (tc); |
---|
1176 | break; |
---|
1177 | |
---|
1178 | default: |
---|
1179 | /* |
---|
1180 | * Invalid test for this task. An error. |
---|
1181 | */ |
---|
1182 | printf ("%s: invalid test: %d\n", tc->name, tc->test); |
---|
1183 | tc->passed = false; |
---|
1184 | tc->test = 0; |
---|
1185 | break; |
---|
1186 | } |
---|
1187 | } |
---|
1188 | |
---|
1189 | printf ("%s: delete task\n", tc->name); |
---|
1190 | rtems_task_exit(); |
---|
1191 | } |
---|
1192 | |
---|
1193 | /** |
---|
1194 | * Get the blocks 0 -> 4 and release them. Task 0 should be holding |
---|
1195 | * each one. |
---|
1196 | */ |
---|
1197 | static void |
---|
1198 | bdbuf_tests_ranged_get_release (bdbuf_task_control* tc, |
---|
1199 | bool wake_master, |
---|
1200 | int lower, |
---|
1201 | int upper) |
---|
1202 | { |
---|
1203 | rtems_status_code sc; |
---|
1204 | bool passed; |
---|
1205 | int i; |
---|
1206 | rtems_bdbuf_buffer* bd; |
---|
1207 | |
---|
1208 | /* |
---|
1209 | * Set task control's passed to false to handle a timeout. |
---|
1210 | */ |
---|
1211 | tc->passed = false; |
---|
1212 | passed = true; |
---|
1213 | |
---|
1214 | for (i = lower; (i < upper) && passed; i++) |
---|
1215 | { |
---|
1216 | printf ("%s: rtems_bdbuf_get[%d]: blocking ...\n", tc->name, i); |
---|
1217 | sc = rtems_bdbuf_get (tc->bdd->dd, i, &bd); |
---|
1218 | printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i); |
---|
1219 | if (!bdbuf_test_print_sc (sc, true)) |
---|
1220 | { |
---|
1221 | passed = false; |
---|
1222 | break; |
---|
1223 | } |
---|
1224 | |
---|
1225 | printf ("%s: rtems_bdbuf_release[%d]: ", tc->name, i); |
---|
1226 | sc = rtems_bdbuf_release (bd); |
---|
1227 | if (!bdbuf_test_print_sc (sc, true)) |
---|
1228 | { |
---|
1229 | passed = false; |
---|
1230 | break; |
---|
1231 | } |
---|
1232 | |
---|
1233 | /* |
---|
1234 | * Wake the master to tell it we have finished. |
---|
1235 | */ |
---|
1236 | if (wake_master) |
---|
1237 | bdbuf_send_wait_event (tc->name, "wake master", tc->master); |
---|
1238 | } |
---|
1239 | |
---|
1240 | tc->passed = passed; |
---|
1241 | tc->test = 0; |
---|
1242 | } |
---|
1243 | |
---|
1244 | static void |
---|
1245 | bdbuf_tests_task_1 (rtems_task_argument arg) |
---|
1246 | { |
---|
1247 | bdbuf_task_control* tc = (bdbuf_task_control*) arg; |
---|
1248 | |
---|
1249 | while (!tc->die) |
---|
1250 | { |
---|
1251 | switch (tc->test) |
---|
1252 | { |
---|
1253 | case 0: |
---|
1254 | /* |
---|
1255 | * Wait for the next test. |
---|
1256 | */ |
---|
1257 | bdbuf_wait (tc->name, 0); |
---|
1258 | break; |
---|
1259 | |
---|
1260 | case 2: |
---|
1261 | bdbuf_tests_ranged_get_release (tc, false, 0, 5); |
---|
1262 | break; |
---|
1263 | |
---|
1264 | case 4: |
---|
1265 | bdbuf_tests_ranged_get_release (tc, false, 0, 9); |
---|
1266 | break; |
---|
1267 | |
---|
1268 | case 5: |
---|
1269 | bdbuf_tests_ranged_get_release (tc, false, 20, 25); |
---|
1270 | break; |
---|
1271 | |
---|
1272 | default: |
---|
1273 | /* |
---|
1274 | * Invalid test for this task. An error. |
---|
1275 | */ |
---|
1276 | printf ("%s: invalid test: %d\n", tc->name, tc->test); |
---|
1277 | tc->passed = false; |
---|
1278 | tc->test = 0; |
---|
1279 | break; |
---|
1280 | } |
---|
1281 | } |
---|
1282 | |
---|
1283 | printf ("%s: delete task\n", tc->name); |
---|
1284 | rtems_task_exit(); |
---|
1285 | } |
---|
1286 | |
---|
1287 | /** |
---|
1288 | * Get the blocks 0 -> 4 and release them. Task 0 should be holding |
---|
1289 | * each one. |
---|
1290 | */ |
---|
1291 | static void |
---|
1292 | bdbuf_tests_task_2_test_2 (bdbuf_task_control* tc) |
---|
1293 | { |
---|
1294 | /* |
---|
1295 | * Use task 1's test 2. They are the same. |
---|
1296 | */ |
---|
1297 | bdbuf_tests_ranged_get_release (tc, true, 0, 5); |
---|
1298 | } |
---|
1299 | |
---|
1300 | static void |
---|
1301 | bdbuf_tests_task_2 (rtems_task_argument arg) |
---|
1302 | { |
---|
1303 | bdbuf_task_control* tc = (bdbuf_task_control*) arg; |
---|
1304 | |
---|
1305 | while (!tc->die) |
---|
1306 | { |
---|
1307 | switch (tc->test) |
---|
1308 | { |
---|
1309 | case 0: |
---|
1310 | /* |
---|
1311 | * Wait for the next test. |
---|
1312 | */ |
---|
1313 | bdbuf_wait (tc->name, 0); |
---|
1314 | break; |
---|
1315 | |
---|
1316 | case 2: |
---|
1317 | bdbuf_tests_task_2_test_2 (tc); |
---|
1318 | break; |
---|
1319 | |
---|
1320 | default: |
---|
1321 | /* |
---|
1322 | * Invalid test for this task. An error. |
---|
1323 | */ |
---|
1324 | printf ("%s: invalid test: %d\n", tc->name, tc->test); |
---|
1325 | tc->passed = false; |
---|
1326 | tc->test = 0; |
---|
1327 | break; |
---|
1328 | } |
---|
1329 | } |
---|
1330 | |
---|
1331 | printf ("%s: delete task\n", tc->name); |
---|
1332 | rtems_task_exit(); |
---|
1333 | } |
---|
1334 | |
---|
1335 | /** |
---|
1336 | * Table of task entry points. |
---|
1337 | */ |
---|
1338 | static rtems_task_entry bdbuf_test_tasks[] = |
---|
1339 | { |
---|
1340 | bdbuf_tests_task_0, |
---|
1341 | bdbuf_tests_task_1, |
---|
1342 | bdbuf_tests_task_2 |
---|
1343 | }; |
---|
1344 | |
---|
1345 | #define BDBUF_TESTS_PRI_HIGH (30) |
---|
1346 | |
---|
1347 | /** |
---|
1348 | * Wait for the all tests to finish. This is signalled by the test |
---|
1349 | * number becoming 0. |
---|
1350 | */ |
---|
1351 | static bool |
---|
1352 | bdbuf_tests_finished (bdbuf_task_control* tasks) |
---|
1353 | { |
---|
1354 | uint32_t time = 0; |
---|
1355 | bool finished = false; |
---|
1356 | |
---|
1357 | while (time < (10 * 4)) |
---|
1358 | { |
---|
1359 | int t; |
---|
1360 | |
---|
1361 | finished = true; |
---|
1362 | |
---|
1363 | for (t = 0; t < BDBUF_TEST_TASKS; t++) |
---|
1364 | if (tasks[t].test) |
---|
1365 | { |
---|
1366 | finished = false; |
---|
1367 | break; |
---|
1368 | } |
---|
1369 | |
---|
1370 | if (finished) |
---|
1371 | break; |
---|
1372 | |
---|
1373 | bdbuf_sleep (250); |
---|
1374 | time++; |
---|
1375 | } |
---|
1376 | |
---|
1377 | if (!finished) |
---|
1378 | printf ("master: test timed out\n"); |
---|
1379 | else |
---|
1380 | { |
---|
1381 | int t; |
---|
1382 | for (t = 0; t < BDBUF_TEST_TASKS; t++) |
---|
1383 | if (!tasks[0].passed) |
---|
1384 | { |
---|
1385 | finished = false; |
---|
1386 | break; |
---|
1387 | } |
---|
1388 | } |
---|
1389 | |
---|
1390 | return finished; |
---|
1391 | } |
---|
1392 | |
---|
1393 | /** |
---|
1394 | * Test 1. |
---|
1395 | * |
---|
1396 | * # Get task 0 to get buffer 0 from the pool then release it twice. |
---|
1397 | */ |
---|
1398 | static bool |
---|
1399 | bdbuf_test_1 (bdbuf_task_control* tasks) |
---|
1400 | { |
---|
1401 | tasks[0].test = 1; |
---|
1402 | |
---|
1403 | /* |
---|
1404 | * Use pool 0. |
---|
1405 | */ |
---|
1406 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1407 | |
---|
1408 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1409 | |
---|
1410 | return bdbuf_tests_finished (tasks); |
---|
1411 | } |
---|
1412 | |
---|
1413 | /** |
---|
1414 | * Test 2. |
---|
1415 | * |
---|
1416 | * # Get task 0 to get buffers 0 -> 4 from the pool hold them. Then get |
---|
1417 | * task 1 and task 2 to get them with blocking. The 2 tasks tests the |
---|
1418 | * priority blocking on the buffer. |
---|
1419 | */ |
---|
1420 | static bool |
---|
1421 | bdbuf_test_2 (bdbuf_task_control* tasks) |
---|
1422 | { |
---|
1423 | int i; |
---|
1424 | |
---|
1425 | tasks[0].test = 2; |
---|
1426 | tasks[1].test = 2; |
---|
1427 | tasks[2].test = 2; |
---|
1428 | |
---|
1429 | /* |
---|
1430 | * Use pool 0. |
---|
1431 | */ |
---|
1432 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1433 | tasks[1].bdd = &bdbuf_disks[0]; |
---|
1434 | tasks[2].bdd = &bdbuf_disks[0]; |
---|
1435 | |
---|
1436 | /* |
---|
1437 | * Wake task 0 and wait for it to have all the buffers. |
---|
1438 | */ |
---|
1439 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1440 | if (bdbuf_wait ("master", BDBUF_SECONDS (5)) != RTEMS_SUCCESSFUL) |
---|
1441 | return false; |
---|
1442 | |
---|
1443 | /* |
---|
1444 | * Wake task 1. |
---|
1445 | */ |
---|
1446 | bdbuf_send_wait_event ("master", "wake task 1", tasks[1].task); |
---|
1447 | |
---|
1448 | /* |
---|
1449 | * Wake task 2. |
---|
1450 | */ |
---|
1451 | bdbuf_send_wait_event ("master", "wake task 2", tasks[2].task); |
---|
1452 | |
---|
1453 | for (i = 0; i < 5; i++) |
---|
1454 | { |
---|
1455 | /* |
---|
1456 | * Wake task 0 and watch task 2 then task 1 get the released buffer. |
---|
1457 | */ |
---|
1458 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1459 | |
---|
1460 | /* |
---|
1461 | * Wait until task 2 has the buffer. |
---|
1462 | */ |
---|
1463 | if (bdbuf_wait ("master", BDBUF_SECONDS (5)) != RTEMS_SUCCESSFUL) |
---|
1464 | return false; |
---|
1465 | } |
---|
1466 | |
---|
1467 | /* |
---|
1468 | * Wait for the tests to finish. |
---|
1469 | */ |
---|
1470 | return bdbuf_tests_finished (tasks); |
---|
1471 | } |
---|
1472 | |
---|
1473 | /** |
---|
1474 | * Test 3. |
---|
1475 | * |
---|
1476 | * # Read a block from disk into the buffer, modify the block and release |
---|
1477 | * it modified. Use a block great then 4 because 0 -> 4 are in the cache. |
---|
1478 | */ |
---|
1479 | static bool |
---|
1480 | bdbuf_test_3 (bdbuf_task_control* tasks) |
---|
1481 | { |
---|
1482 | tasks[0].test = 3; |
---|
1483 | |
---|
1484 | /* |
---|
1485 | * Use pool 0. |
---|
1486 | */ |
---|
1487 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1488 | |
---|
1489 | /* |
---|
1490 | * Wake task 0. |
---|
1491 | */ |
---|
1492 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1493 | |
---|
1494 | return bdbuf_tests_finished (tasks); |
---|
1495 | } |
---|
1496 | |
---|
1497 | /** |
---|
1498 | * Test 4. |
---|
1499 | * |
---|
1500 | * # Read every buffer in the pool and hold. Then get task 1 to ask for another |
---|
1501 | * buffer that is being accessed. It will block waiting for it to appear. |
---|
1502 | */ |
---|
1503 | static bool |
---|
1504 | bdbuf_test_4 (bdbuf_task_control* tasks) |
---|
1505 | { |
---|
1506 | tasks[0].test = 4; |
---|
1507 | tasks[1].test = 4; |
---|
1508 | |
---|
1509 | /* |
---|
1510 | * Use pool 0. |
---|
1511 | */ |
---|
1512 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1513 | tasks[1].bdd = &bdbuf_disks[0]; |
---|
1514 | |
---|
1515 | /* |
---|
1516 | * Wake task 0. |
---|
1517 | */ |
---|
1518 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1519 | |
---|
1520 | /* |
---|
1521 | * Wait for the buffers in the pool to be taken. |
---|
1522 | */ |
---|
1523 | if (bdbuf_wait ("master", BDBUF_SECONDS (5)) != RTEMS_SUCCESSFUL) |
---|
1524 | return false; |
---|
1525 | |
---|
1526 | bdbuf_sleep (100); |
---|
1527 | |
---|
1528 | /* |
---|
1529 | * Wake task 1 to read another one and have to block. |
---|
1530 | */ |
---|
1531 | bdbuf_send_wait_event ("master", "wake task 1", tasks[1].task); |
---|
1532 | |
---|
1533 | bdbuf_sleep (100); |
---|
1534 | |
---|
1535 | /* |
---|
1536 | * Wake task 0 to release it buffers. |
---|
1537 | */ |
---|
1538 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1539 | |
---|
1540 | return bdbuf_tests_finished (tasks); |
---|
1541 | } |
---|
1542 | |
---|
1543 | /** |
---|
1544 | * Test 5. |
---|
1545 | * |
---|
1546 | * # Read every buffer in the pool and hold. Then get task 1 to ask for a new |
---|
1547 | * buffer. It will block waiting for one to appear. |
---|
1548 | */ |
---|
1549 | static bool |
---|
1550 | bdbuf_test_5 (bdbuf_task_control* tasks) |
---|
1551 | { |
---|
1552 | tasks[0].test = 5; |
---|
1553 | tasks[1].test = 5; |
---|
1554 | |
---|
1555 | /* |
---|
1556 | * Use pool 0. |
---|
1557 | */ |
---|
1558 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1559 | tasks[1].bdd = &bdbuf_disks[0]; |
---|
1560 | |
---|
1561 | /* |
---|
1562 | * Wake task 0. |
---|
1563 | */ |
---|
1564 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1565 | |
---|
1566 | /* |
---|
1567 | * Wait for the buffers in the pool to be taken. |
---|
1568 | */ |
---|
1569 | if (bdbuf_wait ("master", BDBUF_SECONDS (5)) != RTEMS_SUCCESSFUL) |
---|
1570 | return false; |
---|
1571 | |
---|
1572 | bdbuf_sleep (100); |
---|
1573 | |
---|
1574 | /* |
---|
1575 | * Wake task 1 to read another one and have to block. |
---|
1576 | */ |
---|
1577 | bdbuf_send_wait_event ("master", "wake task 1", tasks[1].task); |
---|
1578 | |
---|
1579 | bdbuf_sleep (100); |
---|
1580 | |
---|
1581 | /* |
---|
1582 | * Wake task 0 to release it buffers. |
---|
1583 | */ |
---|
1584 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1585 | |
---|
1586 | return bdbuf_tests_finished (tasks); |
---|
1587 | } |
---|
1588 | |
---|
1589 | /** |
---|
1590 | * Test 6. |
---|
1591 | * |
---|
1592 | * # Get 5 buffers, release modify 4 then sync the last. |
---|
1593 | */ |
---|
1594 | static bool |
---|
1595 | bdbuf_test_6 (bdbuf_task_control* tasks) |
---|
1596 | { |
---|
1597 | tasks[0].test = 6; |
---|
1598 | |
---|
1599 | /* |
---|
1600 | * Use pool 0. |
---|
1601 | */ |
---|
1602 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1603 | |
---|
1604 | /* |
---|
1605 | * Wake task 0. |
---|
1606 | */ |
---|
1607 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1608 | |
---|
1609 | return bdbuf_tests_finished (tasks); |
---|
1610 | } |
---|
1611 | |
---|
1612 | /** |
---|
1613 | * Test 7. |
---|
1614 | * |
---|
1615 | * # Get 5 buffers, release modify them all then sync the device. |
---|
1616 | */ |
---|
1617 | static bool |
---|
1618 | bdbuf_test_7 (bdbuf_task_control* tasks) |
---|
1619 | { |
---|
1620 | tasks[0].test = 7; |
---|
1621 | |
---|
1622 | /* |
---|
1623 | * Use pool 0. |
---|
1624 | */ |
---|
1625 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1626 | |
---|
1627 | /* |
---|
1628 | * Wake task 0. |
---|
1629 | */ |
---|
1630 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1631 | |
---|
1632 | return bdbuf_tests_finished (tasks); |
---|
1633 | } |
---|
1634 | |
---|
1635 | /** |
---|
1636 | * Test 8. |
---|
1637 | * |
---|
1638 | * # Get 5 buffers, release modify the last 2 then the reset from 0. |
---|
1639 | */ |
---|
1640 | static bool |
---|
1641 | bdbuf_test_8 (bdbuf_task_control* tasks) |
---|
1642 | { |
---|
1643 | tasks[0].test = 8; |
---|
1644 | |
---|
1645 | /* |
---|
1646 | * Use pool 0. |
---|
1647 | */ |
---|
1648 | tasks[0].bdd = &bdbuf_disks[0]; |
---|
1649 | |
---|
1650 | /* |
---|
1651 | * Wake task 0. |
---|
1652 | */ |
---|
1653 | bdbuf_send_wait_event ("master", "wake task 0", tasks[0].task); |
---|
1654 | |
---|
1655 | return bdbuf_tests_finished (tasks); |
---|
1656 | } |
---|
1657 | |
---|
1658 | /** |
---|
1659 | * A test. |
---|
1660 | */ |
---|
1661 | typedef bool (*bdbuf_test) (bdbuf_task_control* tasks); |
---|
1662 | |
---|
1663 | /** |
---|
1664 | * A test name and function. |
---|
1665 | */ |
---|
1666 | typedef struct bdbuf_test_ident |
---|
1667 | { |
---|
1668 | const char* label; |
---|
1669 | bdbuf_test test; |
---|
1670 | } bdbuf_test_ident; |
---|
1671 | |
---|
1672 | /** |
---|
1673 | * Table of tests. |
---|
1674 | */ |
---|
1675 | static bdbuf_test_ident bdbuf_tests[] = |
---|
1676 | { |
---|
1677 | { |
---|
1678 | "Task 0 get buffer 0 from pool 0", |
---|
1679 | bdbuf_test_1 |
---|
1680 | }, |
---|
1681 | { |
---|
1682 | "Task 0 get buffer 0 -> 4 from pool 0, task 2 and 1 block getting", |
---|
1683 | bdbuf_test_2 |
---|
1684 | }, |
---|
1685 | { |
---|
1686 | "Task 0 read buffer 5, modify and release modified", |
---|
1687 | bdbuf_test_3 |
---|
1688 | }, |
---|
1689 | { |
---|
1690 | "Task 0 read all buffers, task 1 blocks waiting for acessed buffer", |
---|
1691 | bdbuf_test_4 |
---|
1692 | }, |
---|
1693 | { |
---|
1694 | "Task 0 read all buffers, task 1 blocks waiting for new buffer", |
---|
1695 | bdbuf_test_5 |
---|
1696 | }, |
---|
1697 | { |
---|
1698 | "Task 0 release modified 4 buffers then syncs a 5th buffer", |
---|
1699 | bdbuf_test_6 |
---|
1700 | }, |
---|
1701 | { |
---|
1702 | "Task 0 release modified 5 buffers then sync the device", |
---|
1703 | bdbuf_test_7 |
---|
1704 | }, |
---|
1705 | { |
---|
1706 | "Task 0 releases modified 5 buffers is out or order sequence and the" \ |
---|
1707 | " driver checks the buffers are in order", |
---|
1708 | bdbuf_test_8 |
---|
1709 | } |
---|
1710 | }; |
---|
1711 | |
---|
1712 | #define BDBUF_TEST_NUM (sizeof (bdbuf_tests) / sizeof (bdbuf_test_ident)) |
---|
1713 | |
---|
1714 | /** |
---|
1715 | * Test the BD Buffering code. |
---|
1716 | */ |
---|
1717 | static void |
---|
1718 | bdbuf_tester (void) |
---|
1719 | { |
---|
1720 | bdbuf_task_control tasks[BDBUF_TEST_TASKS]; |
---|
1721 | rtems_task_priority old_priority; |
---|
1722 | int t; |
---|
1723 | bool passed = true; |
---|
1724 | rtems_status_code sc; |
---|
1725 | |
---|
1726 | sc = bdbuf_disk_initialize(); |
---|
1727 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
1728 | |
---|
1729 | /* |
---|
1730 | * Change priority to a lower one. |
---|
1731 | */ |
---|
1732 | printf ("lower priority to %d: ", BDBUF_TESTS_PRI_HIGH + 1); |
---|
1733 | bdbuf_test_print_sc (rtems_task_set_priority (RTEMS_SELF, |
---|
1734 | BDBUF_TESTS_PRI_HIGH + 1, |
---|
1735 | &old_priority), |
---|
1736 | true); |
---|
1737 | |
---|
1738 | /* |
---|
1739 | * Make sure the swapout task has run. The user could block |
---|
1740 | * the swapout task from running until later. This is not |
---|
1741 | * tested. |
---|
1742 | */ |
---|
1743 | bdbuf_sleep (100); |
---|
1744 | |
---|
1745 | /* |
---|
1746 | * Start the test tasks used to test the threading parts |
---|
1747 | * of the bdbuf code. |
---|
1748 | */ |
---|
1749 | for (t = 0; t < BDBUF_TEST_TASKS; t++) |
---|
1750 | { |
---|
1751 | bdbuf_task_control_init (t, &tasks[t], |
---|
1752 | rtems_task_self ()); |
---|
1753 | |
---|
1754 | if (!bdbuf_tests_create_task (&tasks[t], |
---|
1755 | BDBUF_TESTS_PRI_HIGH - t, |
---|
1756 | bdbuf_test_tasks[t])) |
---|
1757 | return; |
---|
1758 | } |
---|
1759 | |
---|
1760 | /* |
---|
1761 | * Let the test tasks run if they have not already done so. |
---|
1762 | */ |
---|
1763 | bdbuf_sleep (100); |
---|
1764 | |
---|
1765 | /* |
---|
1766 | * Perform each test. |
---|
1767 | */ |
---|
1768 | for (t = 0; (t < BDBUF_TEST_NUM) && passed; t++) |
---|
1769 | { |
---|
1770 | printf ("test %d: %s\n", t + 1, bdbuf_tests[t].label); |
---|
1771 | passed = bdbuf_tests[t].test (tasks); |
---|
1772 | printf ("test %d: %s\n", t + 1, passed ? "passed" : "failed"); |
---|
1773 | } |
---|
1774 | } |
---|
1775 | |
---|
1776 | static rtems_task Init(rtems_task_argument argument) |
---|
1777 | { |
---|
1778 | TEST_BEGIN(); |
---|
1779 | |
---|
1780 | bdbuf_tester (); |
---|
1781 | |
---|
1782 | TEST_END(); |
---|
1783 | |
---|
1784 | exit (0); |
---|
1785 | } |
---|
1786 | |
---|
1787 | #define CONFIGURE_INIT |
---|
1788 | |
---|
1789 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
1790 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
1791 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
1792 | |
---|
1793 | #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
1794 | |
---|
1795 | #define CONFIGURE_BDBUF_TASK_STACK_SIZE BDBUF_TEST_STACK_SIZE |
---|
1796 | |
---|
1797 | #define CONFIGURE_MAXIMUM_TASKS (1 + BDBUF_TEST_TASKS) |
---|
1798 | #define CONFIGURE_MAXIMUM_SEMAPHORES 2 |
---|
1799 | |
---|
1800 | #define CONFIGURE_EXTRA_TASK_STACKS \ |
---|
1801 | (BDBUF_TEST_TASKS * BDBUF_TEST_STACK_SIZE) |
---|
1802 | |
---|
1803 | #define CONFIGURE_INIT_TASK_STACK_SIZE BDBUF_TEST_STACK_SIZE |
---|
1804 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
1805 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
1806 | |
---|
1807 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
1808 | |
---|
1809 | #include <rtems/confdefs.h> |
---|