source: rtems/testsuites/libtests/block13/init.c @ 1f7b5b0

4.115
Last change on this file since 1f7b5b0 was 1f7b5b0, checked in by Sebastian Huber <sebastian.huber@…>, on 06/04/12 at 15:04:49

libtests/block13: Add const qualifier

  • Property mode set to 100644
File size: 5.0 KB
Line 
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
27#define BLOCK_COUNT 9
28#define READ_COUNT 19
29
30static int block_access_counts [BLOCK_COUNT];
31
32#define RESET_CACHE (-1)
33
34static const int action_sequence [READ_COUNT] = {
35  0, 2, 3, 4, 5, 6, 7, 8,
36  RESET_CACHE,
37  8,
38  RESET_CACHE,
39  7,
40  RESET_CACHE,
41  6, 7,
42  RESET_CACHE,
43  5, 6, 8
44};
45
46#define UNUSED_LINE { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
47
48static const int expected_block_access_counts [READ_COUNT] [BLOCK_COUNT] = {
49   { 1, 0, 0, 0, 0, 0, 0, 0, 0 },
50   { 1, 0, 1, 0, 0, 0, 0, 0, 0 },
51   { 1, 0, 1, 1, 1, 1, 0, 0, 0 },
52   { 1, 0, 1, 1, 1, 1, 0, 0, 0 },
53   { 1, 0, 1, 1, 1, 1, 1, 1, 0 },
54   { 1, 0, 1, 1, 1, 1, 1, 1, 0 },
55   { 1, 0, 1, 1, 1, 1, 1, 1, 1 },
56   { 1, 0, 1, 1, 1, 1, 1, 1, 1 },
57   UNUSED_LINE,
58   { 0, 0, 0, 0, 0, 0, 0, 0, 1 },
59   UNUSED_LINE,
60   { 0, 0, 0, 0, 0, 0, 0, 1, 0 },
61   UNUSED_LINE,
62   { 0, 0, 0, 0, 0, 0, 1, 0, 0 },
63   { 0, 0, 0, 0, 0, 0, 1, 1, 1 },
64   UNUSED_LINE,
65   { 0, 0, 0, 0, 0, 1, 0, 0, 0 },
66   { 0, 0, 0, 0, 0, 1, 1, 1, 1 },
67   { 0, 0, 0, 0, 0, 1, 1, 1, 1 }
68};
69
70#define NO_TRIGGER RTEMS_DISK_READ_AHEAD_NO_TRIGGER
71
72#define TRIGGER_AFTER_RESET RTEMS_DISK_READ_AHEAD_NO_TRIGGER
73
74static const rtems_blkdev_bnum trigger [READ_COUNT] = {
75  1, 3, 5, 5, 7, 7, NO_TRIGGER, NO_TRIGGER,
76  TRIGGER_AFTER_RESET,
77  9,
78  TRIGGER_AFTER_RESET,
79  8,
80  TRIGGER_AFTER_RESET,
81  7, NO_TRIGGER,
82  TRIGGER_AFTER_RESET,
83  6, 8, NO_TRIGGER
84};
85
86#define NOT_CHANGED_BY_RESET(i) (i)
87
88static const rtems_blkdev_bnum next [READ_COUNT] = {
89  2, 4, 6, 6, 8, 8, 8, 8,
90  NOT_CHANGED_BY_RESET(8),
91  10,
92  NOT_CHANGED_BY_RESET(10),
93  9,
94  NOT_CHANGED_BY_RESET(9),
95  8, 8,
96  NOT_CHANGED_BY_RESET(8),
97  7, 9, 9
98};
99
100static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
101{
102  int rv = 0;
103
104  if (req == RTEMS_BLKIO_REQUEST) {
105    rtems_blkdev_request *breq = arg;
106    rtems_blkdev_sg_buffer *sg = breq->bufs;
107    uint32_t i;
108
109    rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_READ);
110
111    for (i = 0; i < breq->bufnum; ++i) {
112      rtems_blkdev_bnum block = sg [i].block;
113
114      rtems_test_assert(block < BLOCK_COUNT);
115
116      ++block_access_counts [block];
117    }
118
119    (*breq->req_done)(breq->done_arg, RTEMS_SUCCESSFUL);
120  } else {
121    errno = EINVAL;
122    rv = -1;
123  }
124
125  return rv;
126}
127
128static void test_read_ahead(rtems_disk_device *dd)
129{
130  int i;
131
132  for (i = 0; i < READ_COUNT; ++i) {
133    int action = action_sequence [i];
134
135    if (action != RESET_CACHE) {
136      rtems_blkdev_bnum block = (rtems_blkdev_bnum) action;
137      rtems_status_code sc;
138      rtems_bdbuf_buffer *bd;
139
140      printf("%i ", action);
141
142      sc = rtems_bdbuf_read(dd, block, &bd);
143      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
144
145      sc = rtems_bdbuf_release(bd);
146      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
147
148      rtems_test_assert(
149        memcmp(
150          block_access_counts,
151          expected_block_access_counts [i],
152          sizeof(block_access_counts)
153        ) == 0
154      );
155    } else {
156      printf("\nreset\n");
157
158      rtems_bdbuf_purge_dev(dd);
159      memset(&block_access_counts, 0, sizeof(block_access_counts));
160    }
161
162    rtems_test_assert(trigger [i] == dd->read_ahead.trigger);
163    rtems_test_assert(next [i] == dd->read_ahead.next);
164  }
165
166  printf("\n");
167}
168
169static void test(void)
170{
171  rtems_status_code sc;
172  dev_t dev = 0;
173  rtems_disk_device *dd;
174
175  sc = rtems_disk_io_initialize();
176  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
177
178  sc = rtems_disk_create_phys(
179    dev,
180    1,
181    BLOCK_COUNT,
182    test_disk_ioctl,
183    NULL,
184    NULL
185  );
186  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
187
188  dd = rtems_disk_obtain(dev);
189  rtems_test_assert(dd != NULL);
190
191  test_read_ahead(dd);
192
193  sc = rtems_disk_release(dd);
194  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
195
196  sc = rtems_disk_delete(dev);
197  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
198}
199
200static void Init(rtems_task_argument arg)
201{
202  puts("\n\n*** TEST BLOCK 13 ***");
203
204  test();
205
206  puts("*** END OF TEST BLOCK 13 ***");
207
208  rtems_test_exit(0);
209}
210
211#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
212#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
213#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
214
215#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1
216#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 1
217#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_COUNT
218#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 2
219#define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 1
220
221#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
222
223#define CONFIGURE_MAXIMUM_TASKS 1
224
225#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
226
227#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
228#define CONFIGURE_INIT_TASK_PRIORITY 2
229
230#define CONFIGURE_INIT
231
232#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.