source: rtems/testsuites/libtests/block08/bdbuf_test4_1.c @ 796967c

4.115
Last change on this file since 796967c was 796967c, checked in by Sebastian Huber <sebastian.huber@…>, on 02/28/12 at 16:19:49

libblock: Change bdbuf API

The functions

o rtems_bdbuf_get(),
o rtems_bdbuf_read(),
o rtems_bdbuf_syncdev(), and
o rtems_bdbuf_purge_dev(),

use now the disk device instead of the device identifier. This makes
bdbuf independent of rtems_disk_obtain() and rtems_disk_release(). It
is the responsiblity of the file system to obtain the disk device. This
also reduces the overhead to get a buffer.

The key for the AVL tree uses now the disk device instead of the device
identifier. The pointer is interpreted as an unsigned integer. This
reduces the memory overhead and makes the comparison operation a bit
faster.

Removed function rtems_bdbuf_purge_major(). This function was too
destructive and could have unpredictable side effects.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*! @file
2 * @brief Check how rtems_bdbuf_sync() works.
3 *
4 * Test sequence:
5 * -# Call rtems_bdbuf_read(#N) in thread #1.
6 * -# Call rtems_bdbuf_read(#N) from thread #2.
7 * -# Thread #2 blocks on this call.
8 * -# Call rtems_bdbuf_sync(#N) in thread #1.
9 * -# After a while disk driver gets write request for block #N.
10 *    Notify bdbuf library about write complete event.
11 * -# Check that thread #1 unlocked after this.
12 * -# Check that thread #2 unblocks and get buffer #N.
13 * -# Release buffer in thread #2.
14 * .
15 *
16 * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
17 * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
18 *
19 * The license and distribution terms for this file may be
20 * found in the file LICENSE in this distribution or at
21 * http://www.rtems.com/license/LICENSE.
22 *
23 * $Id$
24 */
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include <bdbuf_tests.h>
31
32static rtems_task bdbuf_test4_1_thread1(rtems_task_argument arg);
33static rtems_task bdbuf_test4_1_thread2(rtems_task_argument arg);
34
35/* Block number used in the test */
36#define TEST_BLK_NUM_N 112
37
38void
39bdbuf_test4_1_main()
40{
41    bdbuf_test_msg msg;
42
43    TEST_START("Test 4.1");
44
45    START_THREAD(1, bdbuf_test4_1_thread1);
46    START_THREAD(2, bdbuf_test4_1_thread2);
47
48    /*
49     * Step 1:
50     * Call rtems_bdbuf_read(#N) in thread #1.
51     * Wait for read request in disk driver.
52     */
53    WAIT_DRV_MSG(&msg);
54    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
55
56    /* Wait for return from rtems_bdbuf_read(#N) function. */
57    WAIT_THREAD_SYNC(1);
58
59    /*
60     * Step 2:
61     * Call rtems_bdbuf_read(#N) in thread #2.
62     */
63    CONTINUE_THREAD(2);
64   
65    /* Make sure that thread #2 blocks */
66    CHECK_THREAD_BLOCKED(2);
67    TEST_CHECK_RESULT("2");
68
69    /*
70     * Step 3:
71     * Call rtems_bdbuf_sync (#N) in thread #1.
72     */
73    CONTINUE_THREAD(1);
74
75    /*
76     * Setp 4:
77     * Wait for Write request to device driver.
78     */
79    WAIT_DRV_MSG_WR(&msg);
80
81    /* Check that both threads are blocked right now */
82    CHECK_THREAD_BLOCKED(1);
83    CHECK_THREAD_BLOCKED(2);
84
85    /* Send Write complete notification */
86    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
87
88    /*
89     * Step 5:
90     * Check that rtems_bdbuf_sync(#N) call is unlocked.
91     */
92    WAIT_THREAD_SYNC(1);
93    TEST_CHECK_RESULT("5");
94
95    /*
96     * Step 6:
97     * Check that rtems_bdbuf_read(#N) call in thread #2 is unlocked.
98     */
99    WAIT_THREAD_SYNC(2);
100
101    /*
102     * Step 7:
103     * Release buffer in thread #2
104     */
105    CONTINUE_THREAD(2);
106
107    /*
108     * Exit from thread #1.
109     */
110    CONTINUE_THREAD(1);
111
112    TEST_END();
113}
114
115static rtems_task
116bdbuf_test4_1_thread1(rtems_task_argument arg)
117{
118    rtems_status_code   rc;
119    rtems_bdbuf_buffer *bd = NULL;
120
121    /*
122     * Step 1:
123     * Call rtems_bdbuf_read(#N) in thread #1;
124     */
125    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
126    if (rc != RTEMS_SUCCESSFUL)
127    {
128        TEST_FAILED();
129    }
130
131    CONTINUE_MAIN(1);
132   
133    /*
134     * Step 3:
135     * Call rtems_bdbuf_sync(#N)
136     */
137    rc = rtems_bdbuf_sync(bd);
138    if (rc != RTEMS_SUCCESSFUL)
139    {
140        TEST_FAILED();
141    }
142
143    CONTINUE_MAIN(1);
144
145    THREAD_END();
146}
147
148static rtems_task
149bdbuf_test4_1_thread2(rtems_task_argument arg)
150{
151    rtems_status_code   rc;
152    rtems_bdbuf_buffer *bd = NULL;
153
154    WAIT_MAIN_SYNC(2);
155
156    /*
157     * Step 2:
158     * In thread #2 call rtems_bdbuf_read(#N).
159     * We will block on this call.
160     */
161    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
162    if (rc != RTEMS_SUCCESSFUL)
163    {
164        TEST_FAILED();
165    }
166
167    CONTINUE_MAIN(2);
168
169    /*
170     * Release buffer.
171     */
172    rc = rtems_bdbuf_release(bd);
173    if (rc != RTEMS_SUCCESSFUL)
174    {
175        TEST_FAILED();
176    }
177    THREAD_END();
178}
179
180
Note: See TracBrowser for help on using the repository browser.