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