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

Last change on this file since 9de8d61 was 9de8d61, checked in by Sebastian Huber <sebastian.huber@…>, on 07/17/20 at 11:36:49

libtest: <rtems/test.h> to <rtems/test-info.h>

Rename this header file to later move <t.h> to <rtems/test.h>. The main
feature provided by <rtems/test-info.h> is the output of standard test
information which is consumed by the RTEMS Tester.

Update #3199.

  • Property mode set to 100644
File size: 5.0 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, 2018 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
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.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "tmacros.h"
28
29#include <sys/stat.h>
30#include <assert.h>
31#include <errno.h>
32#include <fcntl.h>
33#include <stdlib.h>
34#include <unistd.h>
35
36#include <rtems.h>
37#include <rtems/bdbuf.h>
38#include <rtems/test-info.h>
39
40#include <bsp.h>
41
42const char rtems_test_name[] = "BLOCK 9";
43
44#define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
45
46#define BLOCK_SIZE sizeof(char)
47
48#define BLOCK_COUNT 4
49
50#define BLOCK_READ_IO_ERROR 0
51#define BLOCK_READ_UNSATISFIED 1
52#define BLOCK_READ_SUCCESSFUL 2
53#define BLOCK_WRITE_IO_ERROR 3
54
55#define DISK_PATH "/disk"
56
57static char disk_data [BLOCK_COUNT];
58
59static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
60{
61  rtems_status_code sc = RTEMS_SUCCESSFUL;
62
63  if (req == RTEMS_BLKIO_REQUEST) {
64    rtems_blkdev_request *r = arg;
65    uint32_t i = 0;
66
67    for (i = 0; i < r->bufnum; ++i) {
68      rtems_blkdev_sg_buffer *sg = &r->bufs [i];
69      char *buf = sg->buffer;
70
71      if (sg->length == 1) {
72        switch (r->req) {
73          case RTEMS_BLKDEV_REQ_READ:
74            switch (sg->block) {
75              case BLOCK_READ_IO_ERROR:
76                sc = RTEMS_IO_ERROR;
77                break;
78              case BLOCK_READ_UNSATISFIED:
79                sc = RTEMS_UNSATISFIED;
80                break;
81              case BLOCK_READ_SUCCESSFUL:
82              case BLOCK_WRITE_IO_ERROR:
83                *buf = disk_data [sg->block];
84                break;
85              default:
86                sc = RTEMS_IO_ERROR;
87                break;
88            }
89            break;
90          case RTEMS_BLKDEV_REQ_WRITE:
91            switch (sg->block) {
92              case BLOCK_READ_IO_ERROR:
93              case BLOCK_READ_UNSATISFIED:
94              case BLOCK_READ_SUCCESSFUL:
95                disk_data [sg->block] = *buf;
96                break;
97              case BLOCK_WRITE_IO_ERROR:
98                sc = RTEMS_IO_ERROR;
99                break;
100              default:
101                sc = RTEMS_IO_ERROR;
102                break;
103            }
104            break;
105          default:
106            sc = RTEMS_IO_ERROR;
107            break;
108        }
109      } else {
110        sc = RTEMS_IO_ERROR;
111      }
112    }
113
114    rtems_blkdev_request_done(r, sc);
115
116    return 0;
117  } else {
118    return rtems_blkdev_ioctl(dd, req, arg);
119  }
120}
121
122static void disk_register(
123  uint32_t block_size,
124  rtems_blkdev_bnum block_count,
125  rtems_disk_device **dd
126)
127{
128  rtems_status_code sc;
129  int fd;
130  int rv;
131
132  sc = rtems_blkdev_create(
133    DISK_PATH,
134    block_size,
135    block_count,
136    disk_ioctl,
137    NULL
138  );
139  ASSERT_SC(sc);
140
141  fd = open(DISK_PATH, O_RDWR);
142  rtems_test_assert(fd >= 0);
143
144  rv = rtems_disk_fd_get_disk_device(fd, dd);
145  rtems_test_assert(rv == 0);
146
147  rv = close(fd);
148  rtems_test_assert(rv == 0);
149}
150
151static void check_read(
152  rtems_disk_device *dd,
153  rtems_blkdev_bnum block,
154  rtems_status_code expected_sc
155)
156{
157  rtems_status_code sc = RTEMS_SUCCESSFUL;
158  rtems_bdbuf_buffer *bd = NULL;
159
160  sc = rtems_bdbuf_read(dd, block, &bd);
161  assert(sc == expected_sc);
162
163  if (sc == RTEMS_SUCCESSFUL) {
164    sc = rtems_bdbuf_release(bd);
165    ASSERT_SC(sc);
166  }
167}
168
169static rtems_task Init(rtems_task_argument argument)
170{
171  rtems_status_code sc = RTEMS_SUCCESSFUL;
172  rtems_bdbuf_buffer *bd = NULL;
173  rtems_disk_device *dd = NULL;
174
175  TEST_BEGIN();
176
177  disk_register(BLOCK_SIZE, BLOCK_COUNT, &dd);
178
179  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
180  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
181  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
182  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
183
184  /* Check write IO error */
185
186  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
187  ASSERT_SC(sc);
188
189  bd->buffer [0] = 1;
190
191  sc = rtems_bdbuf_sync(bd);
192  ASSERT_SC(sc);
193
194  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
195  ASSERT_SC(sc);
196
197  assert(bd->buffer [0] == 0);
198
199  sc = rtems_bdbuf_release(bd);
200  ASSERT_SC(sc);
201
202  /* Check write to deleted disk */
203
204  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
205  ASSERT_SC(sc);
206
207  sc = unlink(DISK_PATH);
208  ASSERT_SC(sc);
209
210  sc = rtems_bdbuf_sync(bd);
211  ASSERT_SC(sc);
212
213  TEST_END();
214
215  exit(0);
216}
217
218#define CONFIGURE_INIT
219
220#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
221#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
222#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
223
224#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
225
226#define CONFIGURE_MAXIMUM_TASKS 1
227
228#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
229
230#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
231
232#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE
233#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE
234#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_SIZE * BLOCK_COUNT)
235
236#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.