source: rtems/testsuites/libtests/block08/bdbuf_test4_3.c @ 78da8ac3

4.115
Last change on this file since 78da8ac3 was 64734fc, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 01/19/10 at 08:55:18

updates and new test cases

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