1 | /*! @file |
---|
2 | * @brief Check how rtems_bdbuf_read() handles two readers waiting |
---|
3 | * for a buffer with the same block number in cases when disk device |
---|
4 | * driver reports failure in read complete notification. |
---|
5 | * |
---|
6 | * Test sequence: |
---|
7 | * -# Call rtems_bdbuf_read() function in thread #1 and block on |
---|
8 | * waiting for read complete notification. |
---|
9 | * -# Call rtems_bdbuf_read() function in thread #2 for the same block |
---|
10 | * number. As the result it blocks on this read as well (but it will |
---|
11 | * block on transfer semaphore). |
---|
12 | * -# Disk device reports an error in read complete notification. |
---|
13 | * As the result an error is returned from rtems_bdbuf_read() |
---|
14 | * in thread #1. |
---|
15 | * -# rtems_bdbuf_read() called in thread #2 should try to re-read data |
---|
16 | * again so disk device ioctl() function is called again for this |
---|
17 | * block number. |
---|
18 | * -# This time disk device reports success in read complete notification. |
---|
19 | * As the result rtems_bdbuf_read() in thread #2 shall return |
---|
20 | * RTEMS_SUCCESSFUL and provide buffer descriptor. |
---|
21 | * -# Call rtems_bdbuf_release() function in thread #2. |
---|
22 | * . |
---|
23 | * |
---|
24 | * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia |
---|
25 | * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru> |
---|
26 | * |
---|
27 | * The license and distribution terms for this file may be |
---|
28 | * found in the file LICENSE in this distribution or at |
---|
29 | * http://www.rtems.com/license/LICENSE. |
---|
30 | * |
---|
31 | * $Id$ |
---|
32 | */ |
---|
33 | |
---|
34 | #ifdef HAVE_CONFIG_H |
---|
35 | #include "config.h" |
---|
36 | #endif |
---|
37 | |
---|
38 | #include <bdbuf_tests.h> |
---|
39 | |
---|
40 | static rtems_task bdbuf_test1_3_thread1(rtems_task_argument arg); |
---|
41 | static rtems_task bdbuf_test1_3_thread2(rtems_task_argument arg); |
---|
42 | |
---|
43 | #define TEST_BLK_NUM 30 |
---|
44 | |
---|
45 | void |
---|
46 | bdbuf_test1_3_main() |
---|
47 | { |
---|
48 | bdbuf_test_msg msg; |
---|
49 | |
---|
50 | TEST_START("Test 1.3"); |
---|
51 | |
---|
52 | START_THREAD(1, bdbuf_test1_3_thread1); |
---|
53 | START_THREAD(2, bdbuf_test1_3_thread2); |
---|
54 | |
---|
55 | /* |
---|
56 | * Step 1: |
---|
57 | * Thread #1 calls rtems_bdbuf_read() and we block |
---|
58 | * this thread on data transfer operation. |
---|
59 | */ |
---|
60 | WAIT_DRV_MSG(&msg); |
---|
61 | |
---|
62 | /* |
---|
63 | * Step 2: |
---|
64 | * Thread #2 calls rtems_bdbuf_read() for the same |
---|
65 | * block number, as the result it shall block waiting |
---|
66 | * on buffer state change. |
---|
67 | */ |
---|
68 | CONTINUE_THREAD(2); |
---|
69 | |
---|
70 | /* Make sure thread #2 managed to block on the buffer. */ |
---|
71 | CHECK_THREAD_BLOCKED(2); |
---|
72 | |
---|
73 | /* |
---|
74 | * Step 3: |
---|
75 | * Unblock thread #1 by reporting erroneous data transfer result. |
---|
76 | */ |
---|
77 | SEND_DRV_MSG(0, 0, RTEMS_IO_ERROR, EFAULT); |
---|
78 | |
---|
79 | /* |
---|
80 | * Wait for sync from thread #1. |
---|
81 | */ |
---|
82 | WAIT_THREAD_SYNC(1); |
---|
83 | CONTINUE_THREAD(1); |
---|
84 | TEST_CHECK_RESULT("3"); |
---|
85 | |
---|
86 | /* Check thread #2 is still blocked */ |
---|
87 | CHECK_THREAD_BLOCKED(2); |
---|
88 | |
---|
89 | /* |
---|
90 | * Step 4: |
---|
91 | * For thread #2 bdbuf shall try to re-read data. |
---|
92 | * As the result we will get read call to device driver. |
---|
93 | */ |
---|
94 | WAIT_DRV_MSG(&msg); |
---|
95 | |
---|
96 | /* |
---|
97 | * Step 5: |
---|
98 | * This time report success from the driver and |
---|
99 | * rtems_bdbuf_read() in thread #2 shall return |
---|
100 | * RTEMS_SUCCESSFUL. |
---|
101 | */ |
---|
102 | SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0); |
---|
103 | |
---|
104 | /* |
---|
105 | * Wait for sync from thread #2. |
---|
106 | */ |
---|
107 | WAIT_THREAD_SYNC(2); |
---|
108 | TEST_CHECK_RESULT("5"); |
---|
109 | |
---|
110 | /* |
---|
111 | * Step 6: |
---|
112 | * Release buffer in thread #2 |
---|
113 | */ |
---|
114 | CONTINUE_THREAD(2); |
---|
115 | |
---|
116 | TEST_END(); |
---|
117 | } |
---|
118 | |
---|
119 | static rtems_task |
---|
120 | bdbuf_test1_3_thread1(rtems_task_argument arg) |
---|
121 | { |
---|
122 | rtems_status_code rc; |
---|
123 | rtems_bdbuf_buffer *bd = NULL; |
---|
124 | |
---|
125 | /* |
---|
126 | * Step 1 - 3: |
---|
127 | * Try to read blk #N on thread #1 |
---|
128 | * We will block on this read and meanwhile |
---|
129 | * thread #2 will try to read the same block. |
---|
130 | * After blocking on read in thread #2, device |
---|
131 | * driver will notify about an error, and as the |
---|
132 | * result this call will return an error. |
---|
133 | */ |
---|
134 | rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd); |
---|
135 | if (rc != RTEMS_IO_ERROR || bd != NULL) |
---|
136 | { |
---|
137 | TEST_FAILED(); |
---|
138 | } |
---|
139 | |
---|
140 | CONTINUE_MAIN(1); |
---|
141 | |
---|
142 | THREAD_END(); |
---|
143 | } |
---|
144 | |
---|
145 | static rtems_task |
---|
146 | bdbuf_test1_3_thread2(rtems_task_argument arg) |
---|
147 | { |
---|
148 | rtems_status_code rc; |
---|
149 | rtems_bdbuf_buffer *bd = NULL; |
---|
150 | |
---|
151 | WAIT_MAIN_SYNC(2); |
---|
152 | |
---|
153 | /* |
---|
154 | * Step 2: |
---|
155 | * Try to read block #N. Right now thread #1 is waiting |
---|
156 | * on data transfer operation, so we will block here as well. |
---|
157 | * |
---|
158 | * Step 4-5: |
---|
159 | * Due to the fact that thread #1 failed to read required block |
---|
160 | * number, bdbuf library should ask for re-read data again. |
---|
161 | * Time time main task will tell driver to report success. |
---|
162 | */ |
---|
163 | rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd); |
---|
164 | if (rc != RTEMS_SUCCESSFUL || bd == NULL) |
---|
165 | { |
---|
166 | TEST_FAILED(); |
---|
167 | } |
---|
168 | CONTINUE_MAIN(2); |
---|
169 | |
---|
170 | /* |
---|
171 | * Step 6: |
---|
172 | * Release buffer. |
---|
173 | */ |
---|
174 | rc = rtems_bdbuf_release(bd); |
---|
175 | if (rc != RTEMS_SUCCESSFUL) |
---|
176 | { |
---|
177 | TEST_FAILED(); |
---|
178 | } |
---|
179 | THREAD_END(); |
---|
180 | } |
---|
181 | |
---|