source: rtems/testsuites/libtests/block07/init.c @ 8c1f4064

5
Last change on this file since 8c1f4064 was 0d796d6, checked in by Sebastian Huber <sebastian.huber@…>, on 11/02/17 at 13:08:02

tests: Delete obsolete TESTS_USE_PRINTF

Update #3170.
Update #3199.

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