Home | History | Annotate | Download | only in sched_setscheduler
      1 /*
      2  *  This program is free software; you can redistribute it and/or modify
      3  *  it under the terms of the GNU General Public License version 2.
      4  *
      5  *  This program is distributed in the hope that it will be useful,
      6  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      7  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      8  *  GNU General Public License for more details.
      9  *
     10  *
     11  * Test that the policy and scheduling parameters remain unchanged when the
     12  * sched_ss_repl_period is not greater than or equal to the
     13  * sched_ss_init_budget member.
     14  *
     15  * Steps:
     16  *   1. Get the old policy and priority.
     17  *   2. Call sched_setscheduler with invalid args.
     18  *   3. Check that the policy and priority have not changed.
     19  *
     20  * @pt:SS
     21  */
     22 
     23 #include <errno.h>
     24 #include <sched.h>
     25 #include <stdio.h>
     26 #include <unistd.h>
     27 #include "posixtest.h"
     28 
     29 #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1)
     30 
     31 int main(void)
     32 {
     33 	int policy, result;
     34 	int old_priority, old_policy, new_policy;
     35 	struct sched_param param;
     36 
     37 	if (sched_getparam(getpid(), &param) != 0) {
     38 		perror("An error occurs when calling sched_getparam()");
     39 		return PTS_UNRESOLVED;
     40 	}
     41 	old_priority = param.sched_priority;
     42 
     43 	old_policy = sched_getscheduler(getpid());
     44 	if (old_policy == -1) {
     45 		perror("An error occurs when calling sched_getscheduler()");
     46 		return PTS_UNRESOLVED;
     47 	}
     48 
     49 	/* set a sched_ss_repl_period lower than the sched_ss_init_budget */
     50 	param.sched_ss_repl_period.tv_sec = 1;
     51 	param.sched_ss_repl_period.tv_nsec = 0;
     52 
     53 	param.sched_ss_init_budget.tv_sec = 2;
     54 	param.sched_ss_init_budget.tv_nsec = 0;
     55 
     56 	param.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
     57 
     58 	result = sched_setscheduler(0, SCHED_SPORADIC, &param);
     59 
     60 	if (sched_getparam(getpid(), &param) != 0) {
     61 		perror("An error occurs when calling sched_getparam()");
     62 		return PTS_UNRESOLVED;
     63 	}
     64 
     65 	new_policy = sched_getscheduler(getpid());
     66 	if (new_policy == -1) {
     67 		perror("An error occurs when calling sched_getscheduler()");
     68 		return PTS_UNRESOLVED;
     69 	}
     70 
     71 	if (old_policy == new_policy && old_priority == param.sched_priority) {
     72 		printf("Test PASSED\n");
     73 		return PTS_PASS;
     74 	}
     75 
     76 	if (param.sched_priority != old_priority) {
     77 		printf("The param has changed\n");
     78 	}
     79 	if (new_policy != old_policy) {
     80 		printf("The policy has changed\n");
     81 	}
     82 	return PTS_FAIL;
     83 
     84 }
     85 #else
     86 int main(void)
     87 {
     88 	printf("Does not support SS (SPORADIC SERVER)\n");
     89 	return PTS_UNSUPPORTED;
     90 }
     91 #endif
     92