source: rtems/testsuites/libtests/block08/bdbuf_tests.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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