Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:50

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2014.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #if !defined(OPERATION_COUNT)
0030 #define OPERATION_COUNT 100
0031 #endif
0032 
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036 
0037 #include <rtems/btimer.h>
0038 
0039 #define CONFIGURE_INIT
0040 #include "system.h"
0041 
0042 #if defined(TM03)
0043 const char rtems_test_name[] = "TIME TEST 3";
0044 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO)
0045 #define ATTR_DESC "counting/FIFO"
0046 
0047 #elif defined(TM32)
0048 const char rtems_test_name[] = "TIME TEST 32";
0049 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY)
0050 #define ATTR_DESC "counting/priority"
0051 
0052 #elif defined(TM34)
0053 const char rtems_test_name[] = "TIME TEST 34";
0054 #define SEMAPHORE_ATTRIBUTES RTEMS_BINARY_SEMAPHORE
0055 #define ATTR_DESC "binary/FIFO"
0056 
0057 #elif defined(TM36)
0058 const char rtems_test_name[] = "TIME TEST 36";
0059 #define SEMAPHORE_ATTRIBUTES (RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY)
0060 #define ATTR_DESC "binary/priority"
0061 
0062 #else
0063 #error "Unknown test configuration"
0064 #endif
0065 
0066 
0067 rtems_id Semaphore_id;
0068 rtems_task test_init(
0069   rtems_task_argument argument
0070 );
0071 
0072 rtems_task Middle_tasks(
0073   rtems_task_argument argument
0074 );
0075 
0076 rtems_task High_task(
0077   rtems_task_argument argument
0078 );
0079 
0080 int operation_count = OPERATION_COUNT;
0081 
0082 rtems_task Init(
0083   rtems_task_argument argument
0084 )
0085 {
0086   rtems_status_code status;
0087   rtems_id          task_id;
0088 
0089   Print_Warning();
0090 
0091   TEST_BEGIN();
0092   status = rtems_task_create(
0093     rtems_build_name( 'T', 'A', '1', ' ' ),
0094     RTEMS_MAXIMUM_PRIORITY - 1u,
0095     RTEMS_MINIMUM_STACK_SIZE,
0096     RTEMS_DEFAULT_MODES,
0097     RTEMS_DEFAULT_ATTRIBUTES,
0098     &task_id
0099   );
0100   directive_failed( status, "rtems_task_create of test_init" );
0101 
0102   status = rtems_task_start( task_id, test_init, 0 );
0103   directive_failed( status, "rtems_task_start of test_init" );
0104 
0105   rtems_task_exit();
0106 }
0107 
0108 rtems_task test_init(
0109   rtems_task_argument argument
0110 )
0111 {
0112   rtems_status_code   status;
0113   int                 index;
0114   rtems_id            task_id;
0115   rtems_task_priority priority;
0116 
0117   priority = RTEMS_MAXIMUM_PRIORITY - 2u;
0118 
0119   status = rtems_semaphore_create(
0120     rtems_build_name( 'S', 'M', '1', '\0'),
0121     0,
0122     SEMAPHORE_ATTRIBUTES,
0123     RTEMS_NO_PRIORITY,
0124     &Semaphore_id
0125   );
0126   directive_failed( status, "rtems_semaphore_create of SM1" );
0127 
0128   if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
0129     operation_count =  (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
0130   for ( index = 2 ; index < operation_count ; index ++ ) {
0131     rtems_task_create(
0132       rtems_build_name( 'M', 'I', 'D', ' ' ),
0133       priority,
0134       RTEMS_MINIMUM_STACK_SIZE,
0135       RTEMS_DEFAULT_MODES,
0136       RTEMS_DEFAULT_ATTRIBUTES,
0137       &task_id
0138     );
0139     directive_failed( status, "rtems_task_create middle" );
0140 
0141     priority--;
0142 
0143     rtems_task_start( task_id, Middle_tasks, 0 );
0144     directive_failed( status, "rtems_task_start middle" );
0145   }
0146 
0147   status = rtems_task_create(
0148     rtems_build_name( 'H', 'I', 'G', 'H' ),
0149     priority,
0150     RTEMS_MINIMUM_STACK_SIZE,
0151     RTEMS_DEFAULT_MODES,
0152     RTEMS_DEFAULT_ATTRIBUTES,
0153     &task_id
0154   );
0155   directive_failed( status, "rtems_task_create of high task" );
0156 
0157   status = rtems_task_start( task_id, High_task, 0 );
0158   directive_failed( status, "rtems_task_start of high task" );
0159 
0160   benchmark_timer_initialize();                          /* start the timer */
0161   status = rtems_semaphore_release( Semaphore_id );
0162 }
0163 
0164 rtems_task Middle_tasks(
0165   rtems_task_argument argument
0166 )
0167 {
0168   (void) rtems_semaphore_obtain(
0169     Semaphore_id,
0170     RTEMS_DEFAULT_OPTIONS,
0171     RTEMS_NO_TIMEOUT
0172   );
0173 
0174   (void) rtems_semaphore_release( Semaphore_id );
0175 }
0176 
0177 rtems_task High_task(
0178   rtems_task_argument argument
0179 )
0180 {
0181   (void) rtems_semaphore_obtain(
0182     Semaphore_id,
0183     RTEMS_DEFAULT_OPTIONS,
0184     RTEMS_NO_TIMEOUT
0185   );
0186 
0187   end_time = benchmark_timer_read();
0188 
0189   put_time(
0190     "rtems_semaphore_release: " ATTR_DESC " task readied preempts caller",
0191     end_time,
0192     operation_count - 1,
0193     0,
0194     0
0195   );
0196 
0197   TEST_END();
0198   rtems_test_exit( 0 );
0199 }