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 read/release work in case of only one buffer in ready list.
0005  *
0006  * The same as Test 3.2, but instead of calling rtems_bdbuf_get() in
0007  * threads #1 and #2, it calls rtems_bdbuf_read().
0008  *
0009  * Test sequence:
0010  * -# Call rtems_bdbuf_read(#N1) in thread #1.
0011  * -# Call rtems_bdbuf_read(#N2) in thread #2.
0012  *    This thread blocks because we have no buffers available.
0013  * -# Call rtems_bdbuf_read(#N3) in thread #3.
0014  *    This thread also blocks because we have no buffers available.
0015  * -# Call rtems_bdbuf_release(#N1) in thread #1.
0016  * -# Check that only one thread (thread #2 or thread #3) got a buffer.
0017  *    Another thread shall still be blocked.
0018  * -# Call rtems_bdbuf_release(#N2) in thread #2 and check that
0019  *    thread #3 got a buffer as the result.
0020  * .
0021  *
0022  * Copyright (C) 2010 OKTET Labs, St.-Petersburg, Russia
0023  * Author: Oleg Kravtsov <Oleg.Kravtsov@oktetlabs.ru>
0024  *
0025  * Redistribution and use in source and binary forms, with or without
0026  * modification, are permitted provided that the following conditions
0027  * are met:
0028  * 1. Redistributions of source code must retain the above copyright
0029  *    notice, this list of conditions and the following disclaimer.
0030  * 2. Redistributions in binary form must reproduce the above copyright
0031  *    notice, this list of conditions and the following disclaimer in the
0032  *    documentation and/or other materials provided with the distribution.
0033  *
0034  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0035  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0036  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0037  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0038  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0039  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0040  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0041  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0042  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0043  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0044  * POSSIBILITY OF SUCH DAMAGE.
0045  */
0046 
0047 #ifdef HAVE_CONFIG_H
0048 #include "config.h"
0049 #endif
0050 
0051 #include "bdbuf_tests.h"
0052 
0053 static rtems_task bdbuf_test3_3_thread1(rtems_task_argument arg);
0054 static rtems_task bdbuf_test3_3_thread2(rtems_task_argument arg);
0055 static rtems_task bdbuf_test3_3_thread3(rtems_task_argument arg);
0056 
0057 /* Block number used in the test */
0058 #define TEST_BLK_NUM_N1 96
0059 #define TEST_BLK_NUM_N2 98
0060 #define TEST_BLK_NUM_N3 100
0061 
0062 void
0063 bdbuf_test3_3_main()
0064 {
0065     bdbuf_test_msg msg;
0066 
0067     TEST_START("Test 3.3");
0068 
0069     /*
0070      * Create working threads.
0071      */
0072     SET_THREAD_PRIORITY(2, LOW);
0073     SET_THREAD_PRIORITY(3, HIGH);
0074     START_THREAD(1, bdbuf_test3_3_thread1);
0075     START_THREAD(2, bdbuf_test3_3_thread2);
0076     START_THREAD(3, bdbuf_test3_3_thread3);
0077 
0078     /*
0079      * Start thread #1: it will read buffer #N1.
0080      * Driver is asked to read this buffer.
0081      */
0082     WAIT_DRV_MSG(&msg);
0083     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0084 
0085     WAIT_THREAD_SYNC(1);
0086 
0087     /*
0088      * Block thread #2 and thread #3 on get buffers #N2 and #N3
0089      * correspondingly (bdbuf librbary has no buffers available).
0090      */
0091     CONTINUE_THREAD(2);
0092     CONTINUE_THREAD(3);
0093 
0094     /* Make sure threads managed to block on the buffers get. */
0095     CHECK_THREAD_BLOCKED(2);
0096     CHECK_THREAD_BLOCKED(3);
0097 
0098     /*
0099      * Step 4:
0100      * Thread #1 release buffer.
0101      */
0102     CONTINUE_THREAD(1);
0103 
0104     /* Wait for read request in the driver (for thread #2) */
0105     WAIT_DRV_MSG(&msg);
0106     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0107 
0108     /* Check that there is no read request for another block */
0109     CHECK_NO_DRV_MSG();
0110 
0111     /*
0112      * Check that thread #2 unblocked after this.
0113      */
0114     WAIT_THREAD_SYNC(2);
0115     TEST_CHECK_RESULT("5");
0116 
0117     /* Thread #3 is still in blocked state */
0118     CHECK_THREAD_BLOCKED(3);
0119 
0120     /* Release buffer in thread #2 */
0121     CONTINUE_THREAD(2);
0122 
0123     /* Wait for read request in the driver (for thread #3) */
0124     WAIT_DRV_MSG(&msg);
0125     SEND_DRV_MSG(0, 0, RTEMS_SUCCESSFUL, 0);
0126 
0127     /* Wait for thread #3 to be unblocked */
0128     WAIT_THREAD_SYNC(3);
0129 
0130     /* Release buffer in thread #3 */
0131     CONTINUE_THREAD(3);
0132 
0133     CHECK_NO_DRV_MSG();
0134 
0135     TEST_STOP();
0136 }
0137 
0138 static rtems_task
0139 bdbuf_test3_3_thread1(rtems_task_argument arg)
0140 {
0141     rtems_status_code   rc;
0142     rtems_bdbuf_buffer *bd = NULL;
0143 
0144     /*
0145      * Step 1:
0146      * Call rtems_bdbuf_read(#N) to get a buffer;
0147      */
0148     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N1, &bd);
0149     if (rc != RTEMS_SUCCESSFUL)
0150     {
0151         TEST_FAILED();
0152     }
0153 
0154     CONTINUE_MAIN(1);
0155 
0156     /*
0157      * Step 4:
0158      * Call rtems_bdbuf_release(#N).
0159      */
0160     rc = rtems_bdbuf_release(bd);
0161     if (rc != RTEMS_SUCCESSFUL)
0162     {
0163         TEST_FAILED();
0164     }
0165 
0166     THREAD_END();
0167 }
0168 
0169 static rtems_task
0170 bdbuf_test3_3_thread2(rtems_task_argument arg)
0171 {
0172     rtems_status_code   rc;
0173     rtems_bdbuf_buffer *bd = NULL;
0174 
0175     WAIT_MAIN_SYNC(2);
0176 
0177     /*
0178      * Step 2:
0179      * In thread #2 call read(#N2)
0180      */
0181     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N2, &bd);
0182     if (rc != RTEMS_SUCCESSFUL)
0183     {
0184         TEST_FAILED();
0185     }
0186 
0187     printf("Thread #2 DEBLOCK\n");
0188     CONTINUE_MAIN(2);
0189 
0190     rc = rtems_bdbuf_release(bd);
0191     if (rc != RTEMS_SUCCESSFUL)
0192     {
0193         TEST_FAILED();
0194     }
0195 
0196     THREAD_END();
0197 }
0198 
0199 static rtems_task
0200 bdbuf_test3_3_thread3(rtems_task_argument arg)
0201 {
0202     rtems_status_code   rc;
0203     rtems_bdbuf_buffer *bd = NULL;
0204 
0205     WAIT_MAIN_SYNC(3);
0206 
0207     /*
0208      * Step 3:
0209      * In thread #3 call read(#N3)
0210      */
0211     rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N3, &bd);
0212     if (rc != RTEMS_SUCCESSFUL)
0213     {
0214         TEST_FAILED();
0215     }
0216 
0217     printf("Thread #3 DEBLOCK\n");
0218 
0219     CONTINUE_MAIN(3);
0220 
0221     rc = rtems_bdbuf_release(bd);
0222     if (rc != RTEMS_SUCCESSFUL)
0223     {
0224         TEST_FAILED();
0225     }
0226 
0227     THREAD_END();
0228 }