source: rtems/testsuites/libtests/block03/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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