From: DAN LI <li...@cn...> - 2013-03-04 09:50:10
|
1.Make log style keep consistent with other cases in the same directory. 2.Add error checks to strengthen the robustness of this case. Signed-off-by: DAN LI <li...@cn...> --- .../conformance/interfaces/pthread_once/1-1.c | 70 +++++++++++++++++++--- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..03b2875 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c @@ -21,9 +21,53 @@ * passed to it. If it does, the test fails. */ +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + +/******************************************************************************/ +/****************************** standard includes *****************************/ +/******************************************************************************/ #include <pthread.h> #include <stdio.h> -#include "posixtest.h" +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/******************************************************************************/ +/****************************** Test framework ****************************/ +/******************************************************************************/ +#include "../testfrmw/testfrmw.h" +#include "../testfrmw/testfrmw.c" +/* This header is responsible for defining the following macros: + * UNRESOLVED(ret, descr); + * where descr is a description of the error and ret is an int + * (error code for example) + * FAILED(descr); + * where descr is a short text saying why the test has failed. + * PASSED(); + * No parameter. + * + * Both three macros shall terminate the calling process. + * The testcase shall not terminate in any other maneer. + * + * The other file defines the functions + * void output_init() + * void output(char * string, ...) + * + * Those may be used to output information. + */ + +/******************************************************************************/ +/******************************** Configuration *******************************/ +/******************************************************************************/ +#ifndef VERBOSE +#define VERBOSE 1 +#endif + +/******************************************************************************/ +/******************************* Test case *******************************/ +/******************************************************************************/ + /* Keeps track of how many times the init function has been called. */ int init_flag; @@ -37,23 +81,31 @@ void *an_init_func() int main() { + int ret = 0; + pthread_once_t once_control = PTHREAD_ONCE_INIT; init_flag = 0; + output_init(); + /* Call pthread_once, passing it the once_control */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) + UNRESOLVED(ret, "pthread_once failed"); /* Call pthread_once again. The init function should not be * called. */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) + UNRESOLVED(ret, "pthread_once failed"); - if (init_flag != 1) { - printf("Test FAILED\n"); - return PTS_FAIL; - } + if (init_flag != 1) + FAILED("an_init_func runs two times\n"); - printf("Test PASSED\n"); - return PTS_PASS; +#if VERBOSE > 0 + output("TEST PASSED\n"); +#endif + PASSED; } -- 1.7.12 |
From: <ch...@su...> - 2013-03-05 10:03:47
|
Hi! > 1.Make log style keep consistent with other cases in the same directory. > 2.Add error checks to strengthen the robustness of this case. Any patches that adds useless comments and/or testfrmw are no-go. Sorry. -- Cyril Hrubis ch...@su... |
From: DAN LI <li...@cn...> - 2013-03-05 10:46:23
|
1.Add error checks to: Make sure this case not slip into one situation that the first pthread_once fails, and the second successes, then the case passes with bypassing its assertion. Give more detailed and exact execute result. 2.Replace "posixtest.h" with "testfrmw.h" as the log frame to keep consistent with other cases in the same directory. Signed-off-by: DAN LI <li...@cn...> --- .../conformance/interfaces/pthread_once/1-1.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..c7ae170 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c @@ -21,9 +21,17 @@ * passed to it. If it does, the test fails. */ +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + #include <pthread.h> #include <stdio.h> -#include "posixtest.h" +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "../testfrmw/testfrmw.h" +#include "../testfrmw/testfrmw.c" /* Keeps track of how many times the init function has been called. */ int init_flag; @@ -37,23 +45,29 @@ void *an_init_func() int main() { + int ret = 0; + pthread_once_t once_control = PTHREAD_ONCE_INIT; init_flag = 0; + output_init(); + /* Call pthread_once, passing it the once_control */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) + UNRESOLVED(ret, "pthread_once failed"); /* Call pthread_once again. The init function should not be * called. */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) + UNRESOLVED(ret, "pthread_once failed"); - if (init_flag != 1) { - printf("Test FAILED\n"); - return PTS_FAIL; - } + if (init_flag != 1) + FAILED("an_init_func runs two times\n"); - printf("Test PASSED\n"); - return PTS_PASS; + output("TEST PASSED\n"); + PASSED; } -- 1.7.12 |
From: <ch...@su...> - 2013-03-05 15:03:52
|
Hi! > 2.Replace "posixtest.h" with "testfrmw.h" as the log frame > to keep consistent with other cases in the same directory. The testfrmw is being actively removed, please don't add it. -- Cyril Hrubis ch...@su... |
From: DAN LI <li...@cn...> - 2013-03-06 01:57:11
|
On 03/05/2013 11:04 PM, ch...@su... wrote: > Hi! >> 2.Replace "posixtest.h" with "testfrmw.h" as the log frame >> to keep consistent with other cases in the same directory. > > The testfrmw is being actively removed, please don't add it. > Oh... Thank you for reviewing and sorry for missing this point twice. I will send V3. |
From: DAN LI <li...@cn...> - 2013-03-06 02:33:04
|
Add error checks to: Make sure this case not slip into one situation that the first pthread_once fails, and the second successes, then the case passes with bypassing its assertion. Give more detailed and exact execute result. Signed-off-by: DAN LI <li...@cn...> --- .../conformance/interfaces/pthread_once/1-1.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..3392e6b 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c @@ -26,7 +26,7 @@ #include "posixtest.h" /* Keeps track of how many times the init function has been called. */ -int init_flag; +static int init_flag; /* The init function that pthread_once calls */ void *an_init_func() @@ -37,16 +37,25 @@ void *an_init_func() int main() { + int ret; + pthread_once_t once_control = PTHREAD_ONCE_INIT; init_flag = 0; /* Call pthread_once, passing it the once_control */ - pthread_once(&once_control, (void *)an_init_func); - + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) { + printf("pthread_once failed\n"); + return PTS_UNRESOLVED; + } /* Call pthread_once again. The init function should not be * called. */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, (void *)an_init_func); + if (ret != 0) { + printf("pthread_once failed\n"); + return PTS_UNRESOLVED; + } if (init_flag != 1) { printf("Test FAILED\n"); -- 1.7.12 |
From: <ch...@su...> - 2013-03-06 13:04:08
|
Hi! > Add error checks to: > > Make sure this case not slip into one situation that > the first pthread_once fails, and the second successes, > then the case passes with bypassing its assertion. > > Give more detailed and exact execute result. Out of curiosity, have you seen the situation where the pthread_once() has failed, or is this fix for a hypotetical condition (which is not wrong at all)? > Signed-off-by: DAN LI <li...@cn...> > --- > .../conformance/interfaces/pthread_once/1-1.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c > b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c > index 3a7c861..3392e6b 100644 > --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c > +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c > @@ -26,7 +26,7 @@ > #include "posixtest.h" > > /* Keeps track of how many times the init function has been called. */ > -int init_flag; > +static int init_flag; > > /* The init function that pthread_once calls */ > void *an_init_func() > @@ -37,16 +37,25 @@ void *an_init_func() > > int main() > { > + int ret; > + > pthread_once_t once_control = PTHREAD_ONCE_INIT; > > init_flag = 0; > > /* Call pthread_once, passing it the once_control */ > - pthread_once(&once_control, (void *)an_init_func); > - > + ret = pthread_once(&once_control, (void *)an_init_func); Hmm, I think that we can get rid the cast to the (void *) here. My gues is that the function has wrong prototype which generates warning here. Accordingly to manual page it should be void (*init_routine)(void). So the correct prototype should be void an_init_func(void). Could you please fix the prototype and remove the (void *) casts as well? > + if (ret != 0) { > + printf("pthread_once failed\n"); > + return PTS_UNRESOLVED; > + } > /* Call pthread_once again. The init function should not be > * called. */ > - pthread_once(&once_control, (void *)an_init_func); > + ret = pthread_once(&once_control, (void *)an_init_func); > + if (ret != 0) { > + printf("pthread_once failed\n"); > + return PTS_UNRESOLVED; > + } > > if (init_flag != 1) { > printf("Test FAILED\n"); -- Cyril Hrubis ch...@su... |
From: DAN LI <li...@cn...> - 2013-03-07 03:20:57
|
On 03/06/2013 09:04 PM, ch...@su... wrote: > Hi! >> Add error checks to: >> >> Make sure this case not slip into one situation that >> the first pthread_once fails, and the second successes, >> then the case passes with bypassing its assertion. >> >> Give more detailed and exact execute result. > > Out of curiosity, have you seen the situation where the pthread_once() > has failed, or is this fix for a hypotetical condition (which is not > wrong at all)? Ahh,as you mentioned. Actually,I did try to make pthread_once fail by initting "once_control" with invalid value,giving NULL as "init_routine" ,and so on,but it did not work at all. And,I scanned implementing of pthread_once in glibc src to find it nerver returns any other value than 0. So,it's maybe a "fix for a hypothetical condition" to follow POSIX. > >> Signed-off-by: DAN LI <li...@cn...> >> --- >> .../conformance/interfaces/pthread_once/1-1.c | 17 +++++++++++++---- >> 1 file changed, 13 insertions(+), 4 deletions(-) >> >> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> index 3a7c861..3392e6b 100644 >> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> @@ -26,7 +26,7 @@ >> #include "posixtest.h" >> >> /* Keeps track of how many times the init function has been called. */ >> -int init_flag; >> +static int init_flag; >> >> /* The init function that pthread_once calls */ >> void *an_init_func() >> @@ -37,16 +37,25 @@ void *an_init_func() >> >> int main() >> { >> + int ret; >> + >> pthread_once_t once_control = PTHREAD_ONCE_INIT; >> >> init_flag = 0; >> >> /* Call pthread_once, passing it the once_control */ >> - pthread_once(&once_control, (void *)an_init_func); >> - >> + ret = pthread_once(&once_control, (void *)an_init_func); > > Hmm, I think that we can get rid the cast to the (void *) here. My gues > is that the function has wrong prototype which generates warning here. > > Accordingly to manual page it should be void (*init_routine)(void). So > the correct prototype should be void an_init_func(void). Could you > please fix the prototype and remove the (void *) casts as well? > Ok, thanks for reviewing. >> + if (ret != 0) { >> + printf("pthread_once failed\n"); >> + return PTS_UNRESOLVED; >> + } >> /* Call pthread_once again. The init function should not be >> * called. */ >> - pthread_once(&once_control, (void *)an_init_func); >> + ret = pthread_once(&once_control, (void *)an_init_func); >> + if (ret != 0) { >> + printf("pthread_once failed\n"); >> + return PTS_UNRESOLVED; >> + } >> >> if (init_flag != 1) { >> printf("Test FAILED\n"); > |
From: DAN LI <li...@cn...> - 2013-03-08 02:42:02
|
Fix the prototype and remove the (void *) casts. Add error checks to: Make sure this case not slip into one situation that the first pthread_once fails, and the second successes, then the case passes with bypassing its assertion. Give more detailed and exact execute result. Signed-off-by: DAN LI <li...@cn...> --- .../conformance/interfaces/pthread_once/1-1.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..7504f6c 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c @@ -26,10 +26,10 @@ #include "posixtest.h" /* Keeps track of how many times the init function has been called. */ -int init_flag; +static int init_flag; /* The init function that pthread_once calls */ -void *an_init_func() +void an_init_func(void) { init_flag++; return NULL; @@ -37,16 +37,25 @@ void *an_init_func() int main() { + int ret; + pthread_once_t once_control = PTHREAD_ONCE_INIT; init_flag = 0; /* Call pthread_once, passing it the once_control */ - pthread_once(&once_control, (void *)an_init_func); - + ret = pthread_once(&once_control, an_init_func); + if (ret != 0) { + printf("pthread_once failed\n"); + return PTS_UNRESOLVED; + } /* Call pthread_once again. The init function should not be * called. */ - pthread_once(&once_control, (void *)an_init_func); + ret = pthread_once(&once_control, an_init_func); + if (ret != 0) { + printf("pthread_once failed\n"); + return PTS_UNRESOLVED; + } if (init_flag != 1) { printf("Test FAILED\n"); -- 1.7.12 |
From: <ch...@su...> - 2013-03-11 17:38:29
|
Hi! > Add error checks to: > Make sure this case not slip into one situation that > the first pthread_once fails, and the second successes, > then the case passes with bypassing its assertion. > > Give more detailed and exact execute result. > > > Signed-off-by: DAN LI <li...@cn...> Commited, thanks. -- Cyril Hrubis ch...@su... |