source: rtems/testsuites/libtests/block02/init.c @ 7e102915

5
Last change on this file since 7e102915 was 7e102915, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:09

tests: Use rtems_test_printer in general

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 4.4 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#define TEST_INIT
28
29#define TESTS_USE_PRINTK
30#include "tmacros.h"
31
32#include <rtems.h>
33#include <rtems/bspIo.h>
34#include <rtems/ramdisk.h>
35#include <rtems/bdbuf.h>
36#include <rtems/diskdevs.h>
37
38const char rtems_test_name[] = "BLOCK 2";
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 10
46
47#define PRIORITY_SWAPOUT 50
48
49#define PRIORITY_HIGH 30
50
51#define PRIORITY_LOW 40
52
53#define BLOCK_SIZE_A 512
54
55#define BLOCK_COUNT_A 2
56
57#define BLOCK_SIZE_B 1024
58
59#define BLOCK_COUNT_B 1
60
61static rtems_disk_device *dd_a;
62
63static rtems_disk_device *dd_b;
64
65static volatile bool sync_done = false;
66
67static rtems_id task_id_low;
68
69static rtems_id task_id_high;
70
71static void task_low(rtems_task_argument arg)
72{
73  rtems_status_code sc = RTEMS_SUCCESSFUL;
74  rtems_bdbuf_buffer *bd = NULL;
75
76  rtems_test_assert(!sync_done);
77
78  printk("L: try access: A0\n");
79
80  sc = rtems_bdbuf_get(dd_a, 0, &bd);
81  ASSERT_SC(sc);
82
83  rtems_test_assert(sync_done);
84
85  printk("L: access: A0\n");
86
87  rtems_test_assert(bd->dd == dd_a);
88
89  TEST_END();
90
91  exit(0);
92}
93
94static void task_high(rtems_task_argument arg)
95{
96  rtems_status_code sc = RTEMS_SUCCESSFUL;
97  rtems_bdbuf_buffer *bd = NULL;
98
99  rtems_test_assert(!sync_done);
100
101  printk("H: try access: A0\n");
102
103  sc = rtems_bdbuf_get(dd_a, 0, &bd);
104  ASSERT_SC(sc);
105
106  rtems_test_assert(sync_done);
107
108  printk("H: access: A0\n");
109
110  printk("H: release: A0\n");
111
112  sc = rtems_bdbuf_release(bd);
113  ASSERT_SC(sc);
114
115  printk("H: release done: A0\n");
116
117  printk("H: try access: B0\n");
118
119  sc = rtems_bdbuf_get(dd_b, 0, &bd);
120  ASSERT_SC(sc);
121
122  printk("H: access: B0\n");
123
124  /* If we reach this code, we have likely a bug */
125
126  printk("H: release: B0\n");
127
128  sc = rtems_bdbuf_release(bd);
129  ASSERT_SC(sc);
130
131  printk("H: release done: B0\n");
132
133  rtems_task_delete(RTEMS_SELF);
134}
135
136static rtems_task Init(rtems_task_argument argument)
137{
138  rtems_status_code sc = RTEMS_SUCCESSFUL;
139  rtems_bdbuf_buffer *bd = NULL;
140  dev_t dev_a = 0;
141  dev_t dev_b = 0;
142
143  TEST_BEGIN();
144
145  sc = rtems_disk_io_initialize();
146  ASSERT_SC(sc);
147
148  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, false, "/dev/rda", &dev_a);
149  ASSERT_SC(sc);
150
151  sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
152  ASSERT_SC(sc);
153
154  dd_a = rtems_disk_obtain(dev_a);
155  rtems_test_assert(dd_a != NULL);
156
157  dd_b = rtems_disk_obtain(dev_b);
158  rtems_test_assert(dd_b != NULL);
159
160  sc = rtems_task_create(
161    rtems_build_name(' ', 'L', 'O', 'W'),
162    PRIORITY_LOW,
163    0,
164    RTEMS_DEFAULT_MODES,
165    RTEMS_DEFAULT_ATTRIBUTES,
166    &task_id_low
167  );
168  ASSERT_SC(sc);
169
170  sc = rtems_task_start(task_id_low, task_low, 0);
171  ASSERT_SC(sc);
172
173  sc = rtems_task_create(
174    rtems_build_name('H', 'I', 'G', 'H'),
175    PRIORITY_HIGH,
176    0,
177    RTEMS_DEFAULT_MODES,
178    RTEMS_DEFAULT_ATTRIBUTES,
179    &task_id_high
180  );
181  ASSERT_SC(sc);
182
183  sc = rtems_task_start(task_id_high, task_high, 0);
184  ASSERT_SC(sc);
185
186  sc = rtems_bdbuf_get(dd_a, 0, &bd);
187  ASSERT_SC(sc);
188
189  sc = rtems_bdbuf_sync(bd);
190  ASSERT_SC(sc);
191
192  printk("I: sync done: A0\n");
193
194  sync_done = true;
195
196  sc = rtems_task_suspend(RTEMS_SELF);
197  ASSERT_SC(sc);
198}
199
200#define CONFIGURE_INIT
201
202#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
203#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
204#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
205
206#define CONFIGURE_MAXIMUM_TASKS 3
207#define CONFIGURE_MAXIMUM_DRIVERS 3
208
209#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
210
211#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
212
213#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
214#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
215#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
216
217#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
218
219#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
220#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
221#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE_B
222
223#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.