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 <sys/ioctl.h> |
---|
22 | #include <sys/types.h> |
---|
23 | #include <sys/stat.h> |
---|
24 | #include <fcntl.h> |
---|
25 | #include <unistd.h> |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | #include <rtems/ramdisk.h> |
---|
29 | #include <rtems/bdbuf.h> |
---|
30 | |
---|
31 | const char rtems_test_name[] = "BLOCK 16"; |
---|
32 | |
---|
33 | #define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL) |
---|
34 | |
---|
35 | static void test(void) |
---|
36 | { |
---|
37 | static const char device [] = "/dev/rda"; |
---|
38 | rtems_status_code sc; |
---|
39 | int fd; |
---|
40 | int rv; |
---|
41 | rtems_disk_device *dd; |
---|
42 | ramdisk *rd; |
---|
43 | unsigned char buf [8]; |
---|
44 | uint32_t media_block_size = sizeof(buf [0]); |
---|
45 | rtems_blkdev_bnum media_block_count = sizeof(buf) / sizeof(buf [0]); |
---|
46 | rtems_blkdev_bnum media_size = media_block_size * media_block_count; |
---|
47 | rtems_bdbuf_buffer *media_bd [media_block_count]; |
---|
48 | rtems_bdbuf_buffer *large_bd; |
---|
49 | rtems_blkdev_bnum i; |
---|
50 | |
---|
51 | sc = rtems_disk_io_initialize(); |
---|
52 | ASSERT_SC(sc); |
---|
53 | |
---|
54 | for (i = 0; i < media_block_count; ++i) { |
---|
55 | buf [i] = i; |
---|
56 | } |
---|
57 | |
---|
58 | rd = ramdisk_allocate(buf, media_block_size, media_block_count, false); |
---|
59 | rtems_test_assert(rd != NULL); |
---|
60 | |
---|
61 | sc = rtems_blkdev_create( |
---|
62 | device, |
---|
63 | media_block_size, |
---|
64 | media_block_count, |
---|
65 | ramdisk_ioctl, |
---|
66 | rd |
---|
67 | ); |
---|
68 | ASSERT_SC(sc); |
---|
69 | |
---|
70 | fd = open(device, O_RDWR); |
---|
71 | rtems_test_assert(fd >= 0); |
---|
72 | |
---|
73 | rv = rtems_disk_fd_get_disk_device(fd, &dd); |
---|
74 | rtems_test_assert(rv == 0); |
---|
75 | |
---|
76 | for (i = 0; i < media_block_count; ++i) { |
---|
77 | sc = rtems_bdbuf_read(dd, i, &media_bd [i]); |
---|
78 | ASSERT_SC(sc); |
---|
79 | |
---|
80 | rtems_test_assert(media_bd [i]->buffer [0] == buf [i]); |
---|
81 | } |
---|
82 | |
---|
83 | for (i = 0; i < media_block_count; ++i) { |
---|
84 | media_bd [i]->buffer [0] += media_block_count; |
---|
85 | |
---|
86 | sc = rtems_bdbuf_release_modified(media_bd [i]); |
---|
87 | ASSERT_SC(sc); |
---|
88 | } |
---|
89 | |
---|
90 | for (i = 0; i < media_block_count; i += 2) { |
---|
91 | sc = rtems_bdbuf_read(dd, i, &media_bd [i]); |
---|
92 | ASSERT_SC(sc); |
---|
93 | |
---|
94 | rtems_test_assert(media_bd [i]->buffer [0] == buf [i] + media_block_count); |
---|
95 | } |
---|
96 | |
---|
97 | sc = rtems_bdbuf_set_block_size(dd, media_size, true); |
---|
98 | ASSERT_SC(sc); |
---|
99 | |
---|
100 | for (i = 0; i < media_block_count; i += 2) { |
---|
101 | rtems_test_assert(media_bd [i]->state == RTEMS_BDBUF_STATE_ACCESS_PURGED); |
---|
102 | rtems_test_assert(media_bd [i + 1]->state == RTEMS_BDBUF_STATE_FREE); |
---|
103 | |
---|
104 | rtems_test_assert(media_bd [i]->buffer [0] == buf [i] + media_block_count); |
---|
105 | rtems_test_assert(media_bd [i + 1]->buffer [0] == buf [i + 1]); |
---|
106 | |
---|
107 | sc = rtems_bdbuf_release(media_bd [i]); |
---|
108 | ASSERT_SC(sc); |
---|
109 | } |
---|
110 | |
---|
111 | sc = rtems_bdbuf_read(dd, 0, &large_bd); |
---|
112 | ASSERT_SC(sc); |
---|
113 | |
---|
114 | rtems_test_assert(memcmp(buf, large_bd->buffer, media_size) == 0); |
---|
115 | |
---|
116 | sc = rtems_bdbuf_release(large_bd); |
---|
117 | ASSERT_SC(sc); |
---|
118 | |
---|
119 | rv = close(fd); |
---|
120 | rtems_test_assert(rv == 0); |
---|
121 | |
---|
122 | rv = unlink(device); |
---|
123 | rtems_test_assert(rv == 0); |
---|
124 | } |
---|
125 | |
---|
126 | static 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_CONSOLE_DRIVER |
---|
139 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
140 | |
---|
141 | #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1 |
---|
142 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 8 |
---|
143 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE 8 |
---|
144 | |
---|
145 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
146 | |
---|
147 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
148 | |
---|
149 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
150 | |
---|
151 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
152 | |
---|
153 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
154 | |
---|
155 | #define CONFIGURE_INIT |
---|
156 | |
---|
157 | #include <rtems/confdefs.h> |
---|