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 how rtems_bdbuf_sync() works.
0005  *
0006  * Test sequence:
0007  * -# Call rtems_bdbuf_read(#N) in thread #1.
0008  * -# Call rtems_bdbuf_sync(#N) in thread #1.
0009  * -# After a while disk driver gets write request for block #N.
0010  *    Notify bdbuf about write complete event.
0011  * -# Check that rtems_bdbuf_sync(#N) in thread #1 unlocked after this.
0012  * -# Call rtems_bdbuf_read(#N) in thread #2.
0013  * -# Check that buffer is successfully obtained in thread #2.
0014  * -# Call rtems_bdbuf_release(#N) in thread #2.
0015  * .
0016  *
0017  * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
0018  * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
0019  *
0020  * Redistribution and use in source and binary forms, with or without
0021  * modification, are permitted provided that the following conditions
0022  * are met:
0023  * 1. Redistributions of source code must retain the above copyright
0024  *    notice, this list of conditions and the following disclaimer.
0025  * 2. Redistributions in binary form must reproduce the above copyright
0026  *    notice, this list of conditions and the following disclaimer in the
0027  *    documentation and/or other materials provided with the distribution.
0028  *
0029  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0030  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0031  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0032  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0033  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0034  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0035  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0036  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0037  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0038  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0039  * POSSIBILITY OF SUCH DAMAGE.
0040  */
0041 
0042 #ifdef HAVE_CONFIG_H
0043 #include "config.h"
0044 #endif
0045 
0046 #include "bdbuf_tests.h"
0047 
0048 static rtems_task bdbuf_test4_3_thread1(rtems_task_argument arg);
0049 static rtems_task bdbuf_test4_3_thread2(rtems_task_argument arg);
0050 
0051 /* Block number used in the test */
0052 #define TEST_BLK_NUM_N 116
0053 
0054 void
0055 bdbuf_test4_3_main()
0056 {
0057     bdbuf_test_msg msg;
0058 
0059     TEST_START("Test 4.3");
0060 
0061     START_THREAD(1, bdbuf_test4_3_thread1);
0062     START_THREAD(2, bdbuf_test4_3_thread2);
0063 
0064     /*
0065      * Step 1:
0066      * Call rtems_bdbuf_read(#N) in thread #1.
0067      * Wait for read request in disk driver.
0068      */
0069     WAIT_DRV_MSG(&msg);
0070     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0071 
0072     /*
0073      * Step 2:
0074      * Call rtems_bdbuf_sync(#N) in thread #1.
0075      * As the result buffer is asked to be flashed onto the disk.
0076      */
0077     WAIT_DRV_MSG_WR(&msg);
0078     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0079 
0080     /*
0081      * Step 4:
0082      * Check that rtems_bdbuf_sync(#N) call is unlocked.
0083      */
0084     WAIT_THREAD_SYNC(1);
0085     TEST_CHECK_RESULT("4");
0086 
0087     /*
0088      * Step 5:
0089      * Call rtems_bdbuf_read(#N) in thread #2.
0090      */
0091     CONTINUE_THREAD(2);
0092 
0093     /*
0094      * Step 6:
0095      * Check that thread #2 successfully got the buffer.
0096      */
0097     WAIT_THREAD_SYNC(2);
0098 
0099     /*
0100      * Step 7:
0101      * Release buffer in thread #2
0102      */
0103     CONTINUE_THREAD(2);
0104 
0105     /*
0106      * Exit from thread #1.
0107      */
0108     CONTINUE_THREAD(1);
0109 
0110     TEST_STOP();
0111 }
0112 
0113 static rtems_task
0114 bdbuf_test4_3_thread1(rtems_task_argument arg)
0115 {
0116     rtems_status_code   rc;
0117     rtems_bdbuf_buffer *bd = NULL;
0118 
0119     /*
0120      * Step 1:
0121      * Call rtems_bdbuf_read(#N) in thread #1;
0122      */
0123     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
0124     if (rc != RTEMS_SUCCESSFUL)
0125     {
0126         TEST_FAILED();
0127     }
0128 
0129     /*
0130      * Step 2:
0131      * Call rtems_bdbuf_sync(#N)
0132      */
0133     rc = rtems_bdbuf_sync(bd);
0134     if (rc != RTEMS_SUCCESSFUL)
0135     {
0136         TEST_FAILED();
0137     }
0138 
0139     CONTINUE_MAIN(1);
0140 
0141     THREAD_END();
0142 }
0143 
0144 static rtems_task
0145 bdbuf_test4_3_thread2(rtems_task_argument arg)
0146 {
0147     rtems_status_code   rc;
0148     rtems_bdbuf_buffer *bd = NULL;
0149 
0150     WAIT_MAIN_SYNC(2);
0151 
0152     /*
0153      * Step 5:
0154      * In thread #2 call rtems_bdbuf_read(#N).
0155      * We will block on this call.
0156      */
0157     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
0158     if (rc != RTEMS_SUCCESSFUL)
0159     {
0160         TEST_FAILED();
0161     }
0162 
0163     CONTINUE_MAIN(2);
0164 
0165     /*
0166      * Release buffer.
0167      */
0168     rc = rtems_bdbuf_release(bd);
0169     if (rc != RTEMS_SUCCESSFUL)
0170     {
0171         TEST_FAILED();
0172     }
0173     THREAD_END();
0174 }