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