source: rtems/testsuites/libtests/block12/init.c @ c4b8b147

Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 3, 2017 at 7:35:38 AM

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 3.1 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.org/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
27const char rtems_test_name[] = "BLOCK 12";
28
29#define BLOCK_COUNT 15
30
31static int block_access_counts [BLOCK_COUNT];
32
33static int expected_block_access_counts [BLOCK_COUNT] = {
34  2, 0, 2, 0, 2, 0, 2, 2, 2, 0, 2, 0, 2, 0, 2
35};
36
37static const rtems_blkdev_bnum read_sequence [] = {
38  0, 2, 4, 6, 8, 10, 12, 14, 7
39};
40
41static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
42{
43  int rv = 0;
44
45  if (req == RTEMS_BLKIO_REQUEST) {
46    rtems_blkdev_request *breq = arg;
47    rtems_blkdev_sg_buffer *sg = breq->bufs;
48    uint32_t i;
49
50    rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_READ);
51
52    for (i = 0; i < breq->bufnum; ++i) {
53      rtems_blkdev_bnum block = sg [i].block;
54
55      rtems_test_assert(block < BLOCK_COUNT);
56
57      ++block_access_counts [block];
58    }
59
60    rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
61  } else {
62    errno = EINVAL;
63    rv = -1;
64  }
65
66  return rv;
67}
68
69static void do_read_sequence(rtems_disk_device *dd)
70{
71  size_t i;
72
73  for (i = 0; i < sizeof(read_sequence) / sizeof(read_sequence [0]); ++i) {
74    rtems_status_code sc;
75    rtems_bdbuf_buffer *bd;
76
77    sc = rtems_bdbuf_read(dd, read_sequence [i], &bd);
78    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
79
80    sc = rtems_bdbuf_release(bd);
81    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
82  }
83}
84
85static void test(void)
86{
87  rtems_status_code sc;
88  dev_t dev = 0;
89  rtems_disk_device *dd;
90
91  sc = rtems_disk_io_initialize();
92  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
93
94  sc = rtems_disk_create_phys(
95    dev,
96    1,
97    BLOCK_COUNT,
98    test_disk_ioctl,
99    NULL,
100    NULL
101  );
102  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
103
104  dd = rtems_disk_obtain(dev);
105  rtems_test_assert(dd != NULL);
106
107  do_read_sequence(dd);
108  rtems_bdbuf_purge_dev(dd);
109  do_read_sequence(dd);
110
111  rtems_test_assert(
112    memcmp(
113      block_access_counts,
114      expected_block_access_counts,
115      sizeof(block_access_counts)
116    ) == 0
117  );
118
119  sc = rtems_disk_release(dd);
120  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
121
122  sc = rtems_disk_delete(dev);
123  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
124}
125
126static void Init(rtems_task_argument arg)
127{
128  TEST_BEGIN();
129
130  test();
131
132  TEST_END();
133
134  rtems_test_exit(0);
135}
136
137#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
138#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
140
141#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1
142#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 1
143#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_COUNT
144
145#define CONFIGURE_MAXIMUM_TASKS 1
146
147#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
148
149#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
150
151#define CONFIGURE_INIT
152
153#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.