Hi!
As pointed out by Cheng Shun Xia <[email protected]> the
pthread_mutex_getprioceiling() works only on mutexes initalized with
PTHREAD_PRIO_PROTECT. Also calling perror() after pthread_* fuctions is
meaningless as they return error number directly, this is common mistake
in pthread tests in openposix testsuite and should go to the ltp TODO.
Patch attached.
Signed-off-by: Cyril Hrubis [email protected]
--
Cyril Hrubis
[email protected]
Index: ltp-dev-local/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/1-1.c
===================================================================
--- ltp-dev-local.orig/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/1-1.c
+++ ltp-dev-local/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/1-1.c
@@ -18,42 +18,55 @@
#include <pthread.h>
#include <stdio.h>
#include <sched.h>
+#include <string.h>
#include "posixtest.h"
-int main()
+static void print_error(const char *msg, int ret)
{
-
- /* Make sure there is prioceiling capability. */
- /* #ifndef _POSIX_PRIORITY_SCHEDULING
- fprintf(stderr,"prioceiling attribute is not available for testing\n");
- return PTS_UNRESOLVED;
- #endif */
+ fprintf(stderr, "Errror at %s(): %s\n", msg, strerror(ret));
+}
+int main(void)
+{
+ pthread_mutexattr_t ma;
pthread_mutex_t mutex;
- int prioceiling, max_prio, min_prio;
-
+ int prioceiling, max_prio, min_prio, ret;
+
+ /* Initalize mutex attribut */
+ if ((ret = pthread_mutexattr_init(&ma)) != 0) {
+ print_error("pthread_mutexattr_init", ret);
+ return PTS_UNRESOLVED;
+ }
+
+ /* Initalize mutex protocol */
+ ret = pthread_mutexattr_setprotocol(&ma, PTHREAD_PRIO_PROTECT);
+ if (ret != 0) {
+ print_error("pthread_mutexattr_setprotocol", ret);
+ return PTS_UNRESOLVED;
+ }
+
/* Initialize a mutex object */
- if(pthread_mutex_init(&mutex, NULL) != 0)
- {
- perror("Error at pthread_mutex_init()\n");
+ if ((ret = pthread_mutex_init(&mutex, &ma)) != 0) {
+ print_error("pthread_mutex_init", ret);
return PTS_UNRESOLVED;
}
-
- /* Get the prioceiling of the mutex. */
- if(pthread_mutex_getprioceiling(&mutex, &prioceiling) != 0)
- {
- printf("Test FAILED: Error obtaining the priority ceiling\n");
+
+ /* Get the prioceiling of the mutex */
+ if ((ret = pthread_mutex_getprioceiling(&mutex, &prioceiling)) != 0) {
+ fprintf(stderr, "Test FAILED: Error obtaining the priority"
+ "ceiling: %s\n", strerror(ret));
return PTS_FAIL;
}
-
- /* Get the max and min prio according to SCHED_FIFO (posix scheduling policy) */
+
+ /* Get the max and min according to SCHED_FIFO */
max_prio = sched_get_priority_max(SCHED_FIFO);
min_prio = sched_get_priority_min(SCHED_FIFO);
- /* Make sure that prioceiling is withing the legal SCHED_FIFO boundries. */
- if((prioceiling < min_prio) || (prioceiling > max_prio))
- {
- printf("Test FAILED: Default prioceiling %d is not compliant with SCHED_FIFO boundry. \n", prioceiling);
+ /* Make sure that prioceiling is in the legal SCHED_FIFO boundries */
+ if ((prioceiling < min_prio) || (prioceiling > max_prio)) {
+ fprintf(stderr, "Test FAILED: Default prioceiling %d is not "
+ "compliant with SCHED_FIFO boundry.\n",
+ prioceiling);
return PTS_FAIL;
}
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list