12c28215423293e443469a07ae7011135d058b671Garrett Cooper/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license. For the full content 52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree. 70dc076565f772bb1953209fb69ea150b494aaa40robbiew 80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that pthread_mutexattr_getprioceiling() 90dc076565f772bb1953209fb69ea150b494aaa40robbiew * 100dc076565f772bb1953209fb69ea150b494aaa40robbiew * Gets the priority ceiling attribute of a mutexattr object (which was prev. created 110dc076565f772bb1953209fb69ea150b494aaa40robbiew * by the function pthread_mutexattr_init()). 120dc076565f772bb1953209fb69ea150b494aaa40robbiew * 130dc076565f772bb1953209fb69ea150b494aaa40robbiew * Steps: 140dc076565f772bb1953209fb69ea150b494aaa40robbiew * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() 150dc076565f772bb1953209fb69ea150b494aaa40robbiew * 2. Get the min and max boundries for SCHED_FIFO of what prioceiling can be. 160dc076565f772bb1953209fb69ea150b494aaa40robbiew * 3. In a for loop, go through each valid SCHED_FIFO value, set the prioceiling, then 170dc076565f772bb1953209fb69ea150b494aaa40robbiew * get the prio ceiling. These should always be the same. If not, fail the test. 182c28215423293e443469a07ae7011135d058b671Garrett Cooper * 190dc076565f772bb1953209fb69ea150b494aaa40robbiew */ 200dc076565f772bb1953209fb69ea150b494aaa40robbiew 210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h> 220dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 230dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sched.h> 240dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 250dc076565f772bb1953209fb69ea150b494aaa40robbiew 264ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void) 270dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 282c28215423293e443469a07ae7011135d058b671Garrett Cooper 292c28215423293e443469a07ae7011135d058b671Garrett Cooper /* Make sure there is prioceiling capability. */ 300dc076565f772bb1953209fb69ea150b494aaa40robbiew /* #ifndef _POSIX_PRIORITY_SCHEDULING 31354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr,"prioceiling attribute is not available for testing\n"); 32354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao return PTS_UNRESOLVED; 33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao #endif */ 340dc076565f772bb1953209fb69ea150b494aaa40robbiew 350dc076565f772bb1953209fb69ea150b494aaa40robbiew pthread_mutexattr_t mta; 360dc076565f772bb1953209fb69ea150b494aaa40robbiew int prioceiling, max_prio, min_prio, i; 372c28215423293e443469a07ae7011135d058b671Garrett Cooper 380dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Initialize a mutex attributes object */ 39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (pthread_mutexattr_init(&mta) != 0) { 400dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Error at pthread_mutexattr_init()\n"); 410dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 420dc076565f772bb1953209fb69ea150b494aaa40robbiew } 430dc076565f772bb1953209fb69ea150b494aaa40robbiew 440dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Get the max and min prio according to SCHED_FIFO (posix scheduling policy) */ 450dc076565f772bb1953209fb69ea150b494aaa40robbiew max_prio = sched_get_priority_max(SCHED_FIFO); 460dc076565f772bb1953209fb69ea150b494aaa40robbiew min_prio = sched_get_priority_min(SCHED_FIFO); 470dc076565f772bb1953209fb69ea150b494aaa40robbiew 48354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao for (i = min_prio; (i < max_prio + 1); i++) { 492c28215423293e443469a07ae7011135d058b671Garrett Cooper /* Set the prioceiling to a priority number in the boundries 500dc076565f772bb1953209fb69ea150b494aaa40robbiew * of SCHED_FIFO policy */ 51354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (pthread_mutexattr_setprioceiling(&mta, i)) { 520dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Error setting prioceiling to %d\n", i); 530dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 540dc076565f772bb1953209fb69ea150b494aaa40robbiew } 550dc076565f772bb1953209fb69ea150b494aaa40robbiew 560dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Get the prioceiling mutex attr. */ 57354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (pthread_mutexattr_getprioceiling(&mta, &prioceiling) != 0) { 58354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao fprintf(stderr, 59354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao "Error obtaining the attribute process-shared\n"); 600dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 610dc076565f772bb1953209fb69ea150b494aaa40robbiew } 622c28215423293e443469a07ae7011135d058b671Garrett Cooper 630dc076565f772bb1953209fb69ea150b494aaa40robbiew /* Make sure that prioceiling is withing the legal SCHED_FIFO boundries. */ 64354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (prioceiling != i) { 65354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao printf 66354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao ("Test FAILED: Set prioceiling and get prioceiling did not match.\n"); 670dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 680dc076565f772bb1953209fb69ea150b494aaa40robbiew } 690dc076565f772bb1953209fb69ea150b494aaa40robbiew } 700dc076565f772bb1953209fb69ea150b494aaa40robbiew 710dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED\n"); 720dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 73ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 74