![]() |
|
|||
File indexing completed on 2025-05-11 08:24:53
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup RtemsTaskValTask 0007 */ 0008 0009 /* 0010 * Copyright (C) 2021, 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 <rtems.h> 0056 #include <string.h> 0057 #include <rtems/score/apimutex.h> 0058 0059 #include "ts-config.h" 0060 #include "tx-support.h" 0061 0062 #include <rtems/test.h> 0063 0064 /** 0065 * @defgroup RtemsTaskValTask spec:/rtems/task/val/task 0066 * 0067 * @ingroup TestsuitesValidationNoClock0 0068 * 0069 * @brief This test case collection provides validation test cases for 0070 * requirements of the @ref RTEMSAPIClassicTasks. 0071 * 0072 * This test case performs the following actions: 0073 * 0074 * - Call rtems_task_self() check the returned value. 0075 * 0076 * - Check that the returned value is equal to the object identifier of the 0077 * calling task. 0078 * 0079 * - Call rtems_task_iterate() with a visitor which always returns false. 0080 * 0081 * - Check that the all counter is equal to the count of tasks. Check that 0082 * the calling task was visited exacly once. Firstly, this shows that 0083 * rtems_task_iterate() used the parameters specified by ``visitor`` and 0084 * ``arg``. Secondly, this shows that the iteration was done over all 0085 * tasks. 0086 * 0087 * - Check that the object alloctor mutex was not owned before and after the 0088 * call. Check that the object alloctor mutex was owned during the 0089 * iteration. 0090 * 0091 * - Call rtems_task_iterate() with a visitor which returns true. 0092 * 0093 * - Check that the all counter is equal to one. This shows that the 0094 * iteration stops when the visitor returns true. 0095 * 0096 * - Assert that RTEMS_TASK_STORAGE_ALIGNMENT is a constant expression which 0097 * evaluates to the expected value. 0098 * 0099 * - Assert that RTEMS_NO_PRIORITY is a constant expression which evaluates to 0100 * the expected value. 0101 * 0102 * - Assert that RTEMS_MINIMUM_STACK_SIZE is a constant expression which 0103 * evaluates to the expected value. 0104 * 0105 * - Assert that RTEMS_CONFIGURED_MINIMUM_STACK_SIZE is a constant expression 0106 * which evaluates to the expected value. 0107 * 0108 * - Assert that RTEMS_MINIMUM_PRIORITY is a constant expression which 0109 * evaluates to the expected value. 0110 * 0111 * - Validate RTEMS_SELF using a sample directive call. 0112 * 0113 * - Check that rtems_task_is_suspended() returns the expected status if 0114 * called with a task identifier parameter of RTEMS_SELF. 0115 * 0116 * - Validate the home scheduler of tasks created by rtems_task_create() and 0117 * constructed by rtems_task_construct(). 0118 * 0119 * - Create a task. Check that the home scheduler of the created task is 0120 * scheduler A. 0121 * 0122 * - Construct a task. Check that the home scheduler of the constructed task 0123 * is scheduler A. 0124 * 0125 * @{ 0126 */ 0127 0128 typedef struct { 0129 bool owner_before; 0130 bool owner_in_visitor; 0131 bool owner_after; 0132 uint32_t counter_all; 0133 uint32_t counter_self; 0134 bool done; 0135 } TaskIterateContext; 0136 0137 static bool TaskVisitor( rtems_tcb *tcb, void *arg ) 0138 { 0139 TaskIterateContext *ctx; 0140 0141 ctx = arg; 0142 ++ctx->counter_all; 0143 0144 if ( rtems_task_self() == tcb->Object.id ) { 0145 ++ctx->counter_self; 0146 } 0147 0148 ctx->owner_in_visitor = _RTEMS_Allocator_is_owner(); 0149 0150 return ctx->done; 0151 } 0152 0153 /** 0154 * @brief Call rtems_task_self() check the returned value. 0155 */ 0156 static void RtemsTaskValTask_Action_0( void ) 0157 { 0158 rtems_id id; 0159 0160 id = rtems_task_self(); 0161 0162 /* 0163 * Check that the returned value is equal to the object identifier of the 0164 * calling task. 0165 */ 0166 T_step_eq_u32( 0, id, 0x0a010001 ); 0167 } 0168 0169 /** 0170 * @brief Call rtems_task_iterate() with a visitor which always returns false. 0171 */ 0172 static void RtemsTaskValTask_Action_1( void ) 0173 { 0174 TaskIterateContext ctx; 0175 uint32_t task_count; 0176 0177 task_count = rtems_scheduler_get_processor_maximum(); 0178 0179 if ( task_count > 4 ) { 0180 task_count = 4; 0181 } 0182 0183 ++task_count; 0184 0185 memset( &ctx, 0, sizeof( ctx ) ); 0186 ctx.owner_before = _RTEMS_Allocator_is_owner(); 0187 rtems_task_iterate( TaskVisitor, &ctx ); 0188 ctx.owner_after = _RTEMS_Allocator_is_owner(); 0189 0190 /* 0191 * Check that the all counter is equal to the count of tasks. Check that the 0192 * calling task was visited exacly once. Firstly, this shows that 0193 * rtems_task_iterate() used the parameters specified by ``visitor`` and 0194 * ``arg``. Secondly, this shows that the iteration was done over all tasks. 0195 */ 0196 T_step_eq_u32( 1, ctx.counter_all, task_count ); 0197 T_step_eq_u32( 2, ctx.counter_self, 1 ); 0198 0199 /* 0200 * Check that the object alloctor mutex was not owned before and after the 0201 * call. Check that the object alloctor mutex was owned during the 0202 * iteration. 0203 */ 0204 T_step_false( 3, ctx.owner_before ); 0205 T_step_true( 4, ctx.owner_in_visitor ); 0206 T_step_false( 5, ctx.owner_after ); 0207 } 0208 0209 /** 0210 * @brief Call rtems_task_iterate() with a visitor which returns true. 0211 */ 0212 static void RtemsTaskValTask_Action_2( void ) 0213 { 0214 TaskIterateContext ctx; 0215 0216 memset( &ctx, 0, sizeof( ctx ) ); 0217 ctx.done = true; 0218 rtems_task_iterate( TaskVisitor, &ctx ); 0219 0220 /* 0221 * Check that the all counter is equal to one. This shows that the iteration 0222 * stops when the visitor returns true. 0223 */ 0224 T_step_eq_u32( 6, ctx.counter_all, 1 ); 0225 } 0226 0227 /** 0228 * @brief Assert that RTEMS_TASK_STORAGE_ALIGNMENT is a constant expression 0229 * which evaluates to the expected value. 0230 */ 0231 static void RtemsTaskValTask_Action_3( void ) 0232 { 0233 RTEMS_STATIC_ASSERT( 0234 RTEMS_TASK_STORAGE_ALIGNMENT == CPU_STACK_ALIGNMENT, 0235 STORAGE_ALIGNMENT 0236 ); 0237 } 0238 0239 /** 0240 * @brief Assert that RTEMS_NO_PRIORITY is a constant expression which 0241 * evaluates to the expected value. 0242 */ 0243 static void RtemsTaskValTask_Action_4( void ) 0244 { 0245 RTEMS_STATIC_ASSERT( 0246 RTEMS_NO_PRIORITY == RTEMS_CURRENT_PRIORITY, 0247 NO_PRIORITY 0248 ); 0249 } 0250 0251 /** 0252 * @brief Assert that RTEMS_MINIMUM_STACK_SIZE is a constant expression which 0253 * evaluates to the expected value. 0254 */ 0255 static void RtemsTaskValTask_Action_5( void ) 0256 { 0257 RTEMS_STATIC_ASSERT( 0258 RTEMS_MINIMUM_STACK_SIZE == STACK_MINIMUM_SIZE, 0259 MINIMUM_STACK_SIZE 0260 ); 0261 } 0262 0263 /** 0264 * @brief Assert that RTEMS_CONFIGURED_MINIMUM_STACK_SIZE is a constant 0265 * expression which evaluates to the expected value. 0266 */ 0267 static void RtemsTaskValTask_Action_6( void ) 0268 { 0269 RTEMS_STATIC_ASSERT( 0270 RTEMS_CONFIGURED_MINIMUM_STACK_SIZE == 0, 0271 CONFIGURED_MINIMUM_STACK_SIZE 0272 ); 0273 } 0274 0275 /** 0276 * @brief Assert that RTEMS_MINIMUM_PRIORITY is a constant expression which 0277 * evaluates to the expected value. 0278 */ 0279 static void RtemsTaskValTask_Action_7( void ) 0280 { 0281 RTEMS_STATIC_ASSERT( RTEMS_MINIMUM_PRIORITY == 1, MINIMUM_PRIORITY ); 0282 } 0283 0284 /** 0285 * @brief Validate RTEMS_SELF using a sample directive call. 0286 */ 0287 static void RtemsTaskValTask_Action_8( void ) 0288 { 0289 rtems_status_code sc; 0290 0291 /* 0292 * Check that rtems_task_is_suspended() returns the expected status if called 0293 * with a task identifier parameter of RTEMS_SELF. 0294 */ 0295 sc = rtems_task_is_suspended( RTEMS_SELF ); 0296 T_step_rsc_success( 7, sc ); 0297 } 0298 0299 /** 0300 * @brief Validate the home scheduler of tasks created by rtems_task_create() 0301 * and constructed by rtems_task_construct(). 0302 */ 0303 static void RtemsTaskValTask_Action_9( void ) 0304 { 0305 rtems_status_code sc; 0306 rtems_id id; 0307 0308 /* 0309 * Create a task. Check that the home scheduler of the created task is 0310 * scheduler A. 0311 */ 0312 sc = rtems_task_create( 0313 OBJECT_NAME, 0314 1, 0315 TEST_MINIMUM_STACK_SIZE, 0316 RTEMS_DEFAULT_MODES, 0317 RTEMS_DEFAULT_ATTRIBUTES, 0318 &id 0319 ); 0320 T_step_rsc_success( 8, sc ); 0321 0322 T_step_eq_u32( 9, GetScheduler( id ), SCHEDULER_A_ID ); 0323 DeleteTask( id ); 0324 0325 /* 0326 * Construct a task. Check that the home scheduler of the constructed task 0327 * is scheduler A. 0328 */ 0329 sc = rtems_task_construct( &DefaultTaskConfig, &id ); 0330 T_step_rsc_success( 10, sc ); 0331 0332 T_step_eq_u32( 11, GetScheduler( id ), SCHEDULER_A_ID ); 0333 DeleteTask( id ); 0334 } 0335 0336 /** 0337 * @fn void T_case_body_RtemsTaskValTask( void ) 0338 */ 0339 T_TEST_CASE( RtemsTaskValTask ) 0340 { 0341 T_plan( 12 ); 0342 0343 RtemsTaskValTask_Action_0(); 0344 RtemsTaskValTask_Action_1(); 0345 RtemsTaskValTask_Action_2(); 0346 RtemsTaskValTask_Action_3(); 0347 RtemsTaskValTask_Action_4(); 0348 RtemsTaskValTask_Action_5(); 0349 RtemsTaskValTask_Action_6(); 0350 RtemsTaskValTask_Action_7(); 0351 RtemsTaskValTask_Action_8(); 0352 RtemsTaskValTask_Action_9(); 0353 } 0354 0355 /** @} */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |