[39ee704e] | 1 | /* |
---|
| 2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Obere Lagerstr. 30 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <rtems@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.com/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
| 19 | #include "tmacros.h" |
---|
| 20 | |
---|
| 21 | #include <errno.h> |
---|
| 22 | #include <string.h> |
---|
| 23 | |
---|
| 24 | #include <rtems/blkdev.h> |
---|
| 25 | #include <rtems/bdbuf.h> |
---|
| 26 | |
---|
[f29d969] | 27 | #define BLOCK_COUNT 11 |
---|
| 28 | #define READ_COUNT 23 |
---|
[39ee704e] | 29 | |
---|
| 30 | static int block_access_counts [BLOCK_COUNT]; |
---|
| 31 | |
---|
| 32 | #define RESET_CACHE (-1) |
---|
| 33 | |
---|
| 34 | static const int action_sequence [READ_COUNT] = { |
---|
[f29d969] | 35 | 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
---|
[39ee704e] | 36 | RESET_CACHE, |
---|
[f29d969] | 37 | 10, |
---|
[39ee704e] | 38 | RESET_CACHE, |
---|
[f29d969] | 39 | 9, |
---|
[39ee704e] | 40 | RESET_CACHE, |
---|
[f29d969] | 41 | 8, |
---|
[39ee704e] | 42 | RESET_CACHE, |
---|
[f29d969] | 43 | 7, 8, |
---|
| 44 | RESET_CACHE, |
---|
[71092f7] | 45 | 6, 7, 9 |
---|
[39ee704e] | 46 | }; |
---|
| 47 | |
---|
[f29d969] | 48 | #define UNUSED_LINE { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
---|
[39ee704e] | 49 | |
---|
[1f7b5b0] | 50 | static const int expected_block_access_counts [READ_COUNT] [BLOCK_COUNT] = { |
---|
[f29d969] | 51 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
| 52 | { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, |
---|
| 53 | { 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, |
---|
| 54 | { 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, |
---|
| 55 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
---|
| 56 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
---|
| 57 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
---|
| 58 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
---|
| 59 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
---|
[71092f7] | 60 | { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
---|
[f29d969] | 61 | UNUSED_LINE, |
---|
| 62 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, |
---|
[39ee704e] | 63 | UNUSED_LINE, |
---|
[f29d969] | 64 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
---|
[39ee704e] | 65 | UNUSED_LINE, |
---|
[f29d969] | 66 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, |
---|
[39ee704e] | 67 | UNUSED_LINE, |
---|
[f29d969] | 68 | { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, |
---|
| 69 | { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }, |
---|
[39ee704e] | 70 | UNUSED_LINE, |
---|
[f29d969] | 71 | { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, |
---|
| 72 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 }, |
---|
| 73 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 } |
---|
[39ee704e] | 74 | }; |
---|
| 75 | |
---|
| 76 | #define NO_TRIGGER RTEMS_DISK_READ_AHEAD_NO_TRIGGER |
---|
| 77 | |
---|
| 78 | #define TRIGGER_AFTER_RESET RTEMS_DISK_READ_AHEAD_NO_TRIGGER |
---|
| 79 | |
---|
| 80 | static const rtems_blkdev_bnum trigger [READ_COUNT] = { |
---|
[71092f7] | 81 | 1, 3, 5, 5, 8, 8, 8, NO_TRIGGER, NO_TRIGGER, NO_TRIGGER, |
---|
[39ee704e] | 82 | TRIGGER_AFTER_RESET, |
---|
[f29d969] | 83 | 11, |
---|
[39ee704e] | 84 | TRIGGER_AFTER_RESET, |
---|
[f29d969] | 85 | 10, |
---|
| 86 | TRIGGER_AFTER_RESET, |
---|
| 87 | 9, |
---|
[39ee704e] | 88 | TRIGGER_AFTER_RESET, |
---|
[f29d969] | 89 | 8, NO_TRIGGER, |
---|
[39ee704e] | 90 | TRIGGER_AFTER_RESET, |
---|
[71092f7] | 91 | 7, 9, NO_TRIGGER |
---|
[39ee704e] | 92 | }; |
---|
| 93 | |
---|
| 94 | #define NOT_CHANGED_BY_RESET(i) (i) |
---|
| 95 | |
---|
| 96 | static const rtems_blkdev_bnum next [READ_COUNT] = { |
---|
[71092f7] | 97 | 2, 4, 7, 7, 10, 10, 10, 10, 10, 10, |
---|
[f29d969] | 98 | NOT_CHANGED_BY_RESET(10), |
---|
| 99 | 12, |
---|
| 100 | NOT_CHANGED_BY_RESET(12), |
---|
| 101 | 11, |
---|
| 102 | NOT_CHANGED_BY_RESET(11), |
---|
[39ee704e] | 103 | 10, |
---|
| 104 | NOT_CHANGED_BY_RESET(10), |
---|
[f29d969] | 105 | 9, 9, |
---|
[39ee704e] | 106 | NOT_CHANGED_BY_RESET(9), |
---|
[f29d969] | 107 | 8, 11, 11 |
---|
[39ee704e] | 108 | }; |
---|
| 109 | |
---|
| 110 | static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg) |
---|
| 111 | { |
---|
| 112 | int rv = 0; |
---|
| 113 | |
---|
| 114 | if (req == RTEMS_BLKIO_REQUEST) { |
---|
| 115 | rtems_blkdev_request *breq = arg; |
---|
| 116 | rtems_blkdev_sg_buffer *sg = breq->bufs; |
---|
| 117 | uint32_t i; |
---|
| 118 | |
---|
| 119 | rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_READ); |
---|
| 120 | |
---|
| 121 | for (i = 0; i < breq->bufnum; ++i) { |
---|
| 122 | rtems_blkdev_bnum block = sg [i].block; |
---|
| 123 | |
---|
| 124 | rtems_test_assert(block < BLOCK_COUNT); |
---|
| 125 | |
---|
| 126 | ++block_access_counts [block]; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | (*breq->req_done)(breq->done_arg, RTEMS_SUCCESSFUL); |
---|
| 130 | } else { |
---|
| 131 | errno = EINVAL; |
---|
| 132 | rv = -1; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return rv; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | static void test_read_ahead(rtems_disk_device *dd) |
---|
| 139 | { |
---|
| 140 | int i; |
---|
| 141 | |
---|
| 142 | for (i = 0; i < READ_COUNT; ++i) { |
---|
| 143 | int action = action_sequence [i]; |
---|
| 144 | |
---|
| 145 | if (action != RESET_CACHE) { |
---|
| 146 | rtems_blkdev_bnum block = (rtems_blkdev_bnum) action; |
---|
| 147 | rtems_status_code sc; |
---|
| 148 | rtems_bdbuf_buffer *bd; |
---|
| 149 | |
---|
| 150 | printf("%i ", action); |
---|
| 151 | |
---|
| 152 | sc = rtems_bdbuf_read(dd, block, &bd); |
---|
| 153 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 154 | |
---|
| 155 | sc = rtems_bdbuf_release(bd); |
---|
| 156 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 157 | |
---|
| 158 | rtems_test_assert( |
---|
| 159 | memcmp( |
---|
| 160 | block_access_counts, |
---|
| 161 | expected_block_access_counts [i], |
---|
| 162 | sizeof(block_access_counts) |
---|
| 163 | ) == 0 |
---|
| 164 | ); |
---|
| 165 | } else { |
---|
| 166 | printf("\nreset\n"); |
---|
| 167 | |
---|
| 168 | rtems_bdbuf_purge_dev(dd); |
---|
| 169 | memset(&block_access_counts, 0, sizeof(block_access_counts)); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | rtems_test_assert(trigger [i] == dd->read_ahead.trigger); |
---|
| 173 | rtems_test_assert(next [i] == dd->read_ahead.next); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | printf("\n"); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | static void test(void) |
---|
| 180 | { |
---|
| 181 | rtems_status_code sc; |
---|
| 182 | dev_t dev = 0; |
---|
| 183 | rtems_disk_device *dd; |
---|
| 184 | |
---|
| 185 | sc = rtems_disk_io_initialize(); |
---|
| 186 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 187 | |
---|
| 188 | sc = rtems_disk_create_phys( |
---|
| 189 | dev, |
---|
| 190 | 1, |
---|
| 191 | BLOCK_COUNT, |
---|
| 192 | test_disk_ioctl, |
---|
| 193 | NULL, |
---|
| 194 | NULL |
---|
| 195 | ); |
---|
| 196 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 197 | |
---|
| 198 | dd = rtems_disk_obtain(dev); |
---|
| 199 | rtems_test_assert(dd != NULL); |
---|
| 200 | |
---|
| 201 | test_read_ahead(dd); |
---|
| 202 | |
---|
| 203 | sc = rtems_disk_release(dd); |
---|
| 204 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 205 | |
---|
| 206 | sc = rtems_disk_delete(dev); |
---|
| 207 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | static void Init(rtems_task_argument arg) |
---|
| 211 | { |
---|
| 212 | puts("\n\n*** TEST BLOCK 13 ***"); |
---|
| 213 | |
---|
| 214 | test(); |
---|
| 215 | |
---|
| 216 | puts("*** END OF TEST BLOCK 13 ***"); |
---|
| 217 | |
---|
| 218 | rtems_test_exit(0); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 222 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 223 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
| 224 | |
---|
| 225 | #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1 |
---|
| 226 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 1 |
---|
| 227 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_COUNT |
---|
[f29d969] | 228 | #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 3 |
---|
[39ee704e] | 229 | #define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 1 |
---|
| 230 | |
---|
| 231 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
| 232 | |
---|
| 233 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 234 | |
---|
| 235 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 236 | |
---|
| 237 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES |
---|
| 238 | #define CONFIGURE_INIT_TASK_PRIORITY 2 |
---|
| 239 | |
---|
| 240 | #define CONFIGURE_INIT |
---|
| 241 | |
---|
| 242 | #include <rtems/confdefs.h> |
---|