1 | /*! @file |
---|
2 | * @brief Implementation of auxiliary functions of bdbuf tests. |
---|
3 | * |
---|
4 | * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia |
---|
5 | * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru> |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #ifdef HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <errno.h> |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/io.h> |
---|
23 | #include <rtems/diskdevs.h> |
---|
24 | #include <rtems/bdbuf.h> |
---|
25 | #include "bdbuf_tests.h" |
---|
26 | |
---|
27 | |
---|
28 | struct bdbuf_test_descr { |
---|
29 | void (* main)(void); |
---|
30 | } bdbuf_tests[] = { |
---|
31 | { bdbuf_test1_1_main }, |
---|
32 | { bdbuf_test1_2_main }, |
---|
33 | { bdbuf_test1_3_main }, |
---|
34 | { bdbuf_test1_4_main }, |
---|
35 | { bdbuf_test1_5_main }, |
---|
36 | |
---|
37 | { bdbuf_test2_1_main }, |
---|
38 | { bdbuf_test2_2_main }, |
---|
39 | |
---|
40 | { bdbuf_test3_1_main }, |
---|
41 | { bdbuf_test3_2_main }, |
---|
42 | { bdbuf_test3_3_main }, |
---|
43 | |
---|
44 | { bdbuf_test4_1_main }, |
---|
45 | { bdbuf_test4_2_main }, |
---|
46 | { bdbuf_test4_3_main }, |
---|
47 | }; |
---|
48 | |
---|
49 | #define TEST_SEM_ATTRIBS RTEMS_DEFAULT_ATTRIBUTES |
---|
50 | |
---|
51 | /** Device ID used for testing */ |
---|
52 | const rtems_disk_device *test_dd = NULL; |
---|
53 | |
---|
54 | /** Test result variable */ |
---|
55 | bool good_test_result = true; |
---|
56 | |
---|
57 | test_ctx g_test_ctx; |
---|
58 | |
---|
59 | const char *test_name = "NO TEST"; |
---|
60 | |
---|
61 | bdbuf_test_msg test_drv_msg; |
---|
62 | |
---|
63 | /** Count of messages in RX message queue used on disk driver side. */ |
---|
64 | #define TEST_DRV_RX_MQUEUE_COUNT 10 |
---|
65 | /** Name of disk driver RX message queue. */ |
---|
66 | #define TEST_DRV_RX_MQUEUE_NAME (rtems_build_name( 'M', 'Q', 'D', ' ' )) |
---|
67 | |
---|
68 | /** Count of messages in Test task RX message queue */ |
---|
69 | #define TEST_TASK_RX_MQUEUE_COUNT 10 |
---|
70 | /** Name of Test task RX message queue */ |
---|
71 | #define TEST_TASK_RX_MQUEUE_NAME (rtems_build_name( 'M', 'Q', 'T', ' ' )) |
---|
72 | |
---|
73 | rtems_status_code |
---|
74 | bdbuf_test_start_aux_task(rtems_name name, |
---|
75 | rtems_task_entry entry_point, |
---|
76 | rtems_task_argument arg, |
---|
77 | Objects_Id *id) |
---|
78 | { |
---|
79 | rtems_status_code rc; |
---|
80 | Objects_Id task_id; |
---|
81 | |
---|
82 | rc = rtems_task_create(name, BDBUF_TEST_THREAD_PRIO_NORMAL, 1024 * 2, |
---|
83 | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR, |
---|
84 | RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT, |
---|
85 | &task_id); |
---|
86 | if (rc != RTEMS_SUCCESSFUL) |
---|
87 | { |
---|
88 | printf("Failed to create task\n"); |
---|
89 | return rc; |
---|
90 | } |
---|
91 | |
---|
92 | rc = rtems_task_start(task_id, entry_point, arg); |
---|
93 | if (rc != RTEMS_SUCCESSFUL) |
---|
94 | { |
---|
95 | printf("Failed to start task\n"); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | if (id != NULL) |
---|
100 | *id = task_id; |
---|
101 | } |
---|
102 | return rc; |
---|
103 | } |
---|
104 | |
---|
105 | void |
---|
106 | run_bdbuf_tests() |
---|
107 | { |
---|
108 | rtems_disk_device *disk; |
---|
109 | rtems_status_code sc; |
---|
110 | dev_t dev = -1; |
---|
111 | dev_t test_dev; |
---|
112 | unsigned int i; |
---|
113 | |
---|
114 | rtems_device_major_number major; |
---|
115 | rtems_driver_address_table testdisk = { |
---|
116 | test_disk_initialize, |
---|
117 | RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES |
---|
118 | }; |
---|
119 | |
---|
120 | /* Create a message queue to get events from disk driver. */ |
---|
121 | sc = rtems_message_queue_create(TEST_TASK_RX_MQUEUE_NAME, |
---|
122 | TEST_TASK_RX_MQUEUE_COUNT, |
---|
123 | sizeof(bdbuf_test_msg), |
---|
124 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
125 | &g_test_ctx.test_qid); |
---|
126 | |
---|
127 | if (sc != RTEMS_SUCCESSFUL) |
---|
128 | { |
---|
129 | printk("Failed to create message queue for test task: %u\n", sc); |
---|
130 | return; |
---|
131 | } |
---|
132 | |
---|
133 | /* Register a disk device that is used in tests */ |
---|
134 | sc = rtems_io_register_driver(0, &testdisk, &major); |
---|
135 | if (sc != RTEMS_SUCCESSFUL) |
---|
136 | { |
---|
137 | printk("Failed to register TEST DEVICE: %d\n", sc); |
---|
138 | return; |
---|
139 | } |
---|
140 | |
---|
141 | test_dev = -1; |
---|
142 | while ((disk = rtems_disk_next(dev)) != NULL) |
---|
143 | { |
---|
144 | printk("DEV: %s [%lu]\n", disk->name, disk->size); |
---|
145 | dev = disk->dev; |
---|
146 | if (strcmp(disk->name, TEST_DISK_NAME) == 0) |
---|
147 | test_dev = dev; |
---|
148 | rtems_disk_release(disk); |
---|
149 | } |
---|
150 | |
---|
151 | if (test_dev == (dev_t)-1) |
---|
152 | { |
---|
153 | printf("Failed to find %s disk\n", TEST_DISK_NAME); |
---|
154 | return; |
---|
155 | } |
---|
156 | |
---|
157 | test_dd = rtems_disk_obtain(test_dev); |
---|
158 | if (test_dd == NULL) |
---|
159 | { |
---|
160 | printf("Failed to obtain %s disk\n", TEST_DISK_NAME); |
---|
161 | return; |
---|
162 | } |
---|
163 | |
---|
164 | /* |
---|
165 | * On initialization test disk device driver registers |
---|
166 | * its RX message queue, so we just need to locate it. |
---|
167 | */ |
---|
168 | sc = rtems_message_queue_ident(TEST_DRV_RX_MQUEUE_NAME, |
---|
169 | RTEMS_SEARCH_ALL_NODES, |
---|
170 | &g_test_ctx.test_drv_qid); |
---|
171 | if (sc != RTEMS_SUCCESSFUL) |
---|
172 | { |
---|
173 | printf("Failed to find Test Driver Queue: %u\n", sc); |
---|
174 | return; |
---|
175 | } |
---|
176 | |
---|
177 | for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync_main); i++) |
---|
178 | { |
---|
179 | sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', '0' + i), |
---|
180 | 0, TEST_SEM_ATTRIBS, 0, |
---|
181 | &g_test_ctx.test_sync_main[i]); |
---|
182 | if (sc != RTEMS_SUCCESSFUL) |
---|
183 | { |
---|
184 | printk("Failed to create sync sem for test task: %u\n", sc); |
---|
185 | return; |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync); i++) |
---|
190 | { |
---|
191 | sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'T', '0' + i), |
---|
192 | 0, TEST_SEM_ATTRIBS, 0, |
---|
193 | &g_test_ctx.test_sync[i]); |
---|
194 | if (sc != RTEMS_SUCCESSFUL) |
---|
195 | { |
---|
196 | printk("Failed to create sync sem for test task #%d: %u\n", i + 1, sc); |
---|
197 | return; |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', 'E'), |
---|
202 | 0, TEST_SEM_ATTRIBS, 0, |
---|
203 | &g_test_ctx.test_end_main); |
---|
204 | if (sc != RTEMS_SUCCESSFUL) |
---|
205 | { |
---|
206 | printk("Failed to create end sync sem for test task: %u\n", sc); |
---|
207 | return; |
---|
208 | } |
---|
209 | |
---|
210 | for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++) |
---|
211 | g_test_ctx.test_task[i] = OBJECTS_ID_NONE; |
---|
212 | |
---|
213 | for (i = 0; i < sizeof(bdbuf_tests) / sizeof(bdbuf_tests[0]); i++) |
---|
214 | { |
---|
215 | bdbuf_tests[i].main(); |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | rtems_status_code |
---|
221 | bdbuf_test_create_drv_rx_queue(Objects_Id *id) |
---|
222 | { |
---|
223 | return rtems_message_queue_create(TEST_DRV_RX_MQUEUE_NAME, |
---|
224 | TEST_DRV_RX_MQUEUE_COUNT, |
---|
225 | sizeof(bdbuf_test_msg), |
---|
226 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
227 | id); |
---|
228 | } |
---|
229 | |
---|
230 | rtems_status_code |
---|
231 | bdbuf_test_create_drv_tx_queue(Objects_Id *id) |
---|
232 | { |
---|
233 | return rtems_message_queue_ident(TEST_TASK_RX_MQUEUE_NAME, |
---|
234 | RTEMS_SEARCH_ALL_NODES, |
---|
235 | id); |
---|
236 | } |
---|
237 | |
---|
238 | rtems_status_code |
---|
239 | bdbuf_test_start_thread(unsigned int idx, rtems_task_entry func) |
---|
240 | { |
---|
241 | rtems_status_code sc; |
---|
242 | |
---|
243 | if (g_test_ctx.test_task[idx] != OBJECTS_ID_NONE) |
---|
244 | { |
---|
245 | sc = rtems_task_delete(g_test_ctx.test_task[idx]); |
---|
246 | if (sc != RTEMS_SUCCESSFUL) |
---|
247 | { |
---|
248 | printk("Failed to delete test thread %u in test %s\n", |
---|
249 | idx + 1, g_test_ctx.test_name); |
---|
250 | return sc; |
---|
251 | } |
---|
252 | } |
---|
253 | sc = bdbuf_test_start_aux_task( |
---|
254 | rtems_build_name('T', 'S', '.', '0' + idx), |
---|
255 | func, (rtems_task_argument)(NULL), |
---|
256 | &g_test_ctx.test_task[idx]); |
---|
257 | return sc; |
---|
258 | } |
---|
259 | |
---|
260 | rtems_status_code |
---|
261 | bdbuf_test_end() |
---|
262 | { |
---|
263 | rtems_status_code sc; |
---|
264 | unsigned int i; |
---|
265 | |
---|
266 | for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++) |
---|
267 | { |
---|
268 | if (g_test_ctx.test_task[i] != OBJECTS_ID_NONE) |
---|
269 | { |
---|
270 | sc = rtems_semaphore_obtain(g_test_ctx.test_end_main, |
---|
271 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
272 | if (sc != RTEMS_SUCCESSFUL) |
---|
273 | { |
---|
274 | printk("Failed to get a thread stopped\n"); |
---|
275 | } |
---|
276 | g_test_ctx.test_task[i] = OBJECTS_ID_NONE; |
---|
277 | } |
---|
278 | } |
---|
279 | return RTEMS_SUCCESSFUL; |
---|
280 | } |
---|
281 | |
---|