* [LTP] [PATCH]pthread_once/1-1.c : cleanup & add error checks
@ 2013-03-04 9:12 DAN LI
2013-03-05 9:51 ` chrubis
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: DAN LI @ 2013-03-04 9:12 UTC (permalink / raw)
To: LTP list
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.dan@cn.fujitsu.com>
---
.../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
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [LTP] [PATCH]pthread_once/1-1.c : cleanup & add error checks
2013-03-04 9:12 [LTP] [PATCH]pthread_once/1-1.c : cleanup & add error checks DAN LI
@ 2013-03-05 9:51 ` chrubis
2013-03-05 10:44 ` [LTP] [PATCHv2]pthread_once/1-1.c : cleanup & " DAN LI
2013-03-06 2:30 ` [LTP] [PATCHv3]pthread_once/1-1.c : add " DAN LI
[not found] ` <51394F7C.8020301@cn.fujitsu.com>
2 siblings, 1 reply; 7+ messages in thread
From: chrubis @ 2013-03-05 9:51 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
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
chrubis@suse.cz
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread* [LTP] [PATCHv2]pthread_once/1-1.c : cleanup & error checks
2013-03-05 9:51 ` chrubis
@ 2013-03-05 10:44 ` DAN LI
2013-03-05 15:04 ` chrubis
0 siblings, 1 reply; 7+ messages in thread
From: DAN LI @ 2013-03-05 10:44 UTC (permalink / raw)
To: LTP list
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.dan@cn.fujitsu.com>
---
.../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
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCHv3]pthread_once/1-1.c : add error checks
2013-03-04 9:12 [LTP] [PATCH]pthread_once/1-1.c : cleanup & add error checks DAN LI
2013-03-05 9:51 ` chrubis
@ 2013-03-06 2:30 ` DAN LI
2013-03-06 13:04 ` chrubis
[not found] ` <51394F7C.8020301@cn.fujitsu.com>
2 siblings, 1 reply; 7+ messages in thread
From: DAN LI @ 2013-03-06 2:30 UTC (permalink / raw)
To: ltp-list
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.dan@cn.fujitsu.com>
---
.../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
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [LTP] [PATCHv3]pthread_once/1-1.c : add error checks
2013-03-06 2:30 ` [LTP] [PATCHv3]pthread_once/1-1.c : add " DAN LI
@ 2013-03-06 13:04 ` chrubis
0 siblings, 0 replies; 7+ messages in thread
From: chrubis @ 2013-03-06 13:04 UTC (permalink / raw)
To: DAN LI; +Cc: ltp-list
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.dan@cn.fujitsu.com>
> ---
> .../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
chrubis@suse.cz
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <51394F7C.8020301@cn.fujitsu.com>]
* Re: [LTP] [PATCHv4]pthread_once/1-1.c : cleanup & error checks
[not found] ` <51394F7C.8020301@cn.fujitsu.com>
@ 2013-03-11 17:39 ` chrubis
0 siblings, 0 replies; 7+ messages in thread
From: chrubis @ 2013-03-11 17:39 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
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.dan@cn.fujitsu.com>
Commited, thanks.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-03-11 17:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-04 9:12 [LTP] [PATCH]pthread_once/1-1.c : cleanup & add error checks DAN LI
2013-03-05 9:51 ` chrubis
2013-03-05 10:44 ` [LTP] [PATCHv2]pthread_once/1-1.c : cleanup & " DAN LI
2013-03-05 15:04 ` chrubis
2013-03-06 2:30 ` [LTP] [PATCHv3]pthread_once/1-1.c : add " DAN LI
2013-03-06 13:04 ` chrubis
[not found] ` <51394F7C.8020301@cn.fujitsu.com>
2013-03-11 17:39 ` [LTP] [PATCHv4]pthread_once/1-1.c : cleanup & " chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox