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