source: rtems/testsuites/libtests/block03/init.c @ 90d24022

4.104.115
Last change on this file since 90d24022 was 90d24022, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 10/29/09 at 12:55:30

Added block02, block03 and block04

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup test_bdbuf
5 *
6 * @brief Bdbuf test.
7 */
8
9/*
10 * Copyright (c) 2009
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <assert.h>
23
24#include <rtems.h>
25#include <rtems/ramdisk.h>
26#include <rtems/bdbuf.h>
27#include <rtems/diskdevs.h>
28
29#define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
30
31#define PRIORITY_INIT 10
32
33#define PRIORITY_SWAPOUT 50
34
35#define PRIORITY_HIGH 30
36
37#define PRIORITY_LOW 40
38
39#define BLOCK_SIZE 512
40
41#define BLOCK_COUNT 2
42
43static dev_t dev;
44
45static volatile bool sync_done = false;
46
47static rtems_id task_id_low;
48
49static rtems_id task_id_high;
50
51static void task_low(rtems_task_argument arg)
52{
53  rtems_status_code sc = RTEMS_SUCCESSFUL;
54  rtems_bdbuf_buffer *bd = NULL;
55
56  assert(!sync_done);
57
58  printk("L: try access: 0\n");
59
60  sc = rtems_bdbuf_get(dev, 0, &bd);
61  ASSERT_SC(sc);
62
63  assert(sync_done);
64
65  printk("L: access: 0\n");
66
67  assert(bd->block == 0);
68
69  printk("*** END OF TEST BLOCK 3 ***\n");
70
71  exit(0);
72}
73
74static void task_high(rtems_task_argument arg)
75{
76  rtems_status_code sc = RTEMS_SUCCESSFUL;
77  rtems_bdbuf_buffer *bd = NULL;
78
79  assert(!sync_done);
80
81  printk("H: try access: 0\n");
82
83  sc = rtems_bdbuf_get(dev, 0, &bd);
84  ASSERT_SC(sc);
85
86  assert(sync_done);
87
88  printk("H: access: 0\n");
89
90  printk("H: release: 0\n");
91
92  sc = rtems_bdbuf_release(bd);
93  ASSERT_SC(sc);
94
95  printk("H: release done: 0\n");
96
97  printk("H: try access: 1\n");
98
99  sc = rtems_bdbuf_get(dev, 1, &bd);
100  ASSERT_SC(sc);
101
102  printk("H: access: 1\n");
103
104  /* If we reach this code, we have likely a bug */
105
106  printk("H: release: 1\n");
107
108  sc = rtems_bdbuf_release(bd);
109  ASSERT_SC(sc);
110
111  printk("H: release done: 1\n");
112
113  rtems_task_delete(RTEMS_SELF);
114}
115
116static rtems_task Init(rtems_task_argument argument)
117{
118  rtems_status_code sc = RTEMS_SUCCESSFUL;
119  rtems_bdbuf_buffer *bd = NULL;
120
121  printk("\n\n*** TEST BLOCK 3 ***\n");
122
123  sc = rtems_disk_io_initialize();
124  ASSERT_SC(sc);
125
126  sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
127  ASSERT_SC(sc);
128
129  sc = rtems_task_create(
130    rtems_build_name(' ', 'L', 'O', 'W'),
131    PRIORITY_LOW,
132    0,
133    RTEMS_DEFAULT_MODES,
134    RTEMS_DEFAULT_ATTRIBUTES,
135    &task_id_low
136  );
137  ASSERT_SC(sc);
138
139  sc = rtems_task_start(task_id_low, task_low, 0);
140  ASSERT_SC(sc);
141
142  sc = rtems_task_create(
143    rtems_build_name('H', 'I', 'G', 'H'),
144    PRIORITY_HIGH,
145    0,
146    RTEMS_DEFAULT_MODES,
147    RTEMS_DEFAULT_ATTRIBUTES,
148    &task_id_high
149  );
150  ASSERT_SC(sc);
151
152  sc = rtems_task_start(task_id_high, task_high, 0);
153  ASSERT_SC(sc);
154
155  sc = rtems_bdbuf_get(dev, 0, &bd);
156  ASSERT_SC(sc);
157
158  sc = rtems_bdbuf_sync(bd);
159  ASSERT_SC(sc);
160
161  printk("I: sync done: 0\n");
162
163  sync_done = true;
164
165  sc = rtems_task_suspend(RTEMS_SELF);
166  ASSERT_SC(sc);
167}
168
169#define CONFIGURE_INIT
170
171#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
172#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
173#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
174
175#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
176
177#define CONFIGURE_MAXIMUM_TASKS 5
178#define CONFIGURE_MAXIMUM_DRIVERS 2
179#define CONFIGURE_MAXIMUM_SEMAPHORES 5
180
181#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
182
183#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
184#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
185#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
186
187#define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
188
189#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE
190#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE
191#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_SIZE
192
193#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.