source: rtems/testsuites/libtests/block08/bdbuf_test3_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: 4.7 KB
Line 
1/*! @file
2 * @brief Check how read/release work in case of only one buffer in ready list.
3 *
4 * The same as Test 3.2, but instead of calling rtems_bdbuf_get() in
5 * threads #1 and #2, it calls rtems_bdbuf_read().
6 *
7 * Test sequence:
8 * -# Call rtems_bdbuf_read(#N1) in thread #1.
9 * -# Call rtems_bdbuf_read(#N2) in thread #2.
10 *    This thread blocks because we have no buffers available.
11 * -# Call rtems_bdbuf_read(#N3) in thread #3.
12 *    This thread also blocks because we have no buffers available.
13 * -# Call rtems_bdbuf_release(#N1) in thread #1.
14 * -# Check that only one thread (thread #2 or thread #3) got a buffer.
15 *    Another thread shall still be blocked.
16 * -# Call rtems_bdbuf_release(#N2) in thread #2 and check that
17 *    thread #3 got a buffer as the result.
18 * .
19 *
20 * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
21 * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
22 *
23 * The license and distribution terms for this file may be
24 * found in the file LICENSE in this distribution or at
25 * http://www.rtems.com/license/LICENSE.
26 *
27 * $Id$
28 */
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include <bdbuf_tests.h>
35
36static rtems_task bdbuf_test3_3_thread1(rtems_task_argument arg);
37static rtems_task bdbuf_test3_3_thread2(rtems_task_argument arg);
38static rtems_task bdbuf_test3_3_thread3(rtems_task_argument arg);
39
40/* Block number used in the test */
41#define TEST_BLK_NUM_N1 96
42#define TEST_BLK_NUM_N2 98
43#define TEST_BLK_NUM_N3 100
44
45void
46bdbuf_test3_3_main()
47{
48    bdbuf_test_msg msg;
49
50    TEST_START("Test 3.3");
51
52    /*
53     * Create working threads.
54     */
55    SET_THREAD_PRIORITY(2, LOW);
56    SET_THREAD_PRIORITY(3, HIGH);
57    START_THREAD(1, bdbuf_test3_3_thread1);
58    START_THREAD(2, bdbuf_test3_3_thread2);
59    START_THREAD(3, bdbuf_test3_3_thread3);
60
61    /*
62     * Start thread #1: it will read buffer #N1.
63     * Driver is asked to read this buffer.
64     */
65    WAIT_DRV_MSG(&msg);
66    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
67
68    WAIT_THREAD_SYNC(1);
69
70    /*
71     * Block thread #2 and thread #3 on get buffers #N2 and #N3
72     * correspondingly (bdbuf librbary has no buffers available).
73     */
74    CONTINUE_THREAD(2);
75    CONTINUE_THREAD(3);
76
77    /* Make sure threads managed to block on the buffers get. */
78    CHECK_THREAD_BLOCKED(2);
79    CHECK_THREAD_BLOCKED(3);
80
81    /*
82     * Step 4:
83     * Thread #1 release buffer.
84     */
85    CONTINUE_THREAD(1);
86
87    /* Wait for read request in the driver (for thread #2) */
88    WAIT_DRV_MSG(&msg);
89    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
90
91    /* Check that there is no read request for another block */
92    CHECK_NO_DRV_MSG();
93
94    /*
95     * Check that thread #2 unblocked after this.
96     */
97    WAIT_THREAD_SYNC(2);
98    TEST_CHECK_RESULT("5");
99
100    /* Thread #3 is still in blocked state */
101    CHECK_THREAD_BLOCKED(3);
102
103    /* Release buffer in thread #2 */
104    CONTINUE_THREAD(2);
105
106    /* Wait for read request in the driver (for thread #3) */
107    WAIT_DRV_MSG(&msg);
108    SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
109
110    /* Wait for thread #3 to be unblocked */
111    WAIT_THREAD_SYNC(3);
112
113    /* Release buffer in thread #3 */
114    CONTINUE_THREAD(3);
115
116    CHECK_NO_DRV_MSG();
117
118    TEST_END();
119}
120
121static rtems_task
122bdbuf_test3_3_thread1(rtems_task_argument arg)
123{
124    rtems_status_code   rc;
125    rtems_bdbuf_buffer *bd = NULL;
126
127    /*
128     * Step 1:
129     * Call rtems_bdbuf_read(#N) to get a buffer;
130     */
131    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N1, &bd);
132    if (rc != RTEMS_SUCCESSFUL)
133    {
134        TEST_FAILED();
135    }
136
137    CONTINUE_MAIN(1);
138
139    /*
140     * Step 4:
141     * Call rtems_bdbuf_release(#N).
142     */
143    rc = rtems_bdbuf_release(bd);
144    if (rc != RTEMS_SUCCESSFUL)
145    {
146        TEST_FAILED();
147    }
148
149    THREAD_END();
150}
151
152static rtems_task
153bdbuf_test3_3_thread2(rtems_task_argument arg)
154{
155    rtems_status_code   rc;
156    rtems_bdbuf_buffer *bd = NULL;
157
158    WAIT_MAIN_SYNC(2);
159
160    /*
161     * Step 2:
162     * In thread #2 call read(#N2)
163     */
164    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N2, &bd);
165    if (rc != RTEMS_SUCCESSFUL)
166    {
167        TEST_FAILED();
168    }
169
170    printk("Thread #2 DEBLOCK\n");
171    CONTINUE_MAIN(2);
172
173    rc = rtems_bdbuf_release(bd);
174    if (rc != RTEMS_SUCCESSFUL)
175    {
176        TEST_FAILED();
177    }
178
179    THREAD_END();
180}
181
182static rtems_task
183bdbuf_test3_3_thread3(rtems_task_argument arg)
184{
185    rtems_status_code   rc;
186    rtems_bdbuf_buffer *bd = NULL;
187
188    WAIT_MAIN_SYNC(3);
189
190    /*
191     * Step 3:
192     * In thread #3 call read(#N3)
193     */
194    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N3, &bd);
195    if (rc != RTEMS_SUCCESSFUL)
196    {
197        TEST_FAILED();
198    }
199
200    printk("Thread #3 DEBLOCK\n");
201
202    CONTINUE_MAIN(3);
203   
204    rc = rtems_bdbuf_release(bd);
205    if (rc != RTEMS_SUCCESSFUL)
206    {
207        TEST_FAILED();
208    }
209
210    THREAD_END();
211}
212
Note: See TracBrowser for help on using the repository browser.