source: rtems/testsuites/libtests/block02/init.c @ 24b94c4

Last change on this file since 24b94c4 was 24b94c4, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 30, 2018 at 4:39:09 AM

ramdisk: Use rtems_blkdev_create()

Update #3358.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup test_bdbuf
5 *
6 * @brief Bdbuf test.
7 */
8
9/*
10 * Copyright (c) 2009, 2018 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "tmacros.h"
28
29#include <rtems.h>
30#include <rtems/bspIo.h>
31#include <rtems/ramdisk.h>
32#include <rtems/bdbuf.h>
33
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <unistd.h>
37
38const char rtems_test_name[] = "BLOCK 2";
39
40#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
41
42#define PRIORITY_INIT 10
43
44#define PRIORITY_SWAPOUT 50
45
46#define PRIORITY_HIGH 30
47
48#define PRIORITY_LOW 40
49
50#define BLOCK_SIZE_A 512
51
52#define BLOCK_COUNT_A 2
53
54#define BLOCK_SIZE_B 1024
55
56#define BLOCK_COUNT_B 1
57
58static rtems_disk_device *dd_a;
59
60static rtems_disk_device *dd_b;
61
62static volatile bool sync_done = false;
63
64static rtems_id task_id_low;
65
66static rtems_id task_id_high;
67
68static void task_low(rtems_task_argument arg)
69{
70  rtems_status_code sc = RTEMS_SUCCESSFUL;
71  rtems_bdbuf_buffer *bd = NULL;
72
73  rtems_test_assert(!sync_done);
74
75  printk("L: try access: A0\n");
76
77  sc = rtems_bdbuf_get(dd_a, 0, &bd);
78  ASSERT_SC(sc);
79
80  rtems_test_assert(sync_done);
81
82  printk("L: access: A0\n");
83
84  rtems_test_assert(bd->dd == dd_a);
85
86  TEST_END();
87
88  exit(0);
89}
90
91static void task_high(rtems_task_argument arg)
92{
93  rtems_status_code sc = RTEMS_SUCCESSFUL;
94  rtems_bdbuf_buffer *bd = NULL;
95
96  rtems_test_assert(!sync_done);
97
98  printk("H: try access: A0\n");
99
100  sc = rtems_bdbuf_get(dd_a, 0, &bd);
101  ASSERT_SC(sc);
102
103  rtems_test_assert(sync_done);
104
105  printk("H: access: A0\n");
106
107  printk("H: release: A0\n");
108
109  sc = rtems_bdbuf_release(bd);
110  ASSERT_SC(sc);
111
112  printk("H: release done: A0\n");
113
114  printk("H: try access: B0\n");
115
116  sc = rtems_bdbuf_get(dd_b, 0, &bd);
117  ASSERT_SC(sc);
118
119  printk("H: access: B0\n");
120
121  /* If we reach this code, we have likely a bug */
122
123  printk("H: release: B0\n");
124
125  sc = rtems_bdbuf_release(bd);
126  ASSERT_SC(sc);
127
128  printk("H: release done: B0\n");
129
130  rtems_task_delete(RTEMS_SELF);
131}
132
133static void do_ramdisk_register(
134  uint32_t media_block_size,
135  rtems_blkdev_bnum media_block_count,
136  const char *disk,
137  rtems_disk_device **dd
138)
139{
140  rtems_status_code sc;
141  int fd;
142  int rv;
143
144  sc = ramdisk_register(media_block_size, media_block_count, false, disk);
145  ASSERT_SC(sc);
146
147  fd = open(disk, O_RDWR);
148  rtems_test_assert(fd >= 0);
149
150  rv = rtems_disk_fd_get_disk_device(fd, dd);
151  rtems_test_assert(rv == 0);
152
153  rv = close(fd);
154  rtems_test_assert(rv == 0);
155}
156
157static rtems_task Init(rtems_task_argument argument)
158{
159  rtems_status_code sc = RTEMS_SUCCESSFUL;
160  rtems_bdbuf_buffer *bd = NULL;
161
162  TEST_BEGIN();
163
164  do_ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, "/dev/rda", &dd_a);
165  do_ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, "/dev/rdb", &dd_b);
166
167  sc = rtems_task_create(
168    rtems_build_name(' ', 'L', 'O', 'W'),
169    PRIORITY_LOW,
170    0,
171    RTEMS_DEFAULT_MODES,
172    RTEMS_DEFAULT_ATTRIBUTES,
173    &task_id_low
174  );
175  ASSERT_SC(sc);
176
177  sc = rtems_task_start(task_id_low, task_low, 0);
178  ASSERT_SC(sc);
179
180  sc = rtems_task_create(
181    rtems_build_name('H', 'I', 'G', 'H'),
182    PRIORITY_HIGH,
183    0,
184    RTEMS_DEFAULT_MODES,
185    RTEMS_DEFAULT_ATTRIBUTES,
186    &task_id_high
187  );
188  ASSERT_SC(sc);
189
190  sc = rtems_task_start(task_id_high, task_high, 0);
191  ASSERT_SC(sc);
192
193  sc = rtems_bdbuf_get(dd_a, 0, &bd);
194  ASSERT_SC(sc);
195
196  sc = rtems_bdbuf_sync(bd);
197  ASSERT_SC(sc);
198
199  printk("I: sync done: A0\n");
200
201  sync_done = true;
202
203  sc = rtems_task_suspend(RTEMS_SELF);
204  ASSERT_SC(sc);
205}
206
207#define CONFIGURE_INIT
208
209#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
210#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
211#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
212
213#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
214
215#define CONFIGURE_MAXIMUM_TASKS 3
216
217#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
218
219#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
220
221#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
222#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
223#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
224
225#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
226
227#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
228#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
229#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE_B
230
231#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.