Home | History | Annotate | Download | only in speculative
      1 /*
      2  * Copyright (c) 2004, QUALCOMM Inc. All rights reserved.
      3  * Created by:  abisain REMOVE-THIS AT qualcomm 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  * pthread_attr_setschedparam()
      9 
     10  * 1. Create a pthread_attr object and initialize it
     11  * 2. Set the policy and an invalid priority in that object
     12 
     13  */
     14 
     15 #include <pthread.h>
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <errno.h>
     19 #include "posixtest.h"
     20 
     21 #define TEST "3-1"
     22 #define FUNCTION "pthread_attr_setschedparam"
     23 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
     24 
     25 #define FIFOPOLICY SCHED_FIFO
     26 #define PRIORITY_OFFSET 1000
     27 
     28 int main(void)
     29 {
     30 	pthread_attr_t attr;
     31 	int rc = 0;
     32 	int policy = FIFOPOLICY;
     33 	struct sched_param param;
     34 	int priority;
     35 
     36 	rc = pthread_attr_init(&attr);
     37 	if (rc != 0) {
     38 		printf(ERROR_PREFIX "pthread_attr_init\n");
     39 		exit(PTS_UNRESOLVED);
     40 	}
     41 
     42 	rc = pthread_attr_setschedpolicy(&attr, policy);
     43 	if (rc != 0) {
     44 		printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n");
     45 		exit(PTS_FAIL);
     46 	}
     47 
     48 	priority = sched_get_priority_max(policy);
     49 	if (priority == -1) {
     50 		printf(ERROR_PREFIX "sched_priority_get_max\n");
     51 		exit(PTS_FAIL);
     52 	}
     53 
     54 	param.sched_priority = priority + PRIORITY_OFFSET;
     55 	rc = pthread_attr_setschedparam(&attr, &param);
     56 	if ((rc != EINVAL) && (rc != ENOTSUP)) {
     57 		printf(ERROR_PREFIX
     58 		       "pthread_attr_setschedparam did not fail\n");
     59 		exit(PTS_FAIL);
     60 	}
     61 
     62 	printf("Test PASSED\n");
     63 	exit(PTS_PASS);
     64 }
     65