source: rtems/testsuites/libtests/block09/init.c @ 7d3f9c6

4.115
Last change on this file since 7d3f9c6 was 7d3f9c6, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 07:37:03

Add HAVE_CONFIG_H.

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