1 | /*! @file |
---|
2 | * @brief Check how rtems_bdbuf_read() and rtems_bdbuf_release_modified() |
---|
3 | * coexist. rtems_bdbuf_read() is blocked when required buffer is being |
---|
4 | * transferred. |
---|
5 | * |
---|
6 | * The same as Test 2.1, but on step 7 thread #2 calls |
---|
7 | * rtems_bdbuf_release_modified(). |
---|
8 | * |
---|
9 | * Test sequence: |
---|
10 | * -# Call rtems_bdbuf_read() function in thread #1 and block on |
---|
11 | * waiting for read complete notification. |
---|
12 | * -# Call rtems_bdbuf_read() function in thread #2 for |
---|
13 | * the same block number. As the result it blocks on this read |
---|
14 | * as well (but it will block on transfer semaphore). |
---|
15 | * -# Disk device reports success in read complete notification. |
---|
16 | * As the result rtems_bdbuf_read() function returns |
---|
17 | * RTEMS_SUCCESSFUL in thread #1. |
---|
18 | * -# Thread #1 releases buffer with rtems_bdbuf_release_modified() function. |
---|
19 | * -# rtems_bdbuf_read() function in thread #2 unlocks and |
---|
20 | * returns RTEMS_SUCCESSFUL. |
---|
21 | * -# Wait swapout period and check that the buffer is not requested |
---|
22 | * to be flushed to a disk. |
---|
23 | * -# Call rtems_bdbuf_release_modified() function in thread #2. |
---|
24 | * -# Check that this block number is requested for a flush in swapout period. |
---|
25 | * |
---|
26 | * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia |
---|
27 | * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru> |
---|
28 | * |
---|
29 | * The license and distribution terms for this file may be |
---|
30 | * found in the file LICENSE in this distribution or at |
---|
31 | * http://www.rtems.com/license/LICENSE. |
---|
32 | * |
---|
33 | * $Id$ |
---|
34 | */ |
---|
35 | |
---|
36 | #include <bdbuf_tests.h> |
---|
37 | |
---|
38 | static rtems_task bdbuf_test2_2_thread1(rtems_task_argument arg); |
---|
39 | static rtems_task bdbuf_test2_2_thread2(rtems_task_argument arg); |
---|
40 | |
---|
41 | /* Block number used in the test */ |
---|
42 | #define TEST_BLK_NUM 70 |
---|
43 | |
---|
44 | void |
---|
45 | bdbuf_test2_2_main() |
---|
46 | { |
---|
47 | bdbuf_test_msg msg; |
---|
48 | |
---|
49 | TEST_START("Test 2.2"); |
---|
50 | |
---|
51 | START_THREAD(1, bdbuf_test2_2_thread1); |
---|
52 | START_THREAD(2, bdbuf_test2_2_thread2); |
---|
53 | |
---|
54 | /* |
---|
55 | * Step 1: |
---|
56 | * Thread #1 calls rtems_bdbuf_read() and we block |
---|
57 | * this thread on data transfer operation. |
---|
58 | */ |
---|
59 | WAIT_DRV_MSG(&msg); |
---|
60 | |
---|
61 | /* |
---|
62 | * Step 2: |
---|
63 | * Thread #2 calls rtems_bdbuf_read() for the same |
---|
64 | * block number, as the result it shall block waiting |
---|
65 | * on buffer state change (waiting on TRANSFER state). |
---|
66 | */ |
---|
67 | CONTINUE_THREAD(2); |
---|
68 | |
---|
69 | /* Make sure thread #2 managed to block on the buffer. */ |
---|
70 | CHECK_THREAD_BLOCKED(2); |
---|
71 | |
---|
72 | /* |
---|
73 | * Step 3: |
---|
74 | * Unblock thread #1 by reporting successful data transfer result. |
---|
75 | */ |
---|
76 | SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0); |
---|
77 | |
---|
78 | /* |
---|
79 | * Wait for sync from thread #1. |
---|
80 | */ |
---|
81 | WAIT_THREAD_SYNC(1); |
---|
82 | TEST_CHECK_RESULT("3"); |
---|
83 | |
---|
84 | /* Check thread #2 is still blocked */ |
---|
85 | CHECK_THREAD_BLOCKED(2); |
---|
86 | |
---|
87 | /* |
---|
88 | * Step 4: |
---|
89 | * Thread #1 releases buffer with bdbuf_release_modified() call. |
---|
90 | */ |
---|
91 | CONTINUE_THREAD(1); |
---|
92 | |
---|
93 | /* |
---|
94 | * Step 5: |
---|
95 | * On buffer release operation, we should have unblock |
---|
96 | * of thread #2 that is waiting on read buffer operation. |
---|
97 | */ |
---|
98 | WAIT_THREAD_SYNC(2); |
---|
99 | TEST_CHECK_RESULT("5"); |
---|
100 | |
---|
101 | /* |
---|
102 | * Step 6: |
---|
103 | * Wait swapout period and check that there is no |
---|
104 | * request to flush buffer onto a disk. |
---|
105 | */ |
---|
106 | CHECK_NO_DRV_MSG(); |
---|
107 | |
---|
108 | /* |
---|
109 | * Step 7: |
---|
110 | * Thread #2 releases buffer with bdbuf_release_modified() call. |
---|
111 | */ |
---|
112 | CONTINUE_THREAD(2); |
---|
113 | |
---|
114 | /* |
---|
115 | * Step 8: |
---|
116 | * Check that in swapout interval disk device |
---|
117 | * driver is requested to flush buffer. |
---|
118 | */ |
---|
119 | WAIT_DRV_MSG_WR(&msg); |
---|
120 | SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0); |
---|
121 | |
---|
122 | TEST_END(); |
---|
123 | } |
---|
124 | |
---|
125 | static rtems_task |
---|
126 | bdbuf_test2_2_thread1(rtems_task_argument arg) |
---|
127 | { |
---|
128 | rtems_status_code rc; |
---|
129 | rtems_bdbuf_buffer *bd = NULL; |
---|
130 | |
---|
131 | /* |
---|
132 | * Step 1 - 3: |
---|
133 | * Try to read blk #N on thread #1 |
---|
134 | * We will block on this read and meanwhile |
---|
135 | * thread #2 will try to read the same block. |
---|
136 | * After blocking on read in thread #2, device |
---|
137 | * driver will notify successful completion of |
---|
138 | * date transfer, and as the result this call |
---|
139 | * will return valid buffer. |
---|
140 | */ |
---|
141 | rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd); |
---|
142 | if (rc != RTEMS_SUCCESSFUL) |
---|
143 | { |
---|
144 | TEST_FAILED(); |
---|
145 | } |
---|
146 | CONTINUE_MAIN(1); |
---|
147 | |
---|
148 | /* |
---|
149 | * Step 4: |
---|
150 | * Release buffer returned on the previous step. |
---|
151 | */ |
---|
152 | rc = rtems_bdbuf_release_modified(bd); |
---|
153 | if (rc != RTEMS_SUCCESSFUL) |
---|
154 | { |
---|
155 | TEST_FAILED(); |
---|
156 | } |
---|
157 | THREAD_END(); |
---|
158 | } |
---|
159 | |
---|
160 | static rtems_task |
---|
161 | bdbuf_test2_2_thread2(rtems_task_argument arg) |
---|
162 | { |
---|
163 | rtems_status_code rc; |
---|
164 | rtems_bdbuf_buffer *bd = NULL; |
---|
165 | |
---|
166 | WAIT_MAIN_SYNC(2); |
---|
167 | |
---|
168 | /* |
---|
169 | * Step 2: |
---|
170 | * Try to read block #N. Right now thread #1 is waiting |
---|
171 | * on data transfer operation, so we will block here as well. |
---|
172 | * |
---|
173 | * Step 5: |
---|
174 | * On step 4 thread #1 releases buffer and as the result |
---|
175 | * our read operation should finish with success. |
---|
176 | */ |
---|
177 | rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd); |
---|
178 | if (rc != RTEMS_SUCCESSFUL) |
---|
179 | { |
---|
180 | TEST_FAILED(); |
---|
181 | } |
---|
182 | CONTINUE_MAIN(2); |
---|
183 | |
---|
184 | /* |
---|
185 | * Step 7: |
---|
186 | * Release buffer. |
---|
187 | */ |
---|
188 | rc = rtems_bdbuf_release_modified(bd); |
---|
189 | if (rc != RTEMS_SUCCESSFUL) |
---|
190 | { |
---|
191 | TEST_FAILED(); |
---|
192 | } |
---|
193 | THREAD_END(); |
---|
194 | } |
---|
195 | |
---|
196 | |
---|