All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] [syscalls] io_submit: fix broken testcase
@ 2011-03-27 13:41 czhang
  2011-03-27 14:04 ` Caspar Zhang
  2011-03-27 14:13 ` czhang
  0 siblings, 2 replies; 12+ messages in thread
From: czhang @ 2011-03-27 13:41 UTC (permalink / raw)
  To: ltp-list; +Cc: emcnabb, Caspar Zhang

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

This is a multi-part message in MIME format.

[-- Attachment #2: Type: text/plain, Size: 1590 bytes --]


io_submit01 contains 4 negative testing: EINVAL, EFAULT, EINVAL+EFAULT
and EBADF. The first 3 testcases didn't initialize the content of 'ctx'
so that they contained invalid argument in the cases. This may cause
incorrect result on some architectures, like:

io_submit01    1  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    2  TFAIL  :  unexpected returned value - -22 - expected
-14
io_submit01    3  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    4  TPASS  :  expected failure - returned value = 9 : Bad
file descriptor

I fixed this issue by moving the initialization of ctx before the cases,
also added some additional negative + positive cases. Now tested on x86
and s390x system, the results seem good:

io_submit01    1  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    2  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    3  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    4  TPASS  :  expected failure - returned value = 14 : Bad
address
io_submit01    5  TPASS  :  expected failure - returned value = 22 :
Invalid argument
io_submit01    6  TPASS  :  expected failure - returned value = 9 : Bad
file descriptor
io_submit01    7  TPASS  :  call succeeded expectedly
io_submit01    8  TPASS  :  call succeeded expectedly

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  143 ++++++++++++++-------
 1 files changed, 98 insertions(+), 45 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-syscalls-io_submit-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscalls-io_submit-fix-broken-testcase.patch", Size: 6801 bytes --]

diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..79c0ddc 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -33,6 +33,7 @@ int TST_TOTAL = 3;
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
+#include <fcntl.h>
 
 static void cleanup(void)
 {
@@ -56,12 +57,6 @@ static void setup(void)
    On  success,  io_submit()  returns the number of iocbs submitted (which
    may be 0 if nr is zero); on failure,  it  returns  one  of  the  errors
    listed under ERRORS.
-
-   ERRORS
-   EINVAL The aio_context specified by ctx_id is invalid.  nr is less than
-   0.  The iocb at *iocbpp[0] is not properly initialized,  or  the
-   operation  specified  is  invalid for the file descriptor in the
-   iocb.
  */
 int main(int argc, char *argv[])
 {
@@ -69,8 +64,10 @@ int main(int argc, char *argv[])
 	char *msg;
 
 	long expected_return;
+	long expected_fault = -EFAULT;
+	long expected_inval = -EINVAL;
 
-	int rval;
+	int rval, fd;
 	char buf[256];
 	struct iocb iocb;
 	struct iocb *iocbs[1];
@@ -86,7 +83,13 @@ int main(int argc, char *argv[])
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
-
+		
+		/*
+		 * EINVAL The aio_context specified by ctx_id is invalid. nr is less
+		 * than 0. The iocb at *iocbpp[0] is not properly initialized, or the
+		 * operation specified is invalid for the file descriptor in the iocb.
+		 */
+		/* EINVAL-1: invalid ctx */
 		expected_return = -EINVAL;
 		TEST(io_submit(ctx, 0, NULL));
 		if (TEST_RETURN == 0) {
@@ -100,8 +103,40 @@ int main(int argc, char *argv[])
 				 "expected %ld", TEST_RETURN, expected_return);
 		}
 
+		/* EINVAL-2: invalid nr */
+		expected_return = -EINVAL;
+		rval = io_setup(1, &ctx);
+		if (rval != 0)
+			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
+		TEST(io_submit(ctx, -1, NULL));
+		if (TEST_RETURN == 0) {
+			tst_resm(TFAIL, "call succeeded unexpectedly");
+		} else if (TEST_RETURN == expected_return) {
+			tst_resm(TPASS, "expected failure - "
+				 "returned value = %ld : %s", (-1 * TEST_RETURN),
+				 strerror(-1 * TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "unexpected returned value - %ld - "
+				 "expected %ld", TEST_RETURN, expected_return);
+		}
+
+		/* EINVAL-3: uninitialized iocb */
+		expected_return = -EINVAL;
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		if (TEST_RETURN == 0) {
+			tst_resm(TFAIL, "call succeeded unexpectedly");
+		} else if (TEST_RETURN == expected_return) {
+			tst_resm(TPASS, "expected failure - "
+				 "returned value = %ld : %s", (-1 * TEST_RETURN),
+				 strerror(-1 * TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "unexpected returned value - %ld - "
+				 "expected %ld", TEST_RETURN, expected_return);
+		}
+
 		/*
-		   EFAULT One of the data structures points to invalid data.
+		 * EFAULT: One of the data structures points to invalid data.
 		 */
 		expected_return = -EFAULT;
 		TEST(io_submit(ctx, 1, (void *)-1));
@@ -116,51 +151,42 @@ int main(int argc, char *argv[])
 				 "expected %ld", TEST_RETURN, expected_return);
 		}
 
-		/* Special case EFAULT or EINVAL (indetermination)
-
-		   The errno depends on the per architecture implementation
-		   of io_submit. On the architecture using compat_sys_io_submit
-		   as its implementation, errno is set to -EINVAL. */
-		{
-			long expected_fault = -EFAULT;
-			long expected_inval = -EINVAL;
-
-			TEST(io_submit(ctx, 0, (void *)-1));
-			if (TEST_RETURN == 0)
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-			else if (TEST_RETURN == expected_fault
-				   || TEST_RETURN == expected_inval) {
-				tst_resm(TPASS, "expected failure - "
-					 "returned value = %ld : %s",
-					 (-1 * TEST_RETURN),
-					 strerror(-1 * TEST_RETURN));
-			} else {
-				tst_resm(TFAIL,
-					 "unexpected returned value - %ld - "
-					 "expected %ld(%s) or %ld(%s)",
-					 TEST_RETURN, expected_fault,
-					 strerror(-1 * expected_fault),
-					 expected_inval,
-					 strerror(-1 * expected_inval));
-			}
-
+		/* 
+		 * Special case EFAULT or EINVAL (indetermination)
+		 * 
+		 * The errno depends on the per architecture implementation
+		 * of io_submit. On the architecture using compat_sys_io_submit
+		 * as its implementation, errno is set to -EINVAL. 
+		 */
+		TEST(io_submit(ctx, -1, (void *)-1));
+		if (TEST_RETURN == 0) {
+			tst_resm(TFAIL, "call succeeded unexpectedly");
+		} else if (TEST_RETURN == expected_fault
+			   || TEST_RETURN == expected_inval) {
+			tst_resm(TPASS, "expected failure - "
+				 "returned value = %ld : %s",
+				 (-1 * TEST_RETURN),
+				 strerror(-1 * TEST_RETURN));
+		} else {
+			tst_resm(TFAIL,
+				 "unexpected returned value - %ld - "
+				 "expected %ld(%s) or %ld(%s)",
+				 TEST_RETURN, expected_fault,
+				 strerror(-1 * expected_fault),
+				 expected_inval,
+				 strerror(-1 * expected_inval));
 		}
 
 		/*
-		   EBADF  The file descriptor specified in the first iocb is invalid.
+		 * EBADF: The file descriptor specified in the first iocb is invalid.
 		 */
 		expected_return = -EBADF;
 		io_prep_pread(&iocb, -1, (void *)buf, sizeof(buf), 0);
 		iocbs[0] = &iocb;
-		memset(&ctx, 0, sizeof(io_context_t));
-		rval = io_setup(1, &ctx);
-		if (rval != 0)
-			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
-
 		TEST(io_submit(ctx, 1, iocbs));
-		if (TEST_RETURN == 0)
+		if (TEST_RETURN == 0) {
 			tst_resm(TFAIL, "call succeeded unexpectedly");
-		else if (TEST_RETURN == expected_return) {
+		} else if (TEST_RETURN == expected_return) {
 			tst_resm(TPASS, "expected failure - "
 				 "returned value = %ld : %s", (-1 * TEST_RETURN),
 				 strerror(-1 * TEST_RETURN));
@@ -168,6 +194,33 @@ int main(int argc, char *argv[])
 			tst_resm(TFAIL, "unexpected returned value - %ld - "
 				 "expected %ld", TEST_RETURN, expected_return);
 		}
+
+		/* positive test: nr == 0 */
+		TEST(io_submit(ctx, 0, NULL));
+		if (TEST_RETURN == 0) {
+			tst_resm(TPASS, "call succeeded expectedly");
+		} else {
+			tst_resm(TFAIL, "unexpected failure - "
+				 "returned value = %ld : %s", (-1 * TEST_RETURN),
+				 strerror(-1 * TEST_RETURN));
+		}
+
+		/* positive test: valid fd */
+		if ((fd = open("/etc/fstab", O_RDONLY)) == -1)
+			tst_resm(TBROK, "open /etc/fstab fail");
+		io_prep_pread(&iocb, fd, (void *)buf, sizeof(buf), 0);
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		if (TEST_RETURN == 1)
+			tst_resm(TPASS, "call succeeded expectedly");
+		else if (TEST_RETURN >= 0) {
+			tst_resm(TFAIL, "unexpected retval - "
+				 "returned value = %ld", TEST_RETURN);
+		} else {
+			tst_resm(TFAIL, "unexpected returned value - %ld - "
+				 "expected %ld", TEST_RETURN, expected_return);
+		}
+		close(fd);
 	}
 	cleanup();
 

[-- Attachment #4: Type: text/plain, Size: 418 bytes --]

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar

[-- Attachment #5: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-04-14 16:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-27 13:41 [LTP] [PATCH] [syscalls] io_submit: fix broken testcase czhang
2011-03-27 14:04 ` Caspar Zhang
2011-03-27 14:13 ` czhang
2011-04-01 14:44   ` Cyril Hrubis
2011-04-07  7:31     ` [LTP] [PATCH v2] " Caspar Zhang
2011-04-12  8:06     ` Caspar Zhang
2011-04-13 17:33       ` Cyril Hrubis
2011-04-14  3:33         ` [LTP] [PATCH v3] " Caspar Zhang
2011-04-14 14:44           ` Cyril Hrubis
2011-04-14 14:28             ` [LTP] [PATCH v4] " Caspar Zhang
2011-04-14 14:46               ` Masatake YAMATO
2011-04-14 16:33               ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.