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

5
Last change on this file since 24b94c4 was 24b94c4, checked in by Sebastian Huber <sebastian.huber@…>, on 07/30/18 at 04:39:09

ramdisk: Use rtems_blkdev_create()

Update #3358.

  • Property mode set to 100644
File size: 3.8 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 4";
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 512
51
52#define BLOCK_COUNT 1
53
54static rtems_disk_device *dd;
55
56static rtems_id task_id_low;
57
58static rtems_id task_id_high;
59
60static void task_low(rtems_task_argument arg)
61{
62  rtems_status_code sc = RTEMS_SUCCESSFUL;
63  rtems_bdbuf_buffer *bd = NULL;
64
65  printk("L: try access: 0\n");
66
67  sc = rtems_bdbuf_get(dd, 0, &bd);
68  ASSERT_SC(sc);
69
70  printk("L: access: 0\n");
71
72  sc = rtems_task_resume(task_id_high);
73  ASSERT_SC(sc);
74
75  sc = rtems_bdbuf_sync(bd);
76  ASSERT_SC(sc);
77
78  printk("L: sync done: 0\n");
79
80  rtems_test_assert(false);
81}
82
83static void task_high(rtems_task_argument arg)
84{
85  rtems_status_code sc = RTEMS_SUCCESSFUL;
86  rtems_bdbuf_buffer *bd = NULL;
87
88  sc = rtems_task_suspend(RTEMS_SELF);
89  ASSERT_SC(sc);
90
91  printk("H: try access: 0\n");
92
93  sc = rtems_bdbuf_get(dd, 0, &bd);
94  ASSERT_SC(sc);
95
96  printk("H: access: 0\n");
97
98  printk("H: release: 0\n");
99
100  sc = rtems_bdbuf_release(bd);
101  ASSERT_SC(sc);
102
103  printk("H: release done: 0\n");
104
105  TEST_END();
106
107  exit(0);
108}
109
110static void do_ramdisk_register(
111  uint32_t media_block_size,
112  rtems_blkdev_bnum media_block_count,
113  const char *disk,
114  rtems_disk_device **dd
115)
116{
117  rtems_status_code sc;
118  int fd;
119  int rv;
120
121  sc = ramdisk_register(media_block_size, media_block_count, false, disk);
122  ASSERT_SC(sc);
123
124  fd = open(disk, O_RDWR);
125  rtems_test_assert(fd >= 0);
126
127  rv = rtems_disk_fd_get_disk_device(fd, dd);
128  rtems_test_assert(rv == 0);
129
130  rv = close(fd);
131  rtems_test_assert(rv == 0);
132}
133
134static rtems_task Init(rtems_task_argument argument)
135{
136  rtems_status_code sc = RTEMS_SUCCESSFUL;
137
138  TEST_BEGIN();
139
140  do_ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, "/dev/rda", &dd);
141
142  sc = rtems_task_create(
143    rtems_build_name(' ', 'L', 'O', 'W'),
144    PRIORITY_LOW,
145    0,
146    RTEMS_DEFAULT_MODES,
147    RTEMS_DEFAULT_ATTRIBUTES,
148    &task_id_low
149  );
150  ASSERT_SC(sc);
151
152  sc = rtems_task_start(task_id_low, task_low, 0);
153  ASSERT_SC(sc);
154
155  sc = rtems_task_create(
156    rtems_build_name('H', 'I', 'G', 'H'),
157    PRIORITY_HIGH,
158    0,
159    RTEMS_DEFAULT_MODES,
160    RTEMS_DEFAULT_ATTRIBUTES,
161    &task_id_high
162  );
163  ASSERT_SC(sc);
164
165  sc = rtems_task_start(task_id_high, task_high, 0);
166  ASSERT_SC(sc);
167
168  sc = rtems_task_suspend(RTEMS_SELF);
169  ASSERT_SC(sc);
170}
171
172#define CONFIGURE_INIT
173
174#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
175#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
176#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
177
178#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
179
180#define CONFIGURE_MAXIMUM_TASKS 3
181
182#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
183
184#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
185
186#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
187#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
188#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
189
190#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
191
192#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE
193#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE
194#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE
195
196#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.