source: rtems/testsuites/libtests/block08/bdbuf_test4_1.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.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#include <bdbuf_tests.h>
27
28static rtems_task bdbuf_test4_1_thread1(rtems_task_argument arg);
29static rtems_task bdbuf_test4_1_thread2(rtems_task_argument arg);
30
31/* Block number used in the test */
32#define TEST_BLK_NUM_N 112
33
34void
35bdbuf_test4_1_main()
36{
37    bdbuf_test_msg msg;
38
39    TEST_START("Test 4.1");
40
41    START_THREAD(1, bdbuf_test4_1_thread1);
42    START_THREAD(2, bdbuf_test4_1_thread2);
43
44    /*
45     * Step 1:
46     * Call rtems_bdbuf_read(#N) in thread #1.
47     * Wait for read request in disk driver.
48     */
49    WAIT_DRV_MSG(&msg);
50    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
51
52    /* Wait for return from rtems_bdbuf_read(#N) function. */
53    WAIT_THREAD_SYNC(1);
54
55    /*
56     * Step 2:
57     * Call rtems_bdbuf_read(#N) in thread #2.
58     */
59    CONTINUE_THREAD(2);
60   
61    /* Make sure that thread #2 blocks */
62    CHECK_THREAD_BLOCKED(2);
63    TEST_CHECK_RESULT("2");
64
65    /*
66     * Step 3:
67     * Call rtems_bdbuf_sync (#N) in thread #1.
68     */
69    CONTINUE_THREAD(1);
70
71    /*
72     * Setp 4:
73     * Wait for Write request to device driver.
74     */
75    WAIT_DRV_MSG_WR(&msg);
76
77    /* Check that both threads are blocked right now */
78    CHECK_THREAD_BLOCKED(1);
79    CHECK_THREAD_BLOCKED(2);
80
81    /* Send Write complete notification */
82    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
83
84    /*
85     * Step 5:
86     * Check that rtems_bdbuf_sync(#N) call is unlocked.
87     */
88    WAIT_THREAD_SYNC(1);
89    TEST_CHECK_RESULT("5");
90
91    /*
92     * Step 6:
93     * Check that rtems_bdbuf_read(#N) call in thread #2 is unlocked.
94     */
95    WAIT_THREAD_SYNC(2);
96
97    /*
98     * Step 7:
99     * Release buffer in thread #2
100     */
101    CONTINUE_THREAD(2);
102
103    /*
104     * Exit from thread #1.
105     */
106    CONTINUE_THREAD(1);
107
108    TEST_END();
109}
110
111static rtems_task
112bdbuf_test4_1_thread1(rtems_task_argument arg)
113{
114    rtems_status_code   rc;
115    rtems_bdbuf_buffer *bd = NULL;
116
117    /*
118     * Step 1:
119     * Call rtems_bdbuf_read(#N) in thread #1;
120     */
121    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
122    if (rc != RTEMS_SUCCESSFUL)
123    {
124        TEST_FAILED();
125    }
126
127    CONTINUE_MAIN(1);
128   
129    /*
130     * Step 3:
131     * Call rtems_bdbuf_sync(#N)
132     */
133    rc = rtems_bdbuf_sync(bd);
134    if (rc != RTEMS_SUCCESSFUL)
135    {
136        TEST_FAILED();
137    }
138
139    CONTINUE_MAIN(1);
140
141    THREAD_END();
142}
143
144static rtems_task
145bdbuf_test4_1_thread2(rtems_task_argument arg)
146{
147    rtems_status_code   rc;
148    rtems_bdbuf_buffer *bd = NULL;
149
150    WAIT_MAIN_SYNC(2);
151
152    /*
153     * Step 2:
154     * In thread #2 call rtems_bdbuf_read(#N).
155     * We will block on this call.
156     */
157    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
158    if (rc != RTEMS_SUCCESSFUL)
159    {
160        TEST_FAILED();
161    }
162
163    CONTINUE_MAIN(2);
164
165    /*
166     * Release buffer.
167     */
168    rc = rtems_bdbuf_release(bd);
169    if (rc != RTEMS_SUCCESSFUL)
170    {
171        TEST_FAILED();
172    }
173    THREAD_END();
174}
175
176
Note: See TracBrowser for help on using the repository browser.