source: rtems/testsuites/libtests/block08/bdbuf_test4_3.c @ 7d3f9c6

4.115
Last change on this file since 7d3f9c6 was 7d3f9c6, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 07:37:03

Add HAVE_CONFIG_H.

  • Property mode set to 100644
File size: 3.2 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_sync(#N) in thread #1.
7 * -# After a while disk driver gets write request for block #N.
8 *    Notify bdbuf about write complete event.
9 * -# Check that rtems_bdbuf_sync(#N) in thread #1 unlocked after this.
10 * -# Call rtems_bdbuf_read(#N) in thread #2.
11 * -# Check that buffer is successfully obtained in thread #2.
12 * -# Call rtems_bdbuf_release(#N) in thread #2.
13 * .
14 *
15 * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
16 * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
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.com/license/LICENSE.
21 *
22 * $Id$
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <bdbuf_tests.h>
30
31static rtems_task bdbuf_test4_3_thread1(rtems_task_argument arg);
32static rtems_task bdbuf_test4_3_thread2(rtems_task_argument arg);
33
34/* Block number used in the test */
35#define TEST_BLK_NUM_N 116
36
37void
38bdbuf_test4_3_main()
39{
40    bdbuf_test_msg msg;
41
42    TEST_START("Test 4.3");
43
44    START_THREAD(1, bdbuf_test4_3_thread1);
45    START_THREAD(2, bdbuf_test4_3_thread2);
46
47    /*
48     * Step 1:
49     * Call rtems_bdbuf_read(#N) in thread #1.
50     * Wait for read request in disk driver.
51     */
52    WAIT_DRV_MSG(&msg);
53    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
54
55    /*
56     * Step 2:
57     * Call rtems_bdbuf_sync(#N) in thread #1.
58     * As the result buffer is asked to be flashed onto the disk.
59     */
60    WAIT_DRV_MSG_WR(&msg);
61    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
62
63    /*
64     * Step 4:
65     * Check that rtems_bdbuf_sync(#N) call is unlocked.
66     */
67    WAIT_THREAD_SYNC(1);
68    TEST_CHECK_RESULT("4");
69
70    /*
71     * Step 5:
72     * Call rtems_bdbuf_read(#N) in thread #2.
73     */
74    CONTINUE_THREAD(2);
75
76    /*
77     * Step 6:
78     * Check that thread #2 successfully got the buffer.
79     */
80    WAIT_THREAD_SYNC(2);
81
82    /*
83     * Step 7:
84     * Release buffer in thread #2
85     */
86    CONTINUE_THREAD(2);
87
88    /*
89     * Exit from thread #1.
90     */
91    CONTINUE_THREAD(1);
92
93    TEST_END();
94}
95
96static rtems_task
97bdbuf_test4_3_thread1(rtems_task_argument arg)
98{
99    rtems_status_code   rc;
100    rtems_bdbuf_buffer *bd = NULL;
101
102    /*
103     * Step 1:
104     * Call rtems_bdbuf_read(#N) in thread #1;
105     */
106    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
107    if (rc != RTEMS_SUCCESSFUL)
108    {
109        TEST_FAILED();
110    }
111
112    /*
113     * Step 2:
114     * Call rtems_bdbuf_sync(#N)
115     */
116    rc = rtems_bdbuf_sync(bd);
117    if (rc != RTEMS_SUCCESSFUL)
118    {
119        TEST_FAILED();
120    }
121
122    CONTINUE_MAIN(1);
123
124    THREAD_END();
125}
126
127static rtems_task
128bdbuf_test4_3_thread2(rtems_task_argument arg)
129{
130    rtems_status_code   rc;
131    rtems_bdbuf_buffer *bd = NULL;
132
133    WAIT_MAIN_SYNC(2);
134
135    /*
136     * Step 5:
137     * In thread #2 call rtems_bdbuf_read(#N).
138     * We will block on this call.
139     */
140    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
141    if (rc != RTEMS_SUCCESSFUL)
142    {
143        TEST_FAILED();
144    }
145
146    CONTINUE_MAIN(2);
147
148    /*
149     * Release buffer.
150     */
151    rc = rtems_bdbuf_release(bd);
152    if (rc != RTEMS_SUCCESSFUL)
153    {
154        TEST_FAILED();
155    }
156    THREAD_END();
157}
158
159
Note: See TracBrowser for help on using the repository browser.