source: rtems/testsuites/libtests/block08/bdbuf_tests.c @ b73b952

5
Last change on this file since b73b952 was b73b952, checked in by Joel Sherrill <joel@…>, on 04/26/17 at 03:11:55

block08/bdbuf_tests.c: Add include of <rtems/inttypes.h>

  • Property mode set to 100644
File size: 7.8 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.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <string.h>
18#include <errno.h>
19
20#include <rtems.h>
21#include <rtems/io.h>
22#include <rtems/diskdevs.h>
23#include <rtems/bdbuf.h>
24#include <rtems/inttypes.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 */
52rtems_disk_device *test_dd = NULL;
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    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(
145          "DEV: %s [%" PRIdrtems_blkdev_bnum "]\n",
146         disk->name,
147          disk->size
148        );
149        dev = disk->dev;
150        if (strcmp(disk->name, TEST_DISK_NAME) == 0)
151            test_dev = dev;
152        rtems_disk_release(disk);
153    }
154
155    if (test_dev == (dev_t)-1)
156    {
157        printf("Failed to find %s disk\n", TEST_DISK_NAME);
158        return;
159    }
160
161    test_dd = rtems_disk_obtain(test_dev);
162    if (test_dd == NULL)
163    {
164        printf("Failed to obtain %s disk\n", TEST_DISK_NAME);
165        return;
166    }
167
168    /*
169     * On initialization test disk device driver registers
170     * its RX message queue, so we just need to locate it.
171     */
172    sc = rtems_message_queue_ident(TEST_DRV_RX_MQUEUE_NAME,
173                                   RTEMS_SEARCH_ALL_NODES,
174                                   &g_test_ctx.test_drv_qid);
175    if (sc != RTEMS_SUCCESSFUL)
176    {
177        printf("Failed to find Test Driver Queue: %u\n", sc);
178        return;
179    }
180
181    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync_main); i++)
182    {
183        sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', '0' + i),
184                                    0, TEST_SEM_ATTRIBS, 0,
185                                    &g_test_ctx.test_sync_main[i]);
186        if (sc != RTEMS_SUCCESSFUL)
187        {
188            printk("Failed to create sync sem for test task: %u\n", sc);
189            return;
190        }
191    }
192
193    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_sync); i++)
194    {
195        sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'T', '0' + i),
196                                    0, TEST_SEM_ATTRIBS, 0,
197                                    &g_test_ctx.test_sync[i]);
198        if (sc != RTEMS_SUCCESSFUL)
199        {
200            printk("Failed to create sync sem for test task #%d: %u\n", i + 1, sc);
201            return;
202        }
203    }
204   
205    sc = rtems_semaphore_create(rtems_build_name('T', 'S', 'M', 'E'),
206                                0, TEST_SEM_ATTRIBS, 0,
207                                &g_test_ctx.test_end_main);
208    if (sc != RTEMS_SUCCESSFUL)
209    {
210        printk("Failed to create end sync sem for test task: %u\n", sc);
211        return;
212    }
213
214    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++)
215        g_test_ctx.test_task[i] = OBJECTS_ID_NONE;
216
217    for (i = 0; i < sizeof(bdbuf_tests) / sizeof(bdbuf_tests[0]); i++)
218    {
219        bdbuf_tests[i].main();
220    }
221}
222
223
224rtems_status_code
225bdbuf_test_create_drv_rx_queue(Objects_Id *id)
226{
227    return rtems_message_queue_create(TEST_DRV_RX_MQUEUE_NAME,
228                                      TEST_DRV_RX_MQUEUE_COUNT,
229                                      sizeof(bdbuf_test_msg),
230                                      RTEMS_DEFAULT_ATTRIBUTES,
231                                      id);
232}
233
234rtems_status_code
235bdbuf_test_create_drv_tx_queue(Objects_Id *id)
236{
237    return  rtems_message_queue_ident(TEST_TASK_RX_MQUEUE_NAME,
238                                      RTEMS_SEARCH_ALL_NODES,
239                                      id);
240}
241
242rtems_status_code
243bdbuf_test_start_thread(unsigned int idx, rtems_task_entry func)
244{
245    rtems_status_code sc;
246
247    if (g_test_ctx.test_task[idx] != OBJECTS_ID_NONE)
248    {
249        sc = rtems_task_delete(g_test_ctx.test_task[idx]);
250        if (sc != RTEMS_SUCCESSFUL)
251        {
252            printk("Failed to delete test thread %u in test %s\n",
253                   idx + 1, g_test_ctx.test_name);
254            return sc;
255        }
256    }
257    sc = bdbuf_test_start_aux_task(
258            rtems_build_name('T', 'S', '.', '0' + idx),
259            func, (rtems_task_argument)(NULL),
260            &g_test_ctx.test_task[idx]);
261    return sc;
262}
263
264rtems_status_code
265bdbuf_test_end()
266{
267    rtems_status_code sc;
268    unsigned int      i;
269
270    for (i = 0; i < ARRAY_NUM(g_test_ctx.test_task); i++)
271    {
272        if (g_test_ctx.test_task[i] != OBJECTS_ID_NONE)
273        {
274            sc = rtems_semaphore_obtain(g_test_ctx.test_end_main,
275                                        RTEMS_WAIT, RTEMS_NO_TIMEOUT);
276            if (sc != RTEMS_SUCCESSFUL)
277            {
278                printk("Failed to get a thread stopped\n");
279            }
280            g_test_ctx.test_task[i] = OBJECTS_ID_NONE;
281        }
282    }
283    return RTEMS_SUCCESSFUL;
284}
285
Note: See TracBrowser for help on using the repository browser.