2016-03-15 11:38:17 +03:00
# include "tests.h"
2016-08-09 17:38:29 +03:00
# include <asm/unistd.h>
2016-03-15 11:38:17 +03:00
# if defined __NR_sched_getscheduler && defined __NR_sched_setscheduler
# include <sched.h>
# include <stdio.h>
# include <unistd.h>
int
main ( void )
{
struct sched_param * const param = tail_alloc ( sizeof ( struct sched_param ) ) ;
2016-04-22 00:18:14 +03:00
long rc = syscall ( __NR_sched_getscheduler , 0 ) ;
2016-03-15 11:38:17 +03:00
const char * scheduler ;
switch ( rc ) {
case SCHED_FIFO :
scheduler = " SCHED_FIFO " ;
break ;
case SCHED_RR :
scheduler = " SCHED_RR " ;
break ;
# ifdef SCHED_BATCH
case SCHED_BATCH :
scheduler = " SCHED_BATCH " ;
break ;
# endif
# ifdef SCHED_IDLE
case SCHED_IDLE :
scheduler = " SCHED_IDLE " ;
break ;
# endif
# ifdef SCHED_ISO
case SCHED_ISO :
scheduler = " SCHED_ISO " ;
break ;
# endif
# ifdef SCHED_DEADLINE
case SCHED_DEADLINE :
scheduler = " SCHED_DEADLINE " ;
break ;
# endif
default :
scheduler = " SCHED_OTHER " ;
}
2016-04-22 00:18:14 +03:00
printf ( " sched_getscheduler(0) = %ld (%s) \n " ,
2016-03-15 11:38:17 +03:00
rc , scheduler ) ;
2016-09-05 04:31:35 +03:00
rc = syscall ( __NR_sched_getscheduler , - 1 ) ;
printf ( " sched_getscheduler(-1) = %s \n " , sprintrc ( rc ) ) ;
2016-03-15 11:38:17 +03:00
param - > sched_priority = - 1 ;
2016-09-05 04:31:35 +03:00
rc = syscall ( __NR_sched_setscheduler , 0 , SCHED_FIFO , NULL ) ;
printf ( " sched_setscheduler(0, SCHED_FIFO, NULL) = %s \n " , sprintrc ( rc ) ) ;
rc = syscall ( __NR_sched_setscheduler , 0 , SCHED_FIFO , param + 1 ) ;
printf ( " sched_setscheduler(0, SCHED_FIFO, %p) = %s \n " , param + 1 ,
sprintrc ( rc ) ) ;
rc = syscall ( __NR_sched_setscheduler , 0 , 0xfaceda7a , param ) ;
printf ( " sched_setscheduler(0, %#x /* SCHED_??? */, [%d]) = %s \n " ,
0xfaceda7a , param - > sched_priority , sprintrc ( rc ) ) ;
rc = syscall ( __NR_sched_setscheduler , - 1 , SCHED_FIFO , param ) ;
printf ( " sched_setscheduler(-1, SCHED_FIFO, [%d]) = %s \n " ,
param - > sched_priority , sprintrc ( rc ) ) ;
2016-03-15 11:38:17 +03:00
rc = syscall ( __NR_sched_setscheduler , 0 , SCHED_FIFO , param ) ;
2016-09-05 04:33:16 +03:00
printf ( " sched_setscheduler(0, SCHED_FIFO, [%d]) = %s \n " ,
param - > sched_priority , sprintrc ( rc ) ) ;
2016-03-15 11:38:17 +03:00
puts ( " +++ exited with 0 +++ " ) ;
return 0 ;
}
# else
SKIP_MAIN_UNDEFINED ( " __NR_sched_getscheduler && __NR_sched_setscheduler " )
# endif