source: rtems/testsuites/libtests/block12/init.c @ 3cec2df

5
Last change on this file since 3cec2df was 3cec2df, checked in by Sebastian Huber <sebastian.huber@…>, on 12/17/19 at 08:17:43

config: CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS

Rename CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS into
CONFIGURE_MAXIMUM_FILE_DESCRIPTORS.

Update #3753.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2012, 2018 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <sys/stat.h>
22#include <assert.h>
23#include <errno.h>
24#include <fcntl.h>
25#include <string.h>
26#include <unistd.h>
27
28#include <rtems/blkdev.h>
29#include <rtems/bdbuf.h>
30
31const char rtems_test_name[] = "BLOCK 12";
32
33#define BLOCK_COUNT 15
34
35#define DISK_PATH "/disk"
36
37static int block_access_counts [BLOCK_COUNT];
38
39static int expected_block_access_counts [BLOCK_COUNT] = {
40  2, 0, 2, 0, 2, 0, 2, 2, 2, 0, 2, 0, 2, 0, 2
41};
42
43static const rtems_blkdev_bnum read_sequence [] = {
44  0, 2, 4, 6, 8, 10, 12, 14, 7
45};
46
47static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
48{
49  int rv = 0;
50
51  if (req == RTEMS_BLKIO_REQUEST) {
52    rtems_blkdev_request *breq = arg;
53    rtems_blkdev_sg_buffer *sg = breq->bufs;
54    uint32_t i;
55
56    rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_READ);
57
58    for (i = 0; i < breq->bufnum; ++i) {
59      rtems_blkdev_bnum block = sg [i].block;
60
61      rtems_test_assert(block < BLOCK_COUNT);
62
63      ++block_access_counts [block];
64    }
65
66    rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
67  } else {
68    rv = rtems_blkdev_ioctl(dd, req, arg);
69  }
70
71  return rv;
72}
73
74static void do_read_sequence(rtems_disk_device *dd)
75{
76  size_t i;
77
78  for (i = 0; i < sizeof(read_sequence) / sizeof(read_sequence [0]); ++i) {
79    rtems_status_code sc;
80    rtems_bdbuf_buffer *bd;
81
82    sc = rtems_bdbuf_read(dd, read_sequence [i], &bd);
83    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
84
85    sc = rtems_bdbuf_release(bd);
86    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
87  }
88}
89
90static void test(void)
91{
92  rtems_status_code sc;
93  int fd;
94  int rv;
95  rtems_disk_device *dd;
96
97  sc = rtems_blkdev_create(
98    DISK_PATH,
99    1,
100    BLOCK_COUNT,
101    test_disk_ioctl,
102    NULL
103  );
104  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
105
106  fd = open(DISK_PATH, O_RDWR);
107  rtems_test_assert(fd >= 0);
108
109  rv = rtems_disk_fd_get_disk_device(fd, &dd);
110  rtems_test_assert(rv == 0);
111
112  rv = close(fd);
113  rtems_test_assert(rv == 0);
114
115  do_read_sequence(dd);
116  rtems_bdbuf_purge_dev(dd);
117  do_read_sequence(dd);
118
119  rtems_test_assert(
120    memcmp(
121      block_access_counts,
122      expected_block_access_counts,
123      sizeof(block_access_counts)
124    ) == 0
125  );
126
127  rv = unlink(DISK_PATH);
128  rtems_test_assert(rv == 0);
129}
130
131static void Init(rtems_task_argument arg)
132{
133  TEST_BEGIN();
134
135  test();
136
137  TEST_END();
138
139  rtems_test_exit(0);
140}
141
142#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
143#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
144#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
145
146#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
147
148#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1
149#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 1
150#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_COUNT
151
152#define CONFIGURE_MAXIMUM_TASKS 1
153
154#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
155
156#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
157
158#define CONFIGURE_INIT
159
160#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.