source: rtems/testsuites/libtests/block02/init.c @ c4b8b147

Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 3, 2017 at 7:35:38 AM

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup test_bdbuf
5 *
6 * @brief Bdbuf test.
7 */
8
9/*
10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
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#include <rtems/diskdevs.h>
34
35const char rtems_test_name[] = "BLOCK 2";
36
37/* forward declarations to avoid warnings */
38static rtems_task Init(rtems_task_argument argument);
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 rtems_task Init(rtems_task_argument argument)
134{
135  rtems_status_code sc = RTEMS_SUCCESSFUL;
136  rtems_bdbuf_buffer *bd = NULL;
137  dev_t dev_a = 0;
138  dev_t dev_b = 0;
139
140  TEST_BEGIN();
141
142  sc = rtems_disk_io_initialize();
143  ASSERT_SC(sc);
144
145  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, false, "/dev/rda", &dev_a);
146  ASSERT_SC(sc);
147
148  sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
149  ASSERT_SC(sc);
150
151  dd_a = rtems_disk_obtain(dev_a);
152  rtems_test_assert(dd_a != NULL);
153
154  dd_b = rtems_disk_obtain(dev_b);
155  rtems_test_assert(dd_b != NULL);
156
157  sc = rtems_task_create(
158    rtems_build_name(' ', 'L', 'O', 'W'),
159    PRIORITY_LOW,
160    0,
161    RTEMS_DEFAULT_MODES,
162    RTEMS_DEFAULT_ATTRIBUTES,
163    &task_id_low
164  );
165  ASSERT_SC(sc);
166
167  sc = rtems_task_start(task_id_low, task_low, 0);
168  ASSERT_SC(sc);
169
170  sc = rtems_task_create(
171    rtems_build_name('H', 'I', 'G', 'H'),
172    PRIORITY_HIGH,
173    0,
174    RTEMS_DEFAULT_MODES,
175    RTEMS_DEFAULT_ATTRIBUTES,
176    &task_id_high
177  );
178  ASSERT_SC(sc);
179
180  sc = rtems_task_start(task_id_high, task_high, 0);
181  ASSERT_SC(sc);
182
183  sc = rtems_bdbuf_get(dd_a, 0, &bd);
184  ASSERT_SC(sc);
185
186  sc = rtems_bdbuf_sync(bd);
187  ASSERT_SC(sc);
188
189  printk("I: sync done: A0\n");
190
191  sync_done = true;
192
193  sc = rtems_task_suspend(RTEMS_SELF);
194  ASSERT_SC(sc);
195}
196
197#define CONFIGURE_INIT
198
199#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
200#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
201#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
202
203#define CONFIGURE_MAXIMUM_TASKS 3
204#define CONFIGURE_MAXIMUM_DRIVERS 3
205
206#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
207
208#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
209
210#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
211#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
212#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
213
214#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
215
216#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
217#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
218#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE_B
219
220#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.