source: rtems/testsuites/libtests/block09/init.c @ 9f0a68c

4.115
Last change on this file since 9f0a68c was 9f0a68c, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/12 at 10:54:39

libblock: Block device transfer request API change

Add and use rtems_blkdev_request_done(). Block device transfer requests
must signal the completion status now with rtems_blkdev_request_done().
The return value of the block device IO control will be ignored for
transfer requests.

The first parameter of rtems_blkdev_request_cb is now the transfer
request structure.

Renamed rtems_blkdev_request::req_done to rtems_blkdev_request::done to
break third party drivers at compile time, otherwise this API change
would result in runtime errors.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup test_bdbuf
5 *
6 * @brief Bdbuf test for disk driver error handling..
7 */
8
9/*
10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <assert.h>
28#include <errno.h>
29
30#include <rtems.h>
31#include <rtems/bdbuf.h>
32#include <rtems/diskdevs.h>
33
34/* forward declarations to avoid warnings */
35static rtems_task Init(rtems_task_argument argument);
36
37#define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
38
39#define BLOCK_SIZE sizeof(char)
40
41#define BLOCK_COUNT 4
42
43#define BLOCK_READ_IO_ERROR 0
44#define BLOCK_READ_UNSATISFIED 1
45#define BLOCK_READ_SUCCESSFUL 2
46#define BLOCK_WRITE_IO_ERROR 3
47
48static char disk_data [BLOCK_COUNT];
49
50static const rtems_driver_address_table disk_ops = {
51  .initialization_entry = NULL,
52  RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
53};
54
55static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
56{
57  rtems_status_code sc = RTEMS_SUCCESSFUL;
58
59  if (req == RTEMS_BLKIO_REQUEST) {
60    rtems_blkdev_request *r = arg;
61    uint32_t i = 0;
62
63    for (i = 0; i < r->bufnum; ++i) {
64      rtems_blkdev_sg_buffer *sg = &r->bufs [i];
65      char *buf = sg->buffer;
66
67      if (sg->length == 1) {
68        switch (r->req) {
69          case RTEMS_BLKDEV_REQ_READ:
70            switch (sg->block) {
71              case BLOCK_READ_IO_ERROR:
72                sc = RTEMS_IO_ERROR;
73                break;
74              case BLOCK_READ_UNSATISFIED:
75                sc = RTEMS_UNSATISFIED;
76                break;
77              case BLOCK_READ_SUCCESSFUL:
78              case BLOCK_WRITE_IO_ERROR:
79                *buf = disk_data [sg->block];
80                break;
81              default:
82                sc = RTEMS_IO_ERROR;
83                break;
84            }
85            break;
86          case RTEMS_BLKDEV_REQ_WRITE:
87            switch (sg->block) {
88              case BLOCK_READ_IO_ERROR:
89              case BLOCK_READ_UNSATISFIED:
90              case BLOCK_READ_SUCCESSFUL:
91                disk_data [sg->block] = *buf;
92                break;
93              case BLOCK_WRITE_IO_ERROR:
94                sc = RTEMS_IO_ERROR;
95                break;
96              default:
97                sc = RTEMS_IO_ERROR;
98                break;
99            }
100            break;
101          default:
102            sc = RTEMS_IO_ERROR;
103            break;
104        }
105      } else {
106        sc = RTEMS_IO_ERROR;
107      }
108    }
109
110    rtems_blkdev_request_done(r, sc);
111
112    return 0;
113  } else {
114    return rtems_blkdev_ioctl(dd, req, arg);
115  }
116}
117
118static rtems_status_code disk_register(
119  uint32_t block_size,
120  rtems_blkdev_bnum block_count,
121  dev_t *dev_ptr
122)
123{
124  rtems_status_code sc = RTEMS_SUCCESSFUL;
125  rtems_device_major_number major = 0;
126  dev_t dev = 0;
127
128  sc = rtems_io_register_driver(0, &disk_ops, &major);
129  ASSERT_SC(sc);
130
131  dev = rtems_filesystem_make_dev_t(major, 0);
132
133  sc = rtems_disk_create_phys(
134    dev,
135    block_size,
136    block_count,
137    disk_ioctl,
138    NULL,
139    NULL
140  );
141  ASSERT_SC(sc);
142
143  *dev_ptr = dev;
144
145  return RTEMS_SUCCESSFUL;
146}
147
148static void check_read(
149  rtems_disk_device *dd,
150  rtems_blkdev_bnum block,
151  rtems_status_code expected_sc
152)
153{
154  rtems_status_code sc = RTEMS_SUCCESSFUL;
155  rtems_bdbuf_buffer *bd = NULL;
156
157  sc = rtems_bdbuf_read(dd, block, &bd);
158  assert(sc == expected_sc);
159
160  if (sc == RTEMS_SUCCESSFUL) {
161    sc = rtems_bdbuf_release(bd);
162    ASSERT_SC(sc);
163  }
164}
165
166static rtems_task Init(rtems_task_argument argument)
167{
168  rtems_status_code sc = RTEMS_SUCCESSFUL;
169  rtems_bdbuf_buffer *bd = NULL;
170  dev_t dev = 0;
171  rtems_disk_device *dd = NULL;
172
173  printk("\n\n*** TEST BLOCK 9 ***\n");
174
175  sc = rtems_disk_io_initialize();
176  ASSERT_SC(sc);
177
178  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
179  ASSERT_SC(sc);
180
181  dd = rtems_disk_obtain(dev);
182  assert(dd != NULL);
183
184  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
185  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
186  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
187  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
188
189  /* Check write IO error */
190
191  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
192  ASSERT_SC(sc);
193
194  bd->buffer [0] = 1;
195
196  sc = rtems_bdbuf_sync(bd);
197  ASSERT_SC(sc);
198
199  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
200  ASSERT_SC(sc);
201
202  assert(bd->buffer [0] == 0);
203
204  sc = rtems_bdbuf_release(bd);
205  ASSERT_SC(sc);
206
207  /* Check write to deleted disk */
208
209  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
210  ASSERT_SC(sc);
211
212  sc = rtems_disk_delete(dev);
213  ASSERT_SC(sc);
214
215  sc = rtems_bdbuf_sync(bd);
216  ASSERT_SC(sc);
217
218  sc = rtems_disk_release(dd);
219  ASSERT_SC(sc);
220
221  printk("*** END OF TEST BLOCK 9 ***\n");
222
223  exit(0);
224}
225
226#define CONFIGURE_INIT
227
228#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
229#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
230#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
231
232#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
233
234#define CONFIGURE_MAXIMUM_TASKS 1
235#define CONFIGURE_MAXIMUM_DRIVERS 4
236
237#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
238
239#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE
240#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE
241#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_SIZE * BLOCK_COUNT)
242
243#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.