Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009.
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 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <sched.h>
0034 
0035 #define CONFIGURE_INIT
0036 #include "system.h"
0037 #include <errno.h>
0038 
0039 const char rtems_test_name[] = "PSX 11";
0040 
0041 void *POSIX_Init(
0042   void *argument
0043 )
0044 {
0045   int                  status;
0046   struct sched_param   param;
0047   pthread_attr_t       attr;
0048   int                  priority_1;
0049   int                  priority_2;
0050   int                  priority_3;
0051   int                  priority_4;
0052 
0053   TEST_BEGIN();
0054 
0055   /* set the time of day, and print our buffer in multiple ways */
0056 
0057   set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
0058 
0059   /* get id of this thread */
0060 
0061   Init_id = pthread_self();
0062   printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
0063 
0064   /* exercise pthread_setschedparam */
0065 
0066   priority_1 = sched_get_priority_max( SCHED_FIFO );      /* was 127 */
0067   priority_2 = sched_get_priority_max( SCHED_FIFO ) - 2;  /* was 125 */
0068   priority_3 = sched_get_priority_max( SCHED_FIFO ) - 6;  /* was 121 */
0069   priority_4 = sched_get_priority_max( SCHED_FIFO ) - 7;  /* was 120 */
0070 
0071   param.sched_priority = priority_1;
0072 
0073   printf(
0074     "Init: Setting scheduling parameters to FIFO with priority %d\n",
0075     priority_1
0076   );
0077   status = pthread_setschedparam( Init_id, SCHED_FIFO, &param );
0078   rtems_test_assert( !status );
0079 
0080   param.sched_priority = priority_2;
0081 
0082   printf(
0083     "Init: Setting scheduling parameters to RR with priority %d\n",
0084     priority_2
0085   );
0086   status = pthread_setschedparam( Init_id, SCHED_RR, &param );
0087   rtems_test_assert( !status );
0088 
0089   param.sched_priority = priority_3;
0090 
0091   printf(
0092     "Init: Setting scheduling parameters to OTHER with priority %d\n",
0093     priority_3
0094   );
0095   status = pthread_setschedparam( Init_id, SCHED_OTHER, &param );
0096   rtems_test_assert( !status );
0097 
0098   /* create a thread as SCHED_FIFO */
0099 
0100   printf(
0101     "Init: create a thread of SCHED_FIFO with priority %d\n", priority_4 );
0102   status = pthread_attr_init( &attr );
0103   rtems_test_assert( !status );
0104 
0105   attr.schedpolicy = SCHED_FIFO;
0106   attr.schedparam.sched_priority = priority_4;
0107 
0108   status = pthread_create( &Task_id, &attr, Task_1, NULL );
0109   rtems_test_assert( !status );
0110 
0111   puts( "Init: join with the other thread" );
0112   status = pthread_join( Task_id, NULL );
0113   rtems_test_assert( !status );
0114 
0115   /* create a thread as SCHED_RR */
0116 
0117   printf( "Init: create a thread of SCHED_RR with priority %d\n", priority_4 );
0118   status = pthread_attr_init( &attr );
0119   rtems_test_assert( !status );
0120 
0121   status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
0122   rtems_test_assert( !status );
0123   attr.schedpolicy = SCHED_RR;
0124   attr.schedparam.sched_priority = priority_4;
0125 
0126   status = pthread_create( &Task_id, &attr, Task_1, NULL );
0127   rtems_test_assert( !status );
0128 
0129   puts( "Init: join with the other thread" );
0130   status = pthread_join( Task_id, NULL );
0131   rtems_test_assert( !status );
0132 
0133   /* create a thread as SCHED_OTHER */
0134 
0135   printf(
0136     "Init: create a thread of SCHED_OTHER with priority %d\n", priority_4 );
0137   status = pthread_attr_init( &attr );
0138   rtems_test_assert( !status );
0139 
0140   attr.schedpolicy = SCHED_OTHER;
0141   attr.schedparam.sched_priority = priority_4;
0142 
0143   status = pthread_create( &Task_id, &attr, Task_1, NULL );
0144   rtems_test_assert( !status );
0145 
0146   puts( "Init: join with the other thread" );
0147   status = pthread_join( Task_id, NULL );
0148   rtems_test_assert( !status );
0149 
0150   TEST_END();
0151   rtems_test_exit( 0 );
0152 
0153   return NULL; /* just so the compiler thinks we returned something */
0154 }