source: rtems/testsuites/libtests/block07/init.c @ 7d3f9c6

4.115
Last change on this file since 7d3f9c6 was 7d3f9c6, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 07:37:03

Add HAVE_CONFIG_H.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup test_bdbuf
5 *
6 * @brief Bdbuf test for block size change event.
7 */
8
9/*
10 * Copyright (c) 2009
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <sys/ioctl.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include "tmacros.h"
31
32#include <rtems.h>
33#include <rtems/ramdisk.h>
34#include <rtems/bdbuf.h>
35#include <rtems/diskdevs.h>
36
37#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
38
39#define PRIORITY_INIT 1
40
41#define PRIORITY_HIGH 2
42
43#define PRIORITY_MID 3
44
45#define PRIORITY_LOW 4
46
47#define PRIORITY_SWAPOUT 5
48
49#define PRIORITY_IDLE 6
50
51#define BLOCK_SIZE_A 1
52
53#define BLOCK_SIZE_B 2
54
55#define BLOCK_COUNT 2
56
57static dev_t dev;
58
59static rtems_id task_id_low;
60
61static rtems_id task_id_mid;
62
63static rtems_id task_id_high;
64
65static void change_block_size(void)
66{
67  int rv = 0;
68  uint32_t new_block_size = BLOCK_SIZE_B;
69  int fd = open("/dev/rda", O_RDWR);
70
71  rtems_test_assert(fd >= 0);
72
73  rv = ioctl(fd, RTEMS_BLKIO_SETBLKSIZE, &new_block_size);
74  rtems_test_assert(rv == 0);
75
76  rv = close(fd);
77  rtems_test_assert(rv == 0);
78}
79
80static void task_low(rtems_task_argument arg)
81{
82  rtems_status_code sc = RTEMS_SUCCESSFUL;
83  rtems_bdbuf_buffer *bd = NULL;
84
85  printk("L: try access: 0\n");
86
87  sc = rtems_bdbuf_get(dev, 0, &bd);
88  ASSERT_SC(sc);
89
90  printk("L: access: 0\n");
91
92  rtems_test_assert(bd->group->bds_per_group == 2);
93
94  printk("L: release: 0\n");
95
96  sc = rtems_bdbuf_release(bd);
97  ASSERT_SC(sc);
98
99  printk("L: release done: 0\n");
100
101  printk("*** END OF TEST BLOCK 7 ***\n");
102
103  exit(0);
104}
105
106static void task_mid(rtems_task_argument arg)
107{
108  rtems_status_code sc = RTEMS_SUCCESSFUL;
109  rtems_bdbuf_buffer *bd = NULL;
110
111  printk("M: try access: 0\n");
112
113  sc = rtems_bdbuf_get(dev, 0, &bd);
114  ASSERT_SC(sc);
115
116  printk("M: access: 0\n");
117
118  rtems_test_assert(bd->group->bds_per_group == 1);
119
120  printk("M: release: 0\n");
121
122  sc = rtems_bdbuf_release(bd);
123  ASSERT_SC(sc);
124
125  printk("M: release done: 0\n");
126
127  rtems_task_delete(RTEMS_SELF);
128}
129
130static void task_high(rtems_task_argument arg)
131{
132  rtems_status_code sc = RTEMS_SUCCESSFUL;
133  rtems_bdbuf_buffer *bd = NULL;
134
135  change_block_size();
136
137  printk("H: try access: 0\n");
138
139  sc = rtems_bdbuf_get(dev, 0, &bd);
140  ASSERT_SC(sc);
141
142  printk("H: access: 0\n");
143
144  rtems_test_assert(bd->group->bds_per_group == 1);
145
146  printk("H: release: 0\n");
147
148  sc = rtems_bdbuf_release(bd);
149  ASSERT_SC(sc);
150
151  printk("H: release done: 0\n");
152
153  rtems_task_delete(RTEMS_SELF);
154}
155
156static rtems_task Init(rtems_task_argument argument)
157{
158  rtems_status_code sc = RTEMS_SUCCESSFUL;
159  rtems_task_priority cur_prio = 0;
160  rtems_bdbuf_buffer *bd = NULL;
161
162  printk("\n\n*** TEST BLOCK 7 ***\n");
163
164  sc = rtems_disk_io_initialize();
165  ASSERT_SC(sc);
166
167  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
168  ASSERT_SC(sc);
169
170  sc = rtems_task_create(
171    rtems_build_name(' ', 'L', 'O', 'W'),
172    PRIORITY_LOW,
173    0,
174    RTEMS_DEFAULT_MODES,
175    RTEMS_DEFAULT_ATTRIBUTES,
176    &task_id_low
177  );
178  ASSERT_SC(sc);
179
180  sc = rtems_task_start(task_id_low, task_low, 0);
181  ASSERT_SC(sc);
182
183  sc = rtems_task_create(
184    rtems_build_name(' ', 'M', 'I', 'D'),
185    PRIORITY_MID,
186    0,
187    RTEMS_DEFAULT_MODES,
188    RTEMS_DEFAULT_ATTRIBUTES,
189    &task_id_mid
190  );
191  ASSERT_SC(sc);
192
193  sc = rtems_task_start(task_id_mid, task_mid, 0);
194  ASSERT_SC(sc);
195
196  sc = rtems_task_create(
197    rtems_build_name('H', 'I', 'G', 'H'),
198    PRIORITY_HIGH,
199    0,
200    RTEMS_DEFAULT_MODES,
201    RTEMS_DEFAULT_ATTRIBUTES,
202    &task_id_high
203  );
204  ASSERT_SC(sc);
205
206  sc = rtems_task_start(task_id_high, task_high, 0);
207  ASSERT_SC(sc);
208
209  sc = rtems_task_suspend(task_id_mid);
210  ASSERT_SC(sc);
211
212  sc = rtems_task_suspend(task_id_high);
213  ASSERT_SC(sc);
214
215  sc = rtems_bdbuf_get(dev, 1, &bd);
216  ASSERT_SC(sc);
217
218  sc = rtems_bdbuf_release(bd);
219  ASSERT_SC(sc);
220
221  printk("I: try access: 0\n");
222
223  sc = rtems_bdbuf_get(dev, 0, &bd);
224  ASSERT_SC(sc);
225
226  printk("I: access: 0\n");
227
228  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_IDLE, &cur_prio);
229  ASSERT_SC(sc);
230
231  sc = rtems_task_resume(task_id_high);
232  ASSERT_SC(sc);
233
234  sc = rtems_task_resume(task_id_mid);
235  ASSERT_SC(sc);
236
237  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_INIT, &cur_prio);
238  ASSERT_SC(sc);
239
240  printk("I: release: 0\n");
241
242  sc = rtems_bdbuf_release(bd);
243  ASSERT_SC(sc);
244
245  printk("I: release done: 0\n");
246
247  rtems_task_delete(RTEMS_SELF);
248}
249
250#define CONFIGURE_INIT
251
252#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
253#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
254#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
255
256#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
257#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
258
259#define CONFIGURE_MAXIMUM_TASKS 6
260#define CONFIGURE_MAXIMUM_DRIVERS 2
261
262#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
263
264#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
265#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
266#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
267
268#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
269
270#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
271#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
272#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_SIZE_A * BLOCK_COUNT)
273
274#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.