source: rtems/testsuites/libtests/block07/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 5.6 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.org/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
37const char rtems_test_name[] = "BLOCK 7";
38
39/* forward declarations to avoid warnings */
40static rtems_task Init(rtems_task_argument argument);
41
42#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
43
44#define PRIORITY_INIT 1
45
46#define PRIORITY_HIGH 2
47
48#define PRIORITY_MID 3
49
50#define PRIORITY_LOW 4
51
52#define PRIORITY_SWAPOUT 5
53
54#define PRIORITY_IDLE 6
55
56#define BLOCK_SIZE_A 1
57
58#define BLOCK_SIZE_B 2
59
60#define BLOCK_COUNT 2
61
62static rtems_disk_device *dd;
63
64static rtems_id task_id_low;
65
66static rtems_id task_id_mid;
67
68static rtems_id task_id_high;
69
70static void change_block_size(void)
71{
72  int rv = 0;
73  int fd = open("/dev/rda", O_RDWR);
74
75  rtems_test_assert(fd >= 0);
76
77  rv = rtems_disk_fd_set_block_size(fd, BLOCK_SIZE_B);
78  rtems_test_assert(rv == 0);
79
80  rv = close(fd);
81  rtems_test_assert(rv == 0);
82}
83
84static void task_low(rtems_task_argument arg)
85{
86  rtems_status_code sc = RTEMS_SUCCESSFUL;
87  rtems_bdbuf_buffer *bd = NULL;
88
89  printk("L: try access: 0\n");
90
91  sc = rtems_bdbuf_get(dd, 0, &bd);
92  ASSERT_SC(sc);
93
94  printk("L: access: 0\n");
95
96  rtems_test_assert(bd->group->bds_per_group == 2);
97
98  printk("L: release: 0\n");
99
100  sc = rtems_bdbuf_release(bd);
101  ASSERT_SC(sc);
102
103  printk("L: release done: 0\n");
104
105  rtems_test_endk();
106
107  exit(0);
108}
109
110static void task_mid(rtems_task_argument arg)
111{
112  rtems_status_code sc = RTEMS_SUCCESSFUL;
113  rtems_bdbuf_buffer *bd = NULL;
114
115  printk("M: try access: 0\n");
116
117  sc = rtems_bdbuf_get(dd, 0, &bd);
118  ASSERT_SC(sc);
119
120  printk("M: access: 0\n");
121
122  rtems_test_assert(bd->group->bds_per_group == 1);
123
124  printk("M: release: 0\n");
125
126  sc = rtems_bdbuf_release(bd);
127  ASSERT_SC(sc);
128
129  printk("M: release done: 0\n");
130
131  rtems_task_delete(RTEMS_SELF);
132}
133
134static void task_high(rtems_task_argument arg)
135{
136  rtems_status_code sc = RTEMS_SUCCESSFUL;
137  rtems_bdbuf_buffer *bd = NULL;
138
139  change_block_size();
140
141  printk("H: try access: 0\n");
142
143  sc = rtems_bdbuf_get(dd, 0, &bd);
144  ASSERT_SC(sc);
145
146  printk("H: access: 0\n");
147
148  rtems_test_assert(bd->group->bds_per_group == 1);
149
150  printk("H: release: 0\n");
151
152  sc = rtems_bdbuf_release(bd);
153  ASSERT_SC(sc);
154
155  printk("H: release done: 0\n");
156
157  rtems_task_delete(RTEMS_SELF);
158}
159
160static rtems_task Init(rtems_task_argument argument)
161{
162  rtems_status_code sc = RTEMS_SUCCESSFUL;
163  rtems_task_priority cur_prio = 0;
164  rtems_bdbuf_buffer *bd = NULL;
165  dev_t dev = 0;
166
167  rtems_test_begink();
168
169  sc = rtems_disk_io_initialize();
170  ASSERT_SC(sc);
171
172  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
173  ASSERT_SC(sc);
174
175  dd = rtems_disk_obtain(dev);
176  rtems_test_assert(dd != NULL);
177
178  sc = rtems_task_create(
179    rtems_build_name(' ', 'L', 'O', 'W'),
180    PRIORITY_LOW,
181    0,
182    RTEMS_DEFAULT_MODES,
183    RTEMS_DEFAULT_ATTRIBUTES,
184    &task_id_low
185  );
186  ASSERT_SC(sc);
187
188  sc = rtems_task_start(task_id_low, task_low, 0);
189  ASSERT_SC(sc);
190
191  sc = rtems_task_create(
192    rtems_build_name(' ', 'M', 'I', 'D'),
193    PRIORITY_MID,
194    0,
195    RTEMS_DEFAULT_MODES,
196    RTEMS_DEFAULT_ATTRIBUTES,
197    &task_id_mid
198  );
199  ASSERT_SC(sc);
200
201  sc = rtems_task_start(task_id_mid, task_mid, 0);
202  ASSERT_SC(sc);
203
204  sc = rtems_task_create(
205    rtems_build_name('H', 'I', 'G', 'H'),
206    PRIORITY_HIGH,
207    0,
208    RTEMS_DEFAULT_MODES,
209    RTEMS_DEFAULT_ATTRIBUTES,
210    &task_id_high
211  );
212  ASSERT_SC(sc);
213
214  sc = rtems_task_start(task_id_high, task_high, 0);
215  ASSERT_SC(sc);
216
217  sc = rtems_task_suspend(task_id_mid);
218  ASSERT_SC(sc);
219
220  sc = rtems_task_suspend(task_id_high);
221  ASSERT_SC(sc);
222
223  sc = rtems_bdbuf_get(dd, 1, &bd);
224  ASSERT_SC(sc);
225
226  sc = rtems_bdbuf_release(bd);
227  ASSERT_SC(sc);
228
229  printk("I: try access: 0\n");
230
231  sc = rtems_bdbuf_get(dd, 0, &bd);
232  ASSERT_SC(sc);
233
234  printk("I: access: 0\n");
235
236  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_IDLE, &cur_prio);
237  ASSERT_SC(sc);
238
239  sc = rtems_task_resume(task_id_high);
240  ASSERT_SC(sc);
241
242  sc = rtems_task_resume(task_id_mid);
243  ASSERT_SC(sc);
244
245  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_INIT, &cur_prio);
246  ASSERT_SC(sc);
247
248  printk("I: release: 0\n");
249
250  sc = rtems_bdbuf_release(bd);
251  ASSERT_SC(sc);
252
253  printk("I: release done: 0\n");
254
255  rtems_task_delete(RTEMS_SELF);
256}
257
258#define CONFIGURE_INIT
259
260#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
261#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
262#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
263
264#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
265#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
266
267#define CONFIGURE_MAXIMUM_TASKS 4
268#define CONFIGURE_MAXIMUM_DRIVERS 2
269
270#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
271
272#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
273
274#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
275#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
276#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
277
278#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
279
280#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
281#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
282#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_SIZE_A * BLOCK_COUNT)
283
284#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.