source: rtems/testsuites/libtests/block08/bdbuf_tests.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: 7.6 KB
Line 
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
28struct 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 */
52dev_t      test_dev = (dev_t)-1;
53
54/** Test result variable */
55bool       good_test_result = true;
56
57test_ctx g_test_ctx;
58
59const char *test_name = "NO TEST";
60
61bdbuf_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
73rtems_status_code
74bdbuf_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
105void
106run_bdbuf_tests()
107{
108    rtems_disk_device  *disk;
109    rtems_status_code   sc;
110    dev_t               dev = -1;
111    unsigned int        i;
112
113    rtems_device_major_number  major;
114    rtems_driver_address_table testdisk = {
115        test_disk_initialize,
116        RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
117    };
118
119    /* Create a message queue to get events from disk driver. */
120    sc = rtems_message_queue_create(TEST_TASK_RX_MQUEUE_NAME,
121                                    TEST_TASK_RX_MQUEUE_COUNT,
122                                    sizeof(bdbuf_test_msg),
123                                    RTEMS_DEFAULT_ATTRIBUTES,
124                                    &g_test_ctx.test_qid);
125
126    if (sc != RTEMS_SUCCESSFUL)
127    {
128        printk("Failed to create message queue for test task: %u\n", sc);
129        return;
130    }
131
132    /* Register a disk device that is used in tests */
133    sc = rtems_io_register_driver(0, &testdisk, &major);
134    if (sc != RTEMS_SUCCESSFUL)
135    {
136        printk("Failed to register TEST DEVICE: %d\n", sc);
137        return;
138    }
139
140    test_dev = -1;
141    while ((disk = rtems_disk_next(dev)) != NULL)
142    {
143        printk("DEV: %s [%lu]\n", disk->name, disk->size);
144        dev = disk->dev;
145        if (strcmp(disk->name, TEST_DISK_NAME) == 0)
146            test_dev = dev;
147        rtems_disk_release(disk);
148    }
149
150    if (test_dev == (dev_t)-1)
151    {
152        printf("Failed to find %s disk\n", TEST_DISK_NAME);
153        return;
154    }
155
156    /*
157     * On initialization test disk device driver registers
158     * its RX message queue, so we just need to locate it.
159     */
160    sc = rtems_message_queue_ident(TEST_DRV_RX_MQUEUE_NAME,
161                                   RTEMS_SEARCH_ALL_NODES,
162                                   &g_test_ctx.test_drv_qid);
163    if (sc != RTEMS_SUCCESSFUL)
164    {
165        printf("Failed to find Test Driver Queue: %u\n", sc);
166        return;
167    }
168
169    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync_main); i++)
170    {
171        sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', '0' + i),
172                                    0, TEST_SEM_ATTRIBS, 0,
173                                    &g_test_ctx.test_sync_main[i]);
174        if (sc != RTEMS_SUCCESSFUL)
175        {
176            printk("Failed to create sync sem for test task: %u\n", sc);
177            return;
178        }
179    }
180
181    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync); i++)
182    {
183        sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'T', '0' + i),
184                                    0, TEST_SEM_ATTRIBS, 0,
185                                    &g_test_ctx.test_sync[i]);
186        if (sc != RTEMS_SUCCESSFUL)
187        {
188            printk("Failed to create sync sem for test task #%d: %u\n", i + 1, sc);
189            return;
190        }
191    }
192   
193    sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', 'E'),
194                                0, TEST_SEM_ATTRIBS, 0,
195                                &g_test_ctx.test_end_main);
196    if (sc != RTEMS_SUCCESSFUL)
197    {
198        printk("Failed to create end sync sem for test task: %u\n", sc);
199        return;
200    }
201
202    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++)
203        g_test_ctx.test_task[i] = OBJECTS_ID_NONE;
204
205    for (i = 0; i < sizeof(bdbuf_tests) / sizeof(bdbuf_tests[0]); i++)
206    {
207        bdbuf_tests[i].main();
208    }
209}
210
211
212rtems_status_code
213bdbuf_test_create_drv_rx_queue(Objects_Id *id)
214{
215    return rtems_message_queue_create(TEST_DRV_RX_MQUEUE_NAME,
216                                      TEST_DRV_RX_MQUEUE_COUNT,
217                                      sizeof(bdbuf_test_msg),
218                                      RTEMS_DEFAULT_ATTRIBUTES,
219                                      id);
220}
221
222rtems_status_code
223bdbuf_test_create_drv_tx_queue(Objects_Id *id)
224{
225    return  rtems_message_queue_ident(TEST_TASK_RX_MQUEUE_NAME,
226                                      RTEMS_SEARCH_ALL_NODES,
227                                      id);
228}
229
230rtems_status_code
231bdbuf_test_start_thread(unsigned int idx, rtems_task_entry func)
232{
233    rtems_status_code sc;
234
235    if (g_test_ctx.test_task[idx] != OBJECTS_ID_NONE)
236    {
237        sc = rtems_task_delete(g_test_ctx.test_task[idx]);
238        if (sc != RTEMS_SUCCESSFUL)
239        {
240            printk("Failed to delete test thread %u in test %s\n",
241                   idx + 1, g_test_ctx.test_name);
242            return sc;
243        }
244    }
245    sc = bdbuf_test_start_aux_task(
246            rtems_build_name('T', 'S', '.', '0' + idx),
247            func, (rtems_task_argument)(NULL),
248            &g_test_ctx.test_task[idx]);
249    return sc;
250}
251
252rtems_status_code
253bdbuf_test_end()
254{
255    rtems_status_code sc;
256    unsigned int      i;
257
258    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++)
259    {
260        if (g_test_ctx.test_task[i] != OBJECTS_ID_NONE)
261        {
262            sc = rtems_semaphore_obtain(g_test_ctx.test_end_main,
263                                        RTEMS_WAIT, RTEMS_NO_TIMEOUT);
264            if (sc != RTEMS_SUCCESSFUL)
265            {
266                printk("Failed to get a thread stopped\n");
267            }
268            g_test_ctx.test_task[i] = OBJECTS_ID_NONE;
269        }
270    }
271    return RTEMS_SUCCESSFUL;
272}
273
Note: See TracBrowser for help on using the repository browser.