Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:32

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*! @file
0004  * @brief Check the behaviour of rtems_bdbuf_read() function
0005  * with different reports from disk device driver.
0006  *
0007  * Test sequence:
0008  * -# Call rtems_bdbuf_read() function and return 0 from disk device
0009  *    driver ioctl() function, and the result of asynchronous read
0010  *    complete notification is successful.
0011  * -# Check that rtems_bdbuf_read() returns RTEMS_SUCCESSFUL and
0012  *    provides buffer descriptor.
0013  * -# Call rtems_bdbuf_read() function and return -1 from disk device
0014  *    driver ioctl() function (there will be no asynchronous read
0015  *    complete notification).
0016  * -# Check that rtems_bdbuf_read() returns RTEMS_IO_ERROR.
0017  * -# Call rtems_bdbuf_read() function and return 0 from disk device
0018  *    driver ioctl() function, but the result of asynchronous read
0019  *    complete notification is faulty (with some erroneous status).
0020  * -# Check that rtems_bdbuf_read() returns that status and does not
0021  *    return buffer descriptor.
0022  *
0023  * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
0024  * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
0025  *
0026  * Redistribution and use in source and binary forms, with or without
0027  * modification, are permitted provided that the following conditions
0028  * are met:
0029  * 1. Redistributions of source code must retain the above copyright
0030  *    notice, this list of conditions and the following disclaimer.
0031  * 2. Redistributions in binary form must reproduce the above copyright
0032  *    notice, this list of conditions and the following disclaimer in the
0033  *    documentation and/or other materials provided with the distribution.
0034  *
0035  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0036  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0037  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0038  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0039  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0040  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0041  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0042  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0043  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0044  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0045  * POSSIBILITY OF SUCH DAMAGE.
0046  */
0047 
0048 #ifdef HAVE_CONFIG_H
0049 #include "config.h"
0050 #endif
0051 
0052 #include "bdbuf_tests.h"
0053 
0054 static rtems_task bdbuf_test1_1_thread1(rtems_task_argument arg);
0055 
0056 #define TEST_BLK_NUM 10
0057 
0058 void
0059 bdbuf_test1_1_main()
0060 {
0061     bdbuf_test_msg msg;
0062 
0063     TEST_START("Test 1.1");
0064 
0065     /*
0066      * Create working thread that will call rtems_bdbuf_read() function.
0067      */
0068     START_THREAD(1, bdbuf_test1_1_thread1);
0069 
0070     /*
0071      * Step 1:
0072      * Check that rtems_bdbuf_read() returns RTEMS_SUCCESSFUL
0073      * when device driver returns 0 from ioctl() call and
0074      * return RTEMS_SUCCESSFUL status in asynchronous
0075      * callback notification.
0076      */
0077     WAIT_DRV_MSG(&msg);
0078     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0079 
0080     WAIT_THREAD_SYNC(1);
0081     TEST_CHECK_RESULT("2");
0082 
0083     CONTINUE_THREAD(1);
0084 
0085     /*
0086      * Step 3:
0087      * Check that rtems_bdbuf_read() returns RTEMS_IO_ERROR
0088      * return code, when device driver returns -1 from ioctl() call.
0089      */
0090     WAIT_DRV_MSG(&msg);
0091     SEND_DRV_MSG(-1, EFAULT, RTEMS_SUCCESSFUL, 0);
0092 
0093     WAIT_THREAD_SYNC(1);
0094     TEST_CHECK_RESULT("4");
0095 
0096     CONTINUE_THREAD(1);
0097 
0098     /*
0099      * Step 5:
0100      * Check that rtems_bdbuf_read() returns status obtained
0101      * from device driver via asynchonous notification.
0102      * On this step device driver returns 0 from ioctl() call,
0103      * but notification callback is called with RTEMS_IO_ERROR status.
0104      */
0105     WAIT_DRV_MSG(&msg);
0106     SEND_DRV_MSG(0, 0, RTEMS_IO_ERROR, EFAULT);
0107 
0108     WAIT_THREAD_SYNC(1);
0109     TEST_CHECK_RESULT("6");
0110 
0111     CONTINUE_THREAD(1);
0112 
0113     TEST_STOP();
0114 }
0115 
0116 
0117 static rtems_task
0118 bdbuf_test1_1_thread1(rtems_task_argument arg)
0119 {
0120     rtems_status_code   rc;
0121     rtems_bdbuf_buffer *bd1 = NULL;
0122     rtems_bdbuf_buffer *bd2 = NULL;
0123 
0124     /*
0125      * Step 1-2:
0126      * Successful read operation.
0127      */
0128     rc = rtems_bdbuf_read(test_dd, 0, &bd1);
0129     if (rc != RTEMS_SUCCESSFUL)
0130     {
0131         TEST_FAILED();
0132     }
0133     rc = rtems_bdbuf_release(bd1);
0134     if (rc != RTEMS_SUCCESSFUL)
0135     {
0136         TEST_FAILED();
0137     }
0138 
0139     CONTINUE_MAIN(1);
0140 
0141     /*
0142      * Step 3-4:
0143      * Read operation fails with RTEMS_IO_ERROR code.
0144      * The function shall not update user pointer.
0145      */
0146     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
0147     if (rc != RTEMS_IO_ERROR || bd2 != NULL)
0148     {
0149         TEST_FAILED();
0150     }
0151 
0152     CONTINUE_MAIN(1);
0153 
0154     /*
0155      * Step 5-6:
0156      * Read operation fails with RTEMS_IO_ERROR code.
0157      * The function shall not update user pointer.
0158      */
0159     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
0160     if (rc != RTEMS_IO_ERROR || bd2 != NULL)
0161     {
0162         TEST_FAILED();
0163     }
0164 
0165     CONTINUE_MAIN(1);
0166 
0167     THREAD_END();
0168 }