Skip to contentSkip to conversation

mq_timedreceive: 10-2.c: check timeout error rather than invalid parameter error

PATCH In review Akira Takeuchi 3 participants 5 messages Mar 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mq_timedreceive: 10-2.c: check timeout error rather than invalid parameter error

10-2.c now passes the invalid parameter to mq_timedreceive by specifying a negative value to nanoseconds field, and checks whether EINVAL is not returned when a message can be removed from the queue immediately.

However, this may not be a appropriate testing of mq_timedreceive. POSIX spec of mq_timedreceive says:
The validity of the abstime parameter need not be checked if a message can be removed from the message queue immediately.

This is open for interpretation of POSIX spec, and it was argued about in LKML.

    https://lkml.org/lkml/2012/3/14/589

The conclusion in LKML was that what POSIX spec says is "you don't *have* to check validity". That is, it is allowed to check the validity.

On the other hand, actually, timeout error should not be returned when message can be performed immediately.

Therefore, I modify the testcase to check timeout error rather than invalid parameter error.

---
 .../conformance/interfaces/mq_timedreceive/10-2.c  |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +9 -11
index 49ee4f2..1cbb5b6 100644
@@ -8,12 +8,11 @@
 
 /*
  * If the message can be removed from the message queue immedietely,
- * the operation will never fail and the validity of abs_timeout
- * need not be checked.
+ * the operation will not fail even if abs_timeout is the past time.
  * Test Steps:
- * 1. Set the abs_timeout to be invalid, when there is message
+ * 1. Set the abs_timeout to be a past time, when there is message
  *    than can be removed from the message queue immediately.
- * 2. The validity of abs_timeout will not be checked.
+ * 2. Timeout error is not occured.
  */
 
 #include <stdio.h>
@@ -27,7 +26,7 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define TEST "10-1"
+#define TEST "10-2"
 #define FUNCTION "mq_timedreceive"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
@@ -61,12 +60,11 @@ int main()
         }
 
 	sleep(1); /* wait for a while */
-	ts.tv_sec = time(NULL) -1; /* No wait */
-	ts.tv_nsec = -1; /* Invalid */
+	ts.tv_sec = time(NULL) -1; /* Past time */
+	ts.tv_nsec = 0;
         if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) {
-		if (errno == EINVAL)
-			printf("FAIL: the validity of abs_timeout "
-				"is checked\n");
+		if (errno == ETIMEDOUT)
+			printf("FAIL: mq_timedreceive returned timeout error\n");
 		else
 			perror("Unexpected error at mq_timedreceive");
 		failure = 1;
@@ -94,4 +92,4 @@ int main()
 
         printf("Test PASSED\n");
         return PTS_PASS;
-}
\ No newline at end of file
+}
Signature · 12 lines
1.7.4.1



------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Akira Takeuchi said the following on 2012-3-22 12:23:

Quoted 9 lines

10-2.c now passes the invalid parameter to mq_timedreceive by specifying a negative value to nanoseconds field, and checks whether EINVAL is not returned when a message can be removed from the queue immediately.

However, this may not be a appropriate testing of mq_timedreceive. POSIX spec of mq_timedreceive says:
The validity of the abstime parameter need not be checked if a message can be removed from the message queue immediately.

Quoted 6 lines

This is open for interpretation of POSIX spec, and it was argued about in LKML.

    https://lkml.org/lkml/2012/3/14/589

The conclusion in LKML was that what POSIX spec says is "you don't *have* to check validity". That is, it is allowed to check the validity.

Yeah.

Quoted 3 lines

On the other hand, actually, timeout error should not be returned when message can be performed immediately.

POSIX spec does not say this, so I think it is not necessary to check timeout error.

Quoted 42 lines

Therefore, I modify the testcase to check timeout error rather than invalid parameter error.

---
 .../conformance/interfaces/mq_timedreceive/10-2.c  |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +4 -5
index 49ee4f2..1cbb5b6 100644
@@ -8,12 +8,11 @@
 
 /*
  * If the message can be removed from the message queue immedietely,
- * the operation will never fail and the validity of abs_timeout
- * need not be checked.
+ * the operation will not fail even if abs_timeout is the past time.
  * Test Steps:
- * 1. Set the abs_timeout to be invalid, when there is message
+ * 1. Set the abs_timeout to be a past time, when there is message
  *    than can be removed from the message queue immediately.
- * 2. The validity of abs_timeout will not be checked.
+ * 2. Timeout error is not occured.
  */
 
 #include <stdio.h>
@@ -27,7 +26,7 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define TEST "10-1"
+#define TEST "10-2"
 #define FUNCTION "mq_timedreceive"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
@@ -61,12 +60,11 @@ int main()
         }
 
 	sleep(1); /* wait for a while */

testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c int main() · line 67

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +4 -5
-	ts.tv_sec = time(NULL) -1; /* No wait */
-	ts.tv_nsec = -1; /* Invalid */
+	ts.tv_sec = time(NULL) -1; /* Past time */
+	ts.tv_nsec = 0;
         if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) {
-		if (errno == EINVAL)
-			printf("FAIL: the validity of abs_timeout "
-				"is checked\n");
+		if (errno == ETIMEDOUT)
+			printf("FAIL: mq_timedreceive returned timeout error\n");

The lines need not to be added.
timeout error can be as Unexpected error.

Signature · 2 lines
Best Regards,
Peng

testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c int main() · line 95

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +1 -1
 		else
 			perror("Unexpected error at mq_timedreceive");
 		failure = 1;
@@ -94,4 +92,4 @@ int main()
 
         printf("Test PASSED\n");
         return PTS_PASS;
-}
\ No newline at end of file
+}

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

Thank you for replying.

Quoted 5 lines · On Thu, 22 Mar 2012 16:19:06 +0800 Peng Haitao <[email protected]> wrote:
Quoted 3 lines

On the other hand, actually, timeout error should not be returned when message can be performed immediately.

POSIX spec does not say this, so I think it is not necessary to check timeout error.

Really ? POSIX spec describes as below:

Under no circumstance shall the operation fail with a timeout if a message can be removed from the message queue immediately.

http://pubs.opengroup.org/onlinepubs/009604499/functions/mq_receive.html

My reading of this is that timeout error must not be returned when message can be performed immediately. What do you think of it ?

Regards,
Akira Takeuchi

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Akira Takeuchi said the following on 2012-3-22 17:36:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

On the other hand, actually, timeout error should not be returned when message can be performed immediately.

POSIX spec does not say this, so I think it is not necessary to check timeout error.

Really ? POSIX spec describes as below:

Quoted 8 lines

Under no circumstance shall the operation fail with a timeout if a message can be removed from the message queue immediately.

http://pubs.opengroup.org/onlinepubs/009604499/functions/mq_receive.html

My reading of this is that timeout error must not be returned when message can be performed immediately. What do you think of it ?

Yeah.
I am sorry missing it:(

The patch looks good.

Signature · 2 lines
Best Regards,
Peng
Quoted 6 lines

Regards,
Akira Takeuchi

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
In reply to Akira Takeuchi
Quoted 12 lines · Akira Takeuchi

10-2.c now passes the invalid parameter to mq_timedreceive by specifying a negative value to nanoseconds field, and checks whether EINVAL is not returned when a message can be removed from the queue immediately.

However, this may not be a appropriate testing of mq_timedreceive. POSIX spec of mq_timedreceive says:
The validity of the abstime parameter need not be checked if a message can be removed from the message queue immediately.

This is open for interpretation of POSIX spec, and it was argued about in LKML.

    https://lkml.org/lkml/2012/3/14/589
Quoted 8 lines

The conclusion in LKML was that what POSIX spec says is "you don't *have* to check validity". That is, it is allowed to check the validity.

On the other hand, actually, timeout error should not be returned when message can be performed immediately.

Therefore, I modify the testcase to check timeout error rather than invalid parameter error.

pushed, thanks.

Wanlong Gao

Quoted 54 lines
---
 .../conformance/interfaces/mq_timedreceive/10-2.c  |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +8 -10
index 49ee4f2..1cbb5b6 100644
@@ -8,12 +8,11 @@
 
 /*
  * If the message can be removed from the message queue immedietely,
- * the operation will never fail and the validity of abs_timeout
- * need not be checked.
+ * the operation will not fail even if abs_timeout is the past time.
  * Test Steps:
- * 1. Set the abs_timeout to be invalid, when there is message
+ * 1. Set the abs_timeout to be a past time, when there is message
  *    than can be removed from the message queue immediately.
- * 2. The validity of abs_timeout will not be checked.
+ * 2. Timeout error is not occured.
  */
 
 #include <stdio.h>
@@ -27,7 +26,7 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define TEST "10-1"
+#define TEST "10-2"
 #define FUNCTION "mq_timedreceive"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
@@ -61,12 +60,11 @@ int main()
         }
 
 	sleep(1); /* wait for a while */
-	ts.tv_sec = time(NULL) -1; /* No wait */
-	ts.tv_nsec = -1; /* Invalid */
+	ts.tv_sec = time(NULL) -1; /* Past time */
+	ts.tv_nsec = 0;
         if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) {
-		if (errno == EINVAL)
-			printf("FAIL: the validity of abs_timeout "
-				"is checked\n");
+		if (errno == ETIMEDOUT)
+			printf("FAIL: mq_timedreceive returned timeout error\n");
 		else
 			perror("Unexpected error at mq_timedreceive");
 		failure = 1;

testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c int main() · line 95

Quoted 6 lines
testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/10-2.c +1 -1
@@ -94,4 +92,4 @@ int main()
 
         printf("Test PASSED\n");
         return PTS_PASS;
-}
\ No newline at end of file
+}

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list