[54e34e7] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * All rights assigned to U.S. Government, 1994. |
---|
| 5 | * |
---|
| 6 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 7 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 8 | * notice must appear in all copies of this file and its derivatives. |
---|
| 9 | * |
---|
| 10 | * $Id$ |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #define CONFIGURE_INIT |
---|
| 14 | #include "system.h" |
---|
| 15 | #include <errno.h> |
---|
| 16 | |
---|
| 17 | void print_schedparam( |
---|
| 18 | char *prefix, |
---|
| 19 | struct sched_param *schedparam |
---|
| 20 | ) |
---|
| 21 | { |
---|
| 22 | printf( "%ssched priority = %d\n", prefix, schedparam->sched_priority ); |
---|
| 23 | #if defined(_POSIX_SPORADIC_SERVER) |
---|
| 24 | printf( "%sss_low_priority = %d\n", prefix, schedparam->ss_low_priority ); |
---|
| 25 | printf( "%sss_replenish_period = (%ld, %ld)\n", prefix, |
---|
| 26 | schedparam->ss_replenish_period.tv_sec, |
---|
| 27 | schedparam->ss_replenish_period.tv_nsec ); |
---|
| 28 | printf( "%sss_initial_budget = (%ld, %ld)\n", prefix, |
---|
| 29 | schedparam->ss_initial_budget.tv_sec, |
---|
| 30 | schedparam->ss_initial_budget.tv_nsec ); |
---|
| 31 | #else |
---|
| 32 | printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" ); |
---|
| 33 | #endif |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void *POSIX_Init( |
---|
| 37 | void *argument |
---|
| 38 | ) |
---|
| 39 | { |
---|
| 40 | int status; |
---|
| 41 | pthread_attr_t attr; |
---|
| 42 | struct sched_param schedparam; |
---|
| 43 | |
---|
| 44 | puts( "\n\n*** POSIX TEST 12 ***" ); |
---|
| 45 | |
---|
| 46 | /* set the time of day, and print our buffer in multiple ways */ |
---|
| 47 | |
---|
| 48 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
| 49 | |
---|
| 50 | /* get id of this thread */ |
---|
| 51 | |
---|
| 52 | Init_id = pthread_self(); |
---|
| 53 | printf( "Init's ID is 0x%08x\n", Init_id ); |
---|
| 54 | |
---|
| 55 | /* invalid scheduling policy error */ |
---|
| 56 | |
---|
| 57 | puts( "Init: pthread_attr_init - SUCCESSFUL" ); |
---|
| 58 | status = pthread_attr_init( &attr ); |
---|
| 59 | assert( !status ); |
---|
| 60 | |
---|
[2ffcc2ed] | 61 | status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
| 62 | assert( !status ); |
---|
[54e34e7] | 63 | attr.schedpolicy = -1; |
---|
| 64 | |
---|
| 65 | puts( "Init: pthread_create - EINVAL (invalid scheduling policy)" ); |
---|
| 66 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
| 67 | assert( status == EINVAL ); |
---|
| 68 | |
---|
| 69 | /* replenish period < budget error */ |
---|
| 70 | |
---|
| 71 | puts( "Init: pthread_attr_init - SUCCESSFUL" ); |
---|
| 72 | status = pthread_attr_init( &attr ); |
---|
| 73 | assert( !status ); |
---|
| 74 | |
---|
| 75 | puts( "Init: set scheduling parameter attributes for sporadic server" ); |
---|
| 76 | status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC ); |
---|
| 77 | assert( !status ); |
---|
| 78 | |
---|
| 79 | schedparam.ss_replenish_period.tv_sec = 1; |
---|
| 80 | schedparam.ss_replenish_period.tv_nsec = 0; |
---|
| 81 | schedparam.ss_initial_budget.tv_sec = 2; |
---|
| 82 | schedparam.ss_initial_budget.tv_nsec = 0; |
---|
| 83 | |
---|
| 84 | schedparam.sched_priority = 200; |
---|
| 85 | schedparam.ss_low_priority = 100; |
---|
| 86 | |
---|
| 87 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
| 88 | assert( !status ); |
---|
| 89 | |
---|
[2ffcc2ed] | 90 | status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
---|
| 91 | assert( !status ); |
---|
| 92 | |
---|
[54e34e7] | 93 | puts( "Init: pthread_create - EINVAL (replenish < budget)" ); |
---|
| 94 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
| 95 | assert( status == EINVAL ); |
---|
| 96 | |
---|
| 97 | /* invalid ss_low_priority error */ |
---|
| 98 | |
---|
| 99 | schedparam.ss_replenish_period.tv_sec = 2; |
---|
| 100 | schedparam.ss_replenish_period.tv_nsec = 0; |
---|
| 101 | schedparam.ss_initial_budget.tv_sec = 1; |
---|
| 102 | schedparam.ss_initial_budget.tv_nsec = 0; |
---|
| 103 | |
---|
| 104 | schedparam.sched_priority = 200; |
---|
| 105 | schedparam.ss_low_priority = -1; |
---|
| 106 | |
---|
| 107 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
| 108 | assert( !status ); |
---|
| 109 | |
---|
| 110 | puts( "Init: pthread_create - EINVAL (invalid ss_low_priority)" ); |
---|
| 111 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
| 112 | assert( status == EINVAL ); |
---|
| 113 | |
---|
| 114 | /* create a thread as a sporadic server */ |
---|
| 115 | |
---|
| 116 | schedparam.ss_replenish_period.tv_sec = 2; |
---|
| 117 | schedparam.ss_replenish_period.tv_nsec = 0; |
---|
| 118 | schedparam.ss_initial_budget.tv_sec = 1; |
---|
| 119 | schedparam.ss_initial_budget.tv_nsec = 0; |
---|
| 120 | |
---|
| 121 | schedparam.sched_priority = 200; |
---|
| 122 | schedparam.ss_low_priority = 100; |
---|
| 123 | |
---|
| 124 | status = pthread_attr_setschedparam( &attr, &schedparam ); |
---|
| 125 | assert( !status ); |
---|
| 126 | |
---|
| 127 | puts( "Init: pthread_create - SUCCESSFUL" ); |
---|
| 128 | status = pthread_create( &Task_id, &attr, Task_1, NULL ); |
---|
| 129 | assert( !status ); |
---|
| 130 | |
---|
| 131 | status = pthread_join( Task_id, NULL ); |
---|
| 132 | assert( status ); |
---|
| 133 | |
---|
| 134 | /* switch to Task_1 */ |
---|
| 135 | |
---|
| 136 | puts( "*** END OF POSIX TEST 12 ***" ); |
---|
| 137 | exit( 0 ); |
---|
| 138 | |
---|
| 139 | return NULL; /* just so the compiler thinks we returned something */ |
---|
| 140 | } |
---|