![]() |
|
|||
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_read() and rtems_bdbuf_release_modified() 0005 * coexist. rtems_bdbuf_read() is blocked when required buffer is being 0006 * transferred. 0007 * 0008 * The same as Test 2.1, but on step 7 thread #2 calls 0009 * rtems_bdbuf_release_modified(). 0010 * 0011 * Test sequence: 0012 * -# Call rtems_bdbuf_read() function in thread #1 and block on 0013 * waiting for read complete notification. 0014 * -# Call rtems_bdbuf_read() function in thread #2 for 0015 * the same block number. As the result it blocks on this read 0016 * as well (but it will block on transfer semaphore). 0017 * -# Disk device reports success in read complete notification. 0018 * As the result rtems_bdbuf_read() function returns 0019 * RTEMS_SUCCESSFUL in thread #1. 0020 * -# Thread #1 releases buffer with rtems_bdbuf_release_modified() function. 0021 * -# rtems_bdbuf_read() function in thread #2 unlocks and 0022 * returns RTEMS_SUCCESSFUL. 0023 * -# Wait swapout period and check that the buffer is not requested 0024 * to be flushed to a disk. 0025 * -# Call rtems_bdbuf_release_modified() function in thread #2. 0026 * -# Check that this block number is requested for a flush in swapout period. 0027 * 0028 * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia 0029 * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru> 0030 * 0031 * Redistribution and use in source and binary forms, with or without 0032 * modification, are permitted provided that the following conditions 0033 * are met: 0034 * 1. Redistributions of source code must retain the above copyright 0035 * notice, this list of conditions and the following disclaimer. 0036 * 2. Redistributions in binary form must reproduce the above copyright 0037 * notice, this list of conditions and the following disclaimer in the 0038 * documentation and/or other materials provided with the distribution. 0039 * 0040 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0041 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0042 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0043 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0044 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0045 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0046 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0047 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0048 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0049 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0050 * POSSIBILITY OF SUCH DAMAGE. 0051 */ 0052 0053 #ifdef HAVE_CONFIG_H 0054 #include "config.h" 0055 #endif 0056 0057 #include "bdbuf_tests.h" 0058 0059 static rtems_task bdbuf_test2_2_thread1(rtems_task_argument arg); 0060 static rtems_task bdbuf_test2_2_thread2(rtems_task_argument arg); 0061 0062 /* Block number used in the test */ 0063 #define TEST_BLK_NUM 70 0064 0065 void 0066 bdbuf_test2_2_main() 0067 { 0068 bdbuf_test_msg msg; 0069 0070 TEST_START("Test 2.2"); 0071 0072 START_THREAD(1, bdbuf_test2_2_thread1); 0073 START_THREAD(2, bdbuf_test2_2_thread2); 0074 0075 /* 0076 * Step 1: 0077 * Thread #1 calls rtems_bdbuf_read() and we block 0078 * this thread on data transfer operation. 0079 */ 0080 WAIT_DRV_MSG(&msg); 0081 0082 /* 0083 * Step 2: 0084 * Thread #2 calls rtems_bdbuf_read() for the same 0085 * block number, as the result it shall block waiting 0086 * on buffer state change (waiting on TRANSFER state). 0087 */ 0088 CONTINUE_THREAD(2); 0089 0090 /* Make sure thread #2 managed to block on the buffer. */ 0091 CHECK_THREAD_BLOCKED(2); 0092 0093 /* 0094 * Step 3: 0095 * Unblock thread #1 by reporting successful data transfer result. 0096 */ 0097 SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0); 0098 0099 /* 0100 * Wait for sync from thread #1. 0101 */ 0102 WAIT_THREAD_SYNC(1); 0103 TEST_CHECK_RESULT("3"); 0104 0105 /* Check thread #2 is still blocked */ 0106 CHECK_THREAD_BLOCKED(2); 0107 0108 /* 0109 * Step 4: 0110 * Thread #1 releases buffer with bdbuf_release_modified() call. 0111 */ 0112 CONTINUE_THREAD(1); 0113 0114 /* 0115 * Step 5: 0116 * On buffer release operation, we should have unblock 0117 * of thread #2 that is waiting on read buffer operation. 0118 */ 0119 WAIT_THREAD_SYNC(2); 0120 TEST_CHECK_RESULT("5"); 0121 0122 /* 0123 * Step 6: 0124 * Wait swapout period and check that there is no 0125 * request to flush buffer onto a disk. 0126 */ 0127 CHECK_NO_DRV_MSG(); 0128 0129 /* 0130 * Step 7: 0131 * Thread #2 releases buffer with bdbuf_release_modified() call. 0132 */ 0133 CONTINUE_THREAD(2); 0134 0135 /* 0136 * Step 8: 0137 * Check that in swapout interval disk device 0138 * driver is requested to flush buffer. 0139 */ 0140 WAIT_DRV_MSG_WR(&msg); 0141 SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0); 0142 0143 TEST_STOP(); 0144 } 0145 0146 static rtems_task 0147 bdbuf_test2_2_thread1(rtems_task_argument arg) 0148 { 0149 rtems_status_code rc; 0150 rtems_bdbuf_buffer *bd = NULL; 0151 0152 /* 0153 * Step 1 - 3: 0154 * Try to read blk #N on thread #1 0155 * We will block on this read and meanwhile 0156 * thread #2 will try to read the same block. 0157 * After blocking on read in thread #2, device 0158 * driver will notify successful completion of 0159 * date transfer, and as the result this call 0160 * will return valid buffer. 0161 */ 0162 rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd); 0163 if (rc != RTEMS_SUCCESSFUL) 0164 { 0165 TEST_FAILED(); 0166 } 0167 CONTINUE_MAIN(1); 0168 0169 /* 0170 * Step 4: 0171 * Release buffer returned on the previous step. 0172 */ 0173 rc = rtems_bdbuf_release_modified(bd); 0174 if (rc != RTEMS_SUCCESSFUL) 0175 { 0176 TEST_FAILED(); 0177 } 0178 THREAD_END(); 0179 } 0180 0181 static rtems_task 0182 bdbuf_test2_2_thread2(rtems_task_argument arg) 0183 { 0184 rtems_status_code rc; 0185 rtems_bdbuf_buffer *bd = NULL; 0186 0187 WAIT_MAIN_SYNC(2); 0188 0189 /* 0190 * Step 2: 0191 * Try to read block #N. Right now thread #1 is waiting 0192 * on data transfer operation, so we will block here as well. 0193 * 0194 * Step 5: 0195 * On step 4 thread #1 releases buffer and as the result 0196 * our read operation should finish with success. 0197 */ 0198 rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd); 0199 if (rc != RTEMS_SUCCESSFUL) 0200 { 0201 TEST_FAILED(); 0202 } 0203 CONTINUE_MAIN(2); 0204 0205 /* 0206 * Step 7: 0207 * Release buffer. 0208 */ 0209 rc = rtems_bdbuf_release_modified(bd); 0210 if (rc != RTEMS_SUCCESSFUL) 0211 { 0212 TEST_FAILED(); 0213 } 0214 THREAD_END(); 0215 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |