Home | History | Annotate | Download | only in pthread_attr_setschedpolicy
      1 /*
      2  * Copyright (c) 2004, Intel Corporation. All rights reserved.
      3  * Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7  *
      8  *
      9  * Re-written by Peter W. Morreale <pmorreale AT novell DOT com>
     10  * 24/05/2011
     11  *
     12  * Test pthread_attr_setschedpolicy()
     13  *
     14  * Steps:
     15  * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
     16  * 2.  Test pthread_attr_setschedpolicy for all required supported policies
     17  *
     18  */
     19 
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include <stdlib.h>
     23 #include <string.h>
     24 #include <errno.h>
     25 #include "posixtest.h"
     26 
     27 #define ERR_MSG(p, f, rc) printf("Failed: %s function: %s error: %s (%u)\n", \
     28 						p, f, strerror(rc), rc)
     29 
     30 int set_policy(char *label, int policy)
     31 {
     32 	int rc;
     33 	int status;
     34 	pthread_attr_t attr;
     35 
     36 	rc = pthread_attr_init(&attr);
     37 	if (rc) {
     38 		ERR_MSG("", "pthread_attr_init()", rc);
     39 		return PTS_UNRESOLVED;
     40 	}
     41 
     42 	status = PTS_PASS;
     43 	rc = pthread_attr_setschedpolicy(&attr, policy);
     44 	if (rc) {
     45 		ERR_MSG(label, "pthread_attr_setschedpolicy()", rc);
     46 		status = PTS_FAIL;
     47 	}
     48 
     49 	(void)pthread_attr_destroy(&attr);
     50 
     51 	return status;
     52 }
     53 
     54 int main(void)
     55 {
     56 	int rc;
     57 
     58 	rc = set_policy("SCHED_FIFO", SCHED_FIFO);
     59 	if (rc)
     60 		goto done;
     61 
     62 	rc = set_policy("SCHED_RR", SCHED_RR);
     63 	if (rc)
     64 		goto done;
     65 
     66 	rc = set_policy("SCHED_OTHER", SCHED_OTHER);
     67 	if (rc)
     68 		goto done;
     69 
     70 	printf("Test PASSED\n");
     71 
     72 done:
     73 	return rc;
     74 }
     75