source: rtems/testsuites/libtests/block08/test_disk.c @ 117f7b1

5
Last change on this file since 117f7b1 was 117f7b1, checked in by Sebastian Huber <sebastian.huber@…>, on 08/03/18 at 16:18:56

libtests/block08: Use rtems_blkdev_create()

Update #3358.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*! @file
2 *  @brief Test disk block device implementation.
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#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems.h>
17#include <rtems/libio.h>
18#include <errno.h>
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22#include <inttypes.h>
23
24#include <rtems/blkdev.h>
25
26#include "bdbuf_tests.h"
27
28static Objects_Id drvq_id = OBJECTS_ID_NONE;
29static Objects_Id testq_id = OBJECTS_ID_NONE;
30
31static int
32test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
33{
34    rtems_status_code     rc;
35    bdbuf_test_msg        msg;
36    size_t                msg_size;
37    rtems_blkdev_request *r;
38
39    switch (req)
40    {
41        case RTEMS_BLKIO_REQUEST:
42        {
43            rtems_blkdev_sg_buffer *sg;
44            unsigned int            i;
45
46            r = argp;
47
48            printf("DISK_DRV: %s ",
49                   r->req == RTEMS_BLKDEV_REQ_READ ? "R" :
50                   r->req == RTEMS_BLKDEV_REQ_WRITE ? "W" : "?");
51            for (i = 0, sg = r->bufs; i < r->bufnum; i++, sg++)
52            {
53                printf("[%" PRIu32 "] ", sg->block);
54            }
55            printf("\n");
56            break;
57        }
58
59        default:
60            return rtems_blkdev_ioctl (dd, req, argp);
61    }
62
63    memset(&msg, 0, sizeof(msg));
64    msg.type = BDBUF_TEST_MSG_TYPE_DRIVER_REQ;
65    msg.val.driver_req.dd = dd;
66    msg.val.driver_req.req = req;
67    msg.val.driver_req.argp = argp;
68
69    rc = rtems_message_queue_send(testq_id, &msg, sizeof(msg));
70    if (rc != RTEMS_SUCCESSFUL)
71    {
72        printf("Error while sending a message to Test task: %u\n", rc);
73        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
74        return 0;
75    }
76
77    /* Wait for a reply from the test task */
78    msg_size = sizeof(msg);
79    rc = rtems_message_queue_receive(drvq_id, &msg, &msg_size,
80                                     RTEMS_WAIT, RTEMS_NO_TIMEOUT);
81    if (rc != RTEMS_SUCCESSFUL)
82    {
83        printf("Error while reading a message from Test task: %u\n", rc);
84        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
85        return 0;
86    }
87    if (msg.type != BDBUF_TEST_MSG_TYPE_DRIVER_REPLY)
88    {
89        printf("Unexpected message comes to test disk driver: %d\n",
90               msg.type);
91        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
92        return 0;
93    }
94
95    if (msg.val.driver_reply.ret_val != 0)
96    {
97        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
98    }
99    else
100    {
101        rtems_blkdev_request_done(r, msg.val.driver_reply.res_status);
102    }
103
104    return 0;
105}
106
107rtems_status_code
108test_disk_initialize(void)
109{
110    rtems_status_code rc;
111
112    rc = rtems_blkdev_create(TEST_DISK_NAME,
113                             TEST_DISK_BLOCK_SIZE, TEST_DISK_BLOCK_NUM,
114                             test_disk_ioctl,
115                             NULL);
116    if (rc != RTEMS_SUCCESSFUL)
117    {
118        printf("Failed to create %s disk\n", TEST_DISK_NAME);
119        return rc;
120    }
121
122    rc = bdbuf_test_create_drv_rx_queue(&drvq_id);
123    if (rc != RTEMS_SUCCESSFUL)
124    {
125        printf("%s() Failed to create Msg Queue for RX: %u\n",
126               __FUNCTION__, rc);
127        return rc;
128    }
129
130    rc = bdbuf_test_create_drv_tx_queue(&testq_id);
131    if (rc != RTEMS_SUCCESSFUL)
132    {
133        printf("%s() Failed to get Msg Queue for TX: %u\n",
134               __FUNCTION__, rc);
135        return rc;
136    }
137
138    printf("TEST DISK - OK\n");
139    return RTEMS_SUCCESSFUL;
140}
Note: See TracBrowser for help on using the repository browser.