![]() |
|
|||
File indexing completed on 2025-05-11 08:24:52
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup ScoreTqValTq 0007 */ 0008 0009 /* 0010 * Copyright (C) 2022 embedded brains GmbH & Co. KG 0011 * 0012 * Redistribution and use in source and binary forms, with or without 0013 * modification, are permitted provided that the following conditions 0014 * are met: 0015 * 1. Redistributions of source code must retain the above copyright 0016 * notice, this list of conditions and the following disclaimer. 0017 * 2. Redistributions in binary form must reproduce the above copyright 0018 * notice, this list of conditions and the following disclaimer in the 0019 * documentation and/or other materials provided with the distribution. 0020 * 0021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0024 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0025 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0026 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0027 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0028 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0029 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0030 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0031 * POSSIBILITY OF SUCH DAMAGE. 0032 */ 0033 0034 /* 0035 * This file is part of the RTEMS quality process and was automatically 0036 * generated. If you find something that needs to be fixed or 0037 * worded better please post a report or patch to an RTEMS mailing list 0038 * or raise a bug report: 0039 * 0040 * https://www.rtems.org/bugs.html 0041 * 0042 * For information on updating and regenerating please refer to the How-To 0043 * section in the Software Requirements Engineering chapter of the 0044 * RTEMS Software Engineering manual. The manual is provided as a part of 0045 * a release. For development sources please refer to the online 0046 * documentation at: 0047 * 0048 * https://docs.rtems.org 0049 */ 0050 0051 #ifdef HAVE_CONFIG_H 0052 #include "config.h" 0053 #endif 0054 0055 #include "tx-support.h" 0056 #include "tx-thread-queue.h" 0057 0058 #include <rtems/test.h> 0059 0060 /** 0061 * @defgroup ScoreTqValTq spec:/score/tq/val/tq 0062 * 0063 * @ingroup TestsuitesValidationNoClock0 0064 * 0065 * @brief Tests special thread queue behaviour. 0066 * 0067 * This test case performs the following actions: 0068 * 0069 * - Use two worker threads to provoke a deadlock detection involving a thread 0070 * queue with no owner. 0071 * 0072 * - Let blocker A obtain mutex A. 0073 * 0074 * - Let blocker A block on a counting semaphore. 0075 * 0076 * - Let blocker B block on mutex A. The deadlock detection will stop since 0077 * blocker A blocks on the counting semaphore which has no owner. 0078 * 0079 * - Clean up all used resources. 0080 * 0081 * @{ 0082 */ 0083 0084 /** 0085 * @brief Test context for spec:/score/tq/val/tq test case. 0086 */ 0087 typedef struct { 0088 /** 0089 * @brief This member contains the thread queue test context. 0090 */ 0091 TQContext tq_ctx; 0092 } ScoreTqValTq_Context; 0093 0094 static ScoreTqValTq_Context 0095 ScoreTqValTq_Instance; 0096 0097 static void ScoreTqValTq_Setup( ScoreTqValTq_Context *ctx ) 0098 { 0099 rtems_status_code sc; 0100 0101 SetSelfPriority( PRIO_NORMAL ); 0102 TQInitialize( &ctx->tq_ctx ); 0103 0104 /* Replace mutex D with a counting semaphore */ 0105 DeleteMutex( ctx->tq_ctx.mutex_id[ TQ_MUTEX_D ] ); 0106 sc = rtems_semaphore_create( 0107 rtems_build_name( 'C', 'S', 'E', 'M' ), 0108 0, 0109 RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY, 0110 0, 0111 &ctx->tq_ctx.mutex_id[ TQ_MUTEX_D ] 0112 ); 0113 T_rsc_success( sc ); 0114 } 0115 0116 static void ScoreTqValTq_Setup_Wrap( void *arg ) 0117 { 0118 ScoreTqValTq_Context *ctx; 0119 0120 ctx = arg; 0121 ScoreTqValTq_Setup( ctx ); 0122 } 0123 0124 static void ScoreTqValTq_Teardown( ScoreTqValTq_Context *ctx ) 0125 { 0126 TQDestroy( &ctx->tq_ctx ); 0127 RestoreRunnerPriority(); 0128 } 0129 0130 static void ScoreTqValTq_Teardown_Wrap( void *arg ) 0131 { 0132 ScoreTqValTq_Context *ctx; 0133 0134 ctx = arg; 0135 ScoreTqValTq_Teardown( ctx ); 0136 } 0137 0138 static T_fixture ScoreTqValTq_Fixture = { 0139 .setup = ScoreTqValTq_Setup_Wrap, 0140 .stop = NULL, 0141 .teardown = ScoreTqValTq_Teardown_Wrap, 0142 .scope = NULL, 0143 .initial_context = &ScoreTqValTq_Instance 0144 }; 0145 0146 /** 0147 * @brief Use two worker threads to provoke a deadlock detection involving a 0148 * thread queue with no owner. 0149 */ 0150 static void ScoreTqValTq_Action_0( ScoreTqValTq_Context *ctx ) 0151 { 0152 TQReset( &ctx->tq_ctx ); 0153 0154 /* 0155 * Let blocker A obtain mutex A. 0156 */ 0157 TQSend( &ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_MUTEX_A_OBTAIN ); 0158 0159 /* 0160 * Let blocker A block on a counting semaphore. 0161 */ 0162 TQSend( &ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_MUTEX_D_OBTAIN ); 0163 0164 /* 0165 * Let blocker B block on mutex A. The deadlock detection will stop since 0166 * blocker A blocks on the counting semaphore which has no owner. 0167 */ 0168 TQSend( &ctx->tq_ctx, TQ_BLOCKER_B, TQ_EVENT_MUTEX_A_OBTAIN ); 0169 0170 /* 0171 * Clean up all used resources. 0172 */ 0173 TQMutexRelease( &ctx->tq_ctx, TQ_MUTEX_D ); 0174 TQSend( &ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_MUTEX_A_RELEASE ); 0175 TQSend( &ctx->tq_ctx, TQ_BLOCKER_B, TQ_EVENT_MUTEX_A_RELEASE ); 0176 } 0177 0178 /** 0179 * @fn void T_case_body_ScoreTqValTq( void ) 0180 */ 0181 T_TEST_CASE_FIXTURE( ScoreTqValTq, &ScoreTqValTq_Fixture ) 0182 { 0183 ScoreTqValTq_Context *ctx; 0184 0185 ctx = T_fixture_context(); 0186 0187 ScoreTqValTq_Action_0( ctx ); 0188 } 0189 0190 /** @} */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |