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(TM02)
0043 const char rtems_test_name[] = "TIME TEST 2";
0044 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO)
0045 #define ATTR_DESC "counting/FIFO"
0046 
0047 #elif defined(TM31)
0048 const char rtems_test_name[] = "TIME TEST 31";
0049 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY)
0050 #define ATTR_DESC "counting/priority"
0051 
0052 #elif defined(TM33)
0053 const char rtems_test_name[] = "TIME TEST 33";
0054 #define SEMAPHORE_ATTRIBUTES RTEMS_BINARY_SEMAPHORE
0055 #define ATTR_DESC "binary/FIFO"
0056 
0057 #elif defined(TM35)
0058 const char rtems_test_name[] = "TIME TEST 35";
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 rtems_id High_id;
0067 rtems_id Low_id;
0068 rtems_id Semaphore_id;
0069 
0070 rtems_task High_task(
0071   rtems_task_argument argument
0072 );
0073 
0074 rtems_task Middle_tasks(
0075   rtems_task_argument argument
0076 );
0077 
0078 rtems_task Low_task(
0079   rtems_task_argument argument
0080 );
0081 
0082 int operation_count = OPERATION_COUNT;
0083 
0084 void test_init(void);
0085 
0086 rtems_task Init(
0087   rtems_task_argument argument
0088 )
0089 {
0090   rtems_status_code status;
0091 
0092   Print_Warning();
0093 
0094   TEST_BEGIN();
0095 
0096   test_init();
0097 
0098   status = rtems_task_suspend( RTEMS_SELF );
0099   directive_failed( status, "rtems_task_suspend" );
0100 }
0101 
0102 void test_init(void)
0103 {
0104   rtems_status_code   status;
0105   int                 index;
0106   rtems_task_priority priority;
0107 
0108   priority = 2;
0109 
0110   status = rtems_task_create(
0111     rtems_build_name( 'H', 'I', 'G', 'H' ),
0112     priority,
0113     RTEMS_MINIMUM_STACK_SIZE,
0114     RTEMS_DEFAULT_MODES,
0115     RTEMS_DEFAULT_ATTRIBUTES,
0116     &High_id
0117   );
0118   directive_failed( status, "rtems_task_create of high task" );
0119 
0120   priority++;
0121 
0122   status = rtems_task_start( High_id, High_task, 0 );
0123   directive_failed( status, "rtems_task_start of high task" );
0124 
0125   if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
0126     operation_count = (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
0127   for ( index=2 ; index < operation_count ; index++ ) {
0128     status = rtems_task_create(
0129       rtems_build_name( 'M', 'I', 'D', ' ' ),
0130       priority,
0131       RTEMS_MINIMUM_STACK_SIZE,
0132       RTEMS_DEFAULT_MODES,
0133       RTEMS_DEFAULT_ATTRIBUTES,
0134       &Low_id
0135     );
0136     directive_failed( status, "rtems_task_create middle" );
0137 
0138     priority++;
0139 
0140     status = rtems_task_start( Low_id, Middle_tasks, 0 );
0141     directive_failed( status, "rtems_task_start middle" );
0142   }
0143 
0144   status = rtems_task_create(
0145     rtems_build_name( 'L', 'O', 'W', ' ' ),
0146     priority,
0147     RTEMS_MINIMUM_STACK_SIZE,
0148     RTEMS_DEFAULT_MODES,
0149     RTEMS_DEFAULT_ATTRIBUTES,
0150     &Low_id
0151   );
0152   directive_failed( status, "rtems_task_create low" );
0153 
0154   status = rtems_task_start( Low_id, Low_task, 0 );
0155   directive_failed( status, "rtems_task_start low" );
0156 
0157   status = rtems_semaphore_create(
0158     rtems_build_name( 'S', 'M', '1', ' '),
0159     0,
0160     SEMAPHORE_ATTRIBUTES,
0161     RTEMS_NO_PRIORITY,
0162     &Semaphore_id
0163   );
0164   directive_failed( status, "rtems_semaphore_create of SM1" );
0165 }
0166 
0167 rtems_task High_task(
0168   rtems_task_argument argument
0169 )
0170 {
0171   /* start blocking rtems_semaphore_obtain time */
0172   benchmark_timer_initialize();
0173 
0174   (void) rtems_semaphore_obtain(
0175     Semaphore_id,
0176     RTEMS_DEFAULT_OPTIONS,
0177     RTEMS_NO_TIMEOUT
0178   );
0179 }
0180 
0181 rtems_task Middle_tasks(
0182   rtems_task_argument argument
0183 )
0184 {
0185   (void) rtems_semaphore_obtain(
0186     Semaphore_id,
0187     RTEMS_DEFAULT_OPTIONS,
0188     RTEMS_NO_TIMEOUT
0189   );
0190 }
0191 
0192 rtems_task Low_task(
0193   rtems_task_argument argument
0194 )
0195 {
0196   end_time = benchmark_timer_read();
0197 
0198   put_time(
0199     "rtems_semaphore_obtain: " ATTR_DESC " not available caller blocks",
0200     end_time,
0201     operation_count - 1,
0202     0,
0203     0
0204   );
0205 
0206   TEST_END();
0207   rtems_test_exit( 0 );
0208 }