Home | History | Annotate | Download | only in pthread_getschedparam
      1 /*
      2  * Copyright (c) 2004, Intel Corporation. All rights reserved.
      3  * This file is licensed under the GPL license.  For the full content
      4  * of this license, see the COPYING file at the top level of this
      5  * source tree.
      6  * adam.li (at) intel.com
      7  *
      8  * The pthread_getschedparam() function shall retrieve the scheduling
      9  * policy and scheduling parameters for the thread whose thread ID is
     10  * given by thread and shall store those values in
     11  * policy and param, respectively. The priority value returned from
     12  * pthread_getschedparam() shall be
     13  * the value specified by the most recent pthread_setschedparam(),
     14  * pthread_setschedprio(), or pthread_create() call affecting the
     15  * target thread. It shall not reflect any temporary adjustments to
     16  * its priority as a result of any priority inheritance or ceiling functions.
     17  *
     18  */
     19 
     20  /* Set the sched parameter with pthread_setschedparam then get */
     21 #include <pthread.h>
     22 #include <stdio.h>
     23 #include <stdlib.h>
     24 #include <string.h>
     25 #include "posixtest.h"
     26 
     27 #define ERR_MSG(f, rc)  printf("Failed: func %s rc: %s (%u)\n", \
     28 				f, strerror(rc), rc)
     29 
     30 void *thread_func(void)
     31 {
     32 	struct sched_param sparam;
     33 	int policy, priority, policy_1;
     34 	int rc;
     35 
     36 	policy = SCHED_FIFO;
     37 	priority = sched_get_priority_min(policy);
     38 	sparam.sched_priority = priority;
     39 
     40 	rc = pthread_setschedparam(pthread_self(), policy, &sparam);
     41 	if (rc) {
     42 		ERR_MSG("pthread_setschedparam()", rc);
     43 		exit(PTS_UNRESOLVED);
     44 	}
     45 	rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam);
     46 	if (rc != 0) {
     47 		ERR_MSG("pthread_getschedparam()", rc);
     48 		exit(PTS_FAIL);
     49 	}
     50 
     51 	if (policy_1 != policy) {
     52 		printf("Failed:  policys:  %u != %u\n", policy_1, policy);
     53 		exit(PTS_FAIL);
     54 	}
     55 
     56 	if (sparam.sched_priority != priority) {
     57 		printf("Failed:  priorities: %u != %u\n",
     58 		       sparam.sched_priority, priority);
     59 		exit(PTS_FAIL);
     60 	}
     61 
     62 	return NULL;
     63 }
     64 
     65 int main(void)
     66 {
     67 	pthread_t new_th;
     68 	int rc;
     69 
     70 	rc = pthread_create(&new_th, NULL, thread_func, NULL);
     71 	if (rc) {
     72 		ERR_MSG("pthread_create()", rc);
     73 		return PTS_UNRESOLVED;
     74 	}
     75 
     76 	pthread_join(new_th, NULL);
     77 	printf("Test PASSED\n");
     78 	return PTS_PASS;
     79 }
     80