fix pthread_mutex_getprioceiling testcase
PATCH 1/1 fix pthread_mutex_getprioceiling testcase
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.
Signature · 2 lines
Cyril Hrubis [email protected]
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/1-1.c +36 -23
@@ -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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 4 lines
2. So you're saying that none of the pthread(5) functions provide useful diagnostics, even though the manpages claim they should (in many cases)? That seems like a bug with the pthreads implementation to me...
Not at all, as far as I understand this they just return error as integer value from function to indicate the error, most likely due to problems with errno and race conditions as program runs in more threads, so they are not touching errno that is later picked up by perror() call. So you would get:
"pthread_xxx_xxx() failed: Success"
or any previous errno that was there instead of:
"pthread_xxx_xxx() failed: Invalid value"
I'm just saying that you should not use perror() for pthread functions but rather use value returned from such function.
Signature · 11 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
2. So you're saying that none of the pthread(5) functions provide useful diagnostics, even though the manpages claim they should (in many cases)? That seems like a bug with the pthreads implementation to me...
Not at all, as far as I understand this they just return error as integer value from function to indicate the error, most likely due to problems with errno and race conditions as program runs in more threads, so they are not touching errno that is later picked up by
perror()call. So you would get:"
pthread_xxx_xxx()failed: Success"or any previous errno that was there instead of:
Quoted 7 lines
Quoted 4 lines
"
pthread_xxx_xxx()failed: Invalid value"I'm just saying that you should not use
perror()for pthread functions but rather use value returned from such function.Good point. We probably should save the errno, then quickly print
out the resulting error.
That's what print_error() function in that patch does. ;)
Signature · 11 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 6 lines
I just now noticed the
PTHREAD_PRIO_PROTECTportion of the patch.
The testcase passes now (I can vouch for it passing on FreeBSD), but none of the POSIX specs I read mention anything about this being a hard requirement. So something needs to be figured out as far as whether or not the specs are broken, or this an issue with the pthreads implementation on both FreeBSD and Linux.
Yes, I was unable to find this in the posix too. I consulted our glibc maintainer and all I've got was "it doesn't work without PTHREAD_PRIO_PROTECT". And even free pages from O'Reilly "A POSIX Standart for Better Mutiprocessing" seems to suggest that. I'll try to get that book as it seems to be only source of documentation for realtime threads I know about. Anyway it does make sense to return priority only for mutexes that can be prioritized.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://ad.doubleclick.net/clk;226879339;13503038;l? http://clk.atdmt.com/CRS/go/247765532/direct/01/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
I just now noticed the
PTHREAD_PRIO_PROTECTportion of the patch. The testcase passes now (I can vouch for it passing on FreeBSD), but none of the POSIX specs I read mention anything about this being a hard requirement. So something needs to be figured out as far as whether or not the specs are broken, or this an issue with the pthreads implementation on both FreeBSD and Linux.Quoted 7 lines
Yes, I was unable to find this in the posix too. I consulted our glibc maintainer and all I've got was "it doesn't work without
PTHREAD_PRIO_PROTECT". And even free pages from O'Reilly "A POSIX Standart for Better Mutiprocessing" seems to suggest that. I'll try to get that book as it seems to be only source of documentation for realtime threads I know about. Anyway it does make sense to return priority only for mutexes that can be prioritized.
Quoted 2 lines
I just committed a slightly modified version of your III patch.
I'll have to chase down the POSIX people about this discrepancy...
Okay ;).
Still there are other pthread tests to fix. May be we sould make the function print_pthread_error() library call so that it could be used from other openposix pthread tests.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://ad.doubleclick.net/clk;226879339;13503038;l? http://clk.atdmt.com/CRS/go/247765532/direct/01/ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 8 lines
Quoted 5 lines
As pointed out by Cheng Shun Xia <[email protected]> the
pthread_mutex_getprioceiling()works only on mutexes initalized withPTHREAD_PRIO_PROTECT. Also callingperror()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.1. There are typos in the proposed change (s/Errror/Error/, s/boundry/boundary/).
Should be fixed in attached patch.
Signature · 2 lines
Cyril Hrubis [email protected]
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/1-1.c +38 -25
@@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content
@@ -9,7 +9,7 @@* * returns the current prioceiling of the mutex. * -* Steps:i +* Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutex_getprioceiling() to obtain the prioceiling. *
@@ -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 *fname,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,"Error at %s(): %s\n" , fname,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 accordingly 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 boundaries */ +if ((prioceiling < min_prio) || (prioceiling > max_prio)) { +fprintf (stderr,"Test FAILED: Default prioceiling %d is not " +"compliant with SCHED_FIFO boundary.\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