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

4.11
Last change on this file since 3c462734 was 3c462734, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2012 at 10:13:04 AM

libblock: Fix purge device tree traversal

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