Skip to contentSkip to conversation

pthread_once/1-1.c : cleanup & add error checks

PATCH Superseded DAN LI 2 participants 7 messages Mar 4, 2013 – Mar 11, 2013 1 message not in the archive

lore
Share & tools
lore

DAN LI

author
#0 lore raw

PATCH 1/1 pthread_once/1-1.c : cleanup & add error checks

1.Make log style keep consistent with other cases in the same directory. 2.Add error checks to strengthen the robustness of this case.

---
 .../conformance/interfaces/pthread_once/1-1.c      | 70 +++++++++++++++++++---
 1 file changed, 61 insertions(+), 9 deletions(-)
(quoted diff) +0 -0

b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..03b2875 100644

testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +61 -9

93 lines not on this page · raw message

Signature · 11 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 2 lines

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.

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
author
#2 lore raw

PATCH v2 1/1 pthread_once/1-1.c : cleanup & error checks

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.

---
 .../conformance/interfaces/pthread_once/1-1.c      | 32 ++++++++++++++++------
 1 file changed, 23 insertions(+), 9 deletions(-)
(quoted diff) +0 -0

b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..c7ae170 100644

testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +23 -9
@@ -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;
 }
Signature · 12 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw

Re: [LTP] [PATCHv2]pthread_once/1-1.c : cleanup & error checks

Hi!

Quoted 2 lines

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.

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
author
#4 lore raw

PATCH v3 1/1 pthread_once/1-1.c : add error checks

In reply to DAN LI

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.

---
 .../conformance/interfaces/pthread_once/1-1.c           | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c index 3a7c861..3392e6b 100644

testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +13 -4
@@ -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");
Signature · 12 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw

Re: [LTP] [PATCHv3]pthread_once/1-1.c : add error checks

Hi!

Quoted 7 lines

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)?

Quoted 23 lines
---
 .../conformance/interfaces/pthread_once/1-1.c           | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +1 -1
index 3a7c861..3392e6b 100644
@@ -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()
 {

testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c void *an_init_func() · line 47

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +3 -2
+	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?

Quoted 15 lines
testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c +9 -1
+	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");
Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
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
[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]

#7 lore raw

Re: [LTP] [PATCHv4]pthread_once/1-1.c : cleanup & error checks

Hi!

Quoted 9 lines

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.

Commited, thanks.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list