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
     12  * the sched_ss_max_repl is not within the inclusive range [1,SS_REPL_MAX]
     13  *
     14  * Test with a sched_ss_max_repl value of 0.
     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 max_priority, old_priority, old_policy, new_policy;
     34 	struct sched_param param;
     35 
     36 	if (sched_getparam(getpid(), &param) == -1) {
     37 		perror("An error occurs when calling sched_getparam()");
     38 		return PTS_UNRESOLVED;
     39 	}
     40 	old_priority = param.sched_priority;
     41 
     42 	old_policy = sched_getscheduler(getpid());
     43 	if (old_policy == -1) {
     44 		perror("An error occurs when calling sched_getscheduler()");
     45 		return PTS_UNRESOLVED;
     46 	}
     47 
     48 	/* Make sure that param.sched_priority != old_priority */
     49 	max_priority = sched_get_priority_max(SCHED_SPORADIC);
     50 	param.sched_priority = (old_priority == max_priority) ?
     51 	    sched_get_priority_min(SCHED_SPORADIC) : max_priority;
     52 
     53 	param.sched_ss_max_repl = 0;
     54 
     55 	sched_setscheduler(0, SCHED_SPORADIC, &param);
     56 
     57 	if (sched_getparam(getpid(), &param) != 0) {
     58 		perror("An error occurs when calling sched_getparam()");
     59 		return PTS_UNRESOLVED;
     60 	}
     61 
     62 	new_policy = sched_getscheduler(getpid());
     63 	if (new_policy == -1) {
     64 		perror("An error occurs when calling sched_getscheduler()");
     65 		return PTS_UNRESOLVED;
     66 	}
     67 
     68 	if (old_policy == new_policy && old_priority == param.sched_priority) {
     69 		printf("Test PASSED\n");
     70 		return PTS_PASS;
     71 	}
     72 
     73 	if (param.sched_priority != old_priority) {
     74 		printf("The param has changed\n");
     75 		return PTS_FAIL;
     76 	}
     77 	if (new_policy != old_policy) {
     78 		printf("The policy has changed\n");
     79 		return PTS_FAIL;
     80 	}
     81 
     82 }
     83 #else
     84 int main(void)
     85 {
     86 	printf("Does not support SS (SPORADIC SERVER)\n");
     87 	return PTS_UNSUPPORTED;
     88 }
     89 #endif
     90