Skip to contentSkip to conversation

io_submit: fix broken testcase

PATCH In review [email protected] 3 participants 12 messages Mar 27, 2011 – Apr 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_submit: fix broken testcase

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
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  143 ++++++++++++++-------
 1 files changed, 98 insertions(+), 45 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +98 -45
index 44580e6..79c0ddc 100644
@@ -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();
 

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

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw

Sorry, there are some trailing whitespace in the patch, please ignore this one, I'll workout a newer version.

Quoted 39 lines · On 03/27/2011 09:41 PM, [email protected] wrote:

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
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  143 ++++++++++++++-------
 1 files changed, 98 insertions(+), 45 deletions(-)
Signature · 19 lines
/---------------------------------------\
| Name: Caspar Zhang                    |
| Team: Kernel-QE                       |
| Timezone: GMT+0800 (Asia/Shanghai)    |
| IRC: caspar @ #kernel-qe, #eng-china  |
| Phone: +86-10-6260-8150               |
| Cellphone: +86-138-1073-0090          |
\---------------------------------------/

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

PATCH 1/1 io_submit: fix broken testcase

In reply to [email protected]

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
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  147 ++++++++++++++-------
 1 files changed, 101 insertions(+), 46 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +101 -46
index 44580e6..fc9fc1c 100644
@@ -27,12 +27,13 @@
 
 char *TCID = "io_submit01";
 
-int TST_TOTAL = 3;
+int TST_TOTAL = 8;
 
 #ifdef HAVE_LIBAIO_H
 #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,12 +64,14 @@ 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];
-	
+
 	io_context_t ctx;
 
 	memset(&ctx, 0, sizeof(ctx));
@@ -87,6 +84,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 +104,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 +152,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 +195,34 @@ 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 */
+		fd = open("/etc/fstab", O_RDONLY);
+		if (fd == -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();
 

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

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Hi!

Quoted 7 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +7 -0
+		/* 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) {

testcases/kernel/syscalls/io_submit/io_submit01.c int main(int argc, char *argv[]) · line 123

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +10 -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);
+		}
+

I would preffer to write a function that does this instead of copying this code block several times.

Quoted 1 line

TEST(io_submit(ctx, 1, (void *)-1));

Here it should rather be (io_context_t)-1 as the io_context_t is choosen to be opaque type...

Quoted 30 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +0 -26
@@ -116,51 +152,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));

testcases/kernel/syscalls/io_submit/io_submit01.c int main(int argc, char *argv[]) · line 162

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +8 -2
-			}
-
+		/*
+		 * 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));

Here too.

Quoted 14 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +14 -0
+		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),

testcases/kernel/syscalls/io_submit/io_submit01.c int main(int argc, char *argv[]) · line 185

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +3 -1
+				 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);

The void cast is not needed here. Generally all pointers in C are compatible with void * pointer and casted automatically.

Quoted 22 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +5 -7
 		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 +195,34 @@ 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));

testcases/kernel/syscalls/io_submit/io_submit01.c int main(int argc, char *argv[]) · line 210

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +10 -0
+		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 */
+		fd = open("/etc/fstab", O_RDONLY);

Hmm, I would preffer to create temporary file for this rather than relying on that some magical file exists in system.

testcases/kernel/syscalls/io_submit/io_submit01.c int main(int argc, char *argv[]) · line 213

Quoted 3 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +3 -0
+		if (fd == -1)
+			tst_resm(TBROK, "open /etc/fstab fail");
+		io_prep_pread(&iocb, fd, (void *)buf, sizeof(buf), 0);

The cast again.

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#4 lore raw

PATCH v2 1/1 io_submit: fix broken testcase

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  :  expected success - returned value = 0
io_submit01    8  TPASS  :  expected success - returned value = 1
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  208 +++++++++++----------
 1 files changed, 109 insertions(+), 99 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +109 -99
index 44580e6..cd94649 100644
@@ -27,54 +27,53 @@
 
 char *TCID = "io_submit01";
 
-int TST_TOTAL = 3;
+int TST_TOTAL = 8;
 
 #ifdef HAVE_LIBAIO_H
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
-
-static void cleanup(void)
-{
-	TEST_CLEANUP;
+#include <fcntl.h>
+
+#define TESTFILE	"testfile"
+#define NEG_RESULT(exp, act) {\
+	if (act == 0) {\
+			tst_resm(TFAIL, "call succeeded unexpectedly");\
+		} else if (act == exp) {\
+			tst_resm(TPASS, "expected failure - "\
+				"returned value = %ld : %s", \
+				act, strerror(-1 * act));\
+		} else {\
+			tst_resm(TFAIL, "unexpected failure - "\
+				"returned value = %ld : %s, "\
+				"expected value = %d : %s",\
+				act, strerror(-1 * act),\
+				exp, strerror(-1 * exp));\
+		} \
 }
-
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+#define POS_RESULT(act) {\
+	if (act >= 0) {\
+		tst_resm(TPASS, "expected success - "\
+			"returned value = %ld", act);\
+	} else {\
+		tst_resm(TFAIL, "unexpected failure - "\
+			"returned value = %ld : %s",\
+			act, strerror(-1 * act));\
+	} \
 }
 
-/*
-   DESCRIPTION
-   io_submit() queues nr I/O request blocks for processing in the AIO con-
-   text ctx_id.  iocbpp should be an array of nr AIO request blocks, which
-   will be submitted to context ctx_id.
-
-   RETURN VALUE
-   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.
- */
+static void cleanup(void);
+static void setup(void);
+
 int main(int argc, char *argv[])
 {
 	int lc;
 	char *msg;
-
-	long expected_return;
-
-	int rval;
+	int rval, fd;
 	char buf[256];
 	struct iocb iocb;
 	struct iocb *iocbs[1];
-	
+
 	io_context_t ctx;
 
 	memset(&ctx, 0, sizeof(ctx));
@@ -87,92 +86,103 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
 
-		expected_return = -EINVAL;
+		/* 1 - EINVAL */
+		/* 1.1 - EINVAL: invalid ctx */
 		TEST(io_submit(ctx, 0, 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);
-		}
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 1.2 - EINVAL: invalid nr */
+		rval = io_setup(1, &ctx);
+		if (rval != 0)
+			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
+		TEST(io_submit(ctx, -1, NULL));
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 1.3 - EINVAL: uninitialized iocb */
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 2 - EFAULT: iocb points to invalid data */
+		TEST(io_submit(ctx, 1, (struct iocb **)-1));
+		NEG_RESULT(-EFAULT, TEST_RETURN);
 
 		/*
-		   EFAULT One of the data structures points to invalid data.
+		 * 3 - 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.
 		 */
-		expected_return = -EFAULT;
-		TEST(io_submit(ctx, 1, (void *)-1));
+		TEST(io_submit(ctx, -1, (struct iocb **)-1));
 		if (TEST_RETURN == 0) {
 			tst_resm(TFAIL, "call succeeded unexpectedly");
-		} else if (TEST_RETURN == expected_return) {
+		} else if (TEST_RETURN == -EFAULT
+			   || TEST_RETURN == -EINVAL) {
 			tst_resm(TPASS, "expected failure - "
-				 "returned value = %ld : %s", (-1 * TEST_RETURN),
-				 strerror(-1 * TEST_RETURN));
+				"returned value = %ld : %s",
+				TEST_RETURN, strerror(-1 * TEST_RETURN));
 		} else {
-			tst_resm(TFAIL, "unexpected returned value - %ld - "
-				 "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));
-			}
-
+			tst_resm(TFAIL, "unexpected failure - "
+				"returned value = %ld : %s, "
+				"expected = %d : %s or %d : %s",
+				TEST_RETURN, strerror(-1 * TEST_RETURN),
+				-EFAULT, strerror(EFAULT),
+				-EINVAL, strerror(EINVAL));
 		}
 
 		/*
-		   EBADF  The file descriptor specified in the first iocb is invalid.
+		 * 4 - EBADF: fd in iocb is invalid
 		 */
-		expected_return = -EBADF;
-		io_prep_pread(&iocb, -1, (void *)buf, sizeof(buf), 0);
+		io_prep_pread(&iocb, -1, 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));
+		NEG_RESULT(-EBADF, TEST_RETURN);
+
+		/* 5 - Positive test: nr == 0 */
+		TEST(io_submit(ctx, 0, NULL));
+		POS_RESULT(TEST_RETURN);
 
+		/* 6 - Positive test: valid fd */
+		fd = open(TESTFILE, O_RDONLY);
+		if (fd == -1)
+			tst_resm(TBROK|TERRNO, "open");
+		io_prep_pread(&iocb, fd, buf, sizeof(buf), 0);
+		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);
-		}
+		POS_RESULT(TEST_RETURN);
+		if (close(fd) == -1)
+			tst_resm(TBROK|TERRNO, "close");
 	}
 	cleanup();
 
 	tst_exit();
 }
+
+static void setup(void)
+{
+	int fd;
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	fd = open(TESTFILE, O_CREAT|O_RDWR, 0755);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (close(fd) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "close");
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+
+	tst_rmdir();
+}
+
 #else
 int main(int argc, char *argv[])
 {

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#5 lore raw

PATCH v2 1/1 io_submit: fix broken testcase

In reply to Cyril Hrubis

Updated the patch per Cyril's suggestion but the v2 patch escaped from my mailbox, re-send it again. Please review it.

Thanks,
Caspar

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  :  expected success - returned value = 0
io_submit01    8  TPASS  :  expected success - returned value = 1
---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  208 +++++++++++----------
 1 files changed, 109 insertions(+), 99 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +109 -99
index 44580e6..cd94649 100644
@@ -27,54 +27,53 @@
 
 char *TCID = "io_submit01";
 
-int TST_TOTAL = 3;
+int TST_TOTAL = 8;
 
 #ifdef HAVE_LIBAIO_H
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
-
-static void cleanup(void)
-{
-	TEST_CLEANUP;
+#include <fcntl.h>
+
+#define TESTFILE	"testfile"
+#define NEG_RESULT(exp, act) {\
+	if (act == 0) {\
+			tst_resm(TFAIL, "call succeeded unexpectedly");\
+		} else if (act == exp) {\
+			tst_resm(TPASS, "expected failure - "\
+				"returned value = %ld : %s", \
+				act, strerror(-1 * act));\
+		} else {\
+			tst_resm(TFAIL, "unexpected failure - "\
+				"returned value = %ld : %s, "\
+				"expected value = %d : %s",\
+				act, strerror(-1 * act),\
+				exp, strerror(-1 * exp));\
+		} \
 }
-
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+#define POS_RESULT(act) {\
+	if (act >= 0) {\
+		tst_resm(TPASS, "expected success - "\
+			"returned value = %ld", act);\
+	} else {\
+		tst_resm(TFAIL, "unexpected failure - "\
+			"returned value = %ld : %s",\
+			act, strerror(-1 * act));\
+	} \
 }
 
-/*
-   DESCRIPTION
-   io_submit() queues nr I/O request blocks for processing in the AIO con-
-   text ctx_id.  iocbpp should be an array of nr AIO request blocks, which
-   will be submitted to context ctx_id.
-
-   RETURN VALUE
-   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.
- */
+static void cleanup(void);
+static void setup(void);
+
 int main(int argc, char *argv[])
 {
 	int lc;
 	char *msg;
-
-	long expected_return;
-
-	int rval;
+	int rval, fd;
 	char buf[256];
 	struct iocb iocb;
 	struct iocb *iocbs[1];
-	
+
 	io_context_t ctx;
 
 	memset(&ctx, 0, sizeof(ctx));
@@ -87,92 +86,103 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
 
-		expected_return = -EINVAL;
+		/* 1 - EINVAL */
+		/* 1.1 - EINVAL: invalid ctx */
 		TEST(io_submit(ctx, 0, 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);
-		}
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 1.2 - EINVAL: invalid nr */
+		rval = io_setup(1, &ctx);
+		if (rval != 0)
+			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
+		TEST(io_submit(ctx, -1, NULL));
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 1.3 - EINVAL: uninitialized iocb */
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		NEG_RESULT(-EINVAL, TEST_RETURN);
+
+		/* 2 - EFAULT: iocb points to invalid data */
+		TEST(io_submit(ctx, 1, (struct iocb **)-1));
+		NEG_RESULT(-EFAULT, TEST_RETURN);
 
 		/*
-		   EFAULT One of the data structures points to invalid data.
+		 * 3 - 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.
 		 */
-		expected_return = -EFAULT;
-		TEST(io_submit(ctx, 1, (void *)-1));
+		TEST(io_submit(ctx, -1, (struct iocb **)-1));
 		if (TEST_RETURN == 0) {
 			tst_resm(TFAIL, "call succeeded unexpectedly");
-		} else if (TEST_RETURN == expected_return) {
+		} else if (TEST_RETURN == -EFAULT
+			   || TEST_RETURN == -EINVAL) {
 			tst_resm(TPASS, "expected failure - "
-				 "returned value = %ld : %s", (-1 * TEST_RETURN),
-				 strerror(-1 * TEST_RETURN));
+				"returned value = %ld : %s",
+				TEST_RETURN, strerror(-1 * TEST_RETURN));
 		} else {
-			tst_resm(TFAIL, "unexpected returned value - %ld - "
-				 "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));
-			}
-
+			tst_resm(TFAIL, "unexpected failure - "
+				"returned value = %ld : %s, "
+				"expected = %d : %s or %d : %s",
+				TEST_RETURN, strerror(-1 * TEST_RETURN),
+				-EFAULT, strerror(EFAULT),
+				-EINVAL, strerror(EINVAL));
 		}
 
 		/*
-		   EBADF  The file descriptor specified in the first iocb is invalid.
+		 * 4 - EBADF: fd in iocb is invalid
 		 */
-		expected_return = -EBADF;
-		io_prep_pread(&iocb, -1, (void *)buf, sizeof(buf), 0);
+		io_prep_pread(&iocb, -1, 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));
+		NEG_RESULT(-EBADF, TEST_RETURN);
+
+		/* 5 - Positive test: nr == 0 */
+		TEST(io_submit(ctx, 0, NULL));
+		POS_RESULT(TEST_RETURN);
 
+		/* 6 - Positive test: valid fd */
+		fd = open(TESTFILE, O_RDONLY);
+		if (fd == -1)
+			tst_resm(TBROK|TERRNO, "open");
+		io_prep_pread(&iocb, fd, buf, sizeof(buf), 0);
+		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);
-		}
+		POS_RESULT(TEST_RETURN);
+		if (close(fd) == -1)
+			tst_resm(TBROK|TERRNO, "close");
 	}
 	cleanup();
 
 	tst_exit();
 }
+
+static void setup(void)
+{
+	int fd;
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	fd = open(TESTFILE, O_CREAT|O_RDWR, 0755);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (close(fd) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "close");
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+
+	tst_rmdir();
+}
+
 #else
 int main(int argc, char *argv[])
 {

------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes not days. Key insights are discussed in the 2010 Forrester Wave Report as part of an in-depth evaluation of disaster recovery service providers. Forrester found the best-in-class provider in terms of services and vision. Read this report now! http://p.sf.net/sfu/ibm-webcastpromo

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

Hi!

Quoted 35 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +18 -11
-int TST_TOTAL = 3;
+int TST_TOTAL = 8;
 
 #ifdef HAVE_LIBAIO_H
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
-
-static void cleanup(void)
-{
-	TEST_CLEANUP;
+#include <fcntl.h>
+
+#define TESTFILE	"testfile"
+#define NEG_RESULT(exp, act) {\
+	if (act == 0) {\
+			tst_resm(TFAIL, "call succeeded unexpectedly");\
+		} else if (act == exp) {\
+			tst_resm(TPASS, "expected failure - "\
+				"returned value = %ld : %s", \
+				act, strerror(-1 * act));\
+		} else {\
+			tst_resm(TFAIL, "unexpected failure - "\
+				"returned value = %ld : %s, "\
+				"expected value = %d : %s",\
+				act, strerror(-1 * act),\
+				exp, strerror(-1 * exp));\
+		} \
 }
-
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;

testcases/kernel/syscalls/io_submit/io_submit01.c line 63

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +9 -0
+#define POS_RESULT(act) {\
+	if (act >= 0) {\
+		tst_resm(TPASS, "expected success - "\
+			"returned value = %ld", act);\
+	} else {\
+		tst_resm(TFAIL, "unexpected failure - "\
+			"returned value = %ld : %s",\
+			act, strerror(-1 * act));\
+	} \
 }

Any particular reason why these couldn't be functions? Macros are harder to read and easier to misuse, so generally they shouldn't be used unless it's really necessary.

Or maybe even better to have a funciton that gets io_submit parameters and expected result as an arguments and does the test itself.

And also please avoid unnecessary code moving. If you contributed a test that has setup() and cleanup() after main, that's ok. But there is no need to shuffle that code in the existings testcases.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now!  http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#7 lore raw

PATCH v3 1/1 io_submit: fix broken testcase

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  :  expected success - returned value = 0
io_submit01    8  TPASS  :  expected success - returned value = 1

v2: use tempfile instead of read /etc/fstab directly
v3: add a function to check results

---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  189 +++++++++++----------
 1 files changed, 99 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +99 -90
index 44580e6..82cb1a2 100644
@@ -33,48 +33,71 @@ int TST_TOTAL = 3;
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
+#include <fcntl.h>
+
+#define TESTFILE	"testfile"
 
 static void cleanup(void)
 {
 	TEST_CLEANUP;
+
+	tst_rmdir();
 }
 
 static void setup(void)
 {
+	int fd;
+
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	fd = open(TESTFILE, O_CREAT|O_RDWR, 0755);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (close(fd) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "close");
+}
+
+static void check_result(long exp, long act)
+{
+	if (exp >= 0)
+	{
+		if (act == exp)
+			tst_resm(TPASS, "expected success - "
+					"returned value = %ld", act);
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s",
+					act, strerror(-1 * act));
+	} else {
+		if (act == exp)
+			tst_resm(TPASS, "expected failure - "
+					"returned value = %ld : %s",
+					act, strerror(-1 * act));
+		else if (act == 0)
+			tst_resm(TFAIL, "call succeeded unexpectedly");
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s, "
+					"expected value = %ld : %s",
+					act, strerror(-1 * act),
+					exp, strerror(-1 * exp));
+	}
 }
 
-/*
-   DESCRIPTION
-   io_submit() queues nr I/O request blocks for processing in the AIO con-
-   text ctx_id.  iocbpp should be an array of nr AIO request blocks, which
-   will be submitted to context ctx_id.
-
-   RETURN VALUE
-   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[])
 {
 	int lc;
 	char *msg;
 
-	long expected_return;
-
-	int rval;
+	int rval, fd;
 	char buf[256];
 	struct iocb iocb;
 	struct iocb *iocbs[1];
-	
+
 	io_context_t ctx;
 
 	memset(&ctx, 0, sizeof(ctx));
@@ -87,87 +110,73 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
 
-		expected_return = -EINVAL;
+		/* 1 - EINVAL */
+		/* 1.1 - EINVAL: invalid ctx */
 		TEST(io_submit(ctx, 0, 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);
-		}
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 1.2 - EINVAL: invalid nr */
+		rval = io_setup(1, &ctx);
+		if (rval != 0)
+			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
+		TEST(io_submit(ctx, -1, NULL));
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 1.3 - EINVAL: uninitialized iocb */
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 2 - EFAULT: iocb points to invalid data */
+		TEST(io_submit(ctx, 1, (struct iocb **)-1));
+		check_result(-EFAULT, TEST_RETURN);
 
 		/*
-		   EFAULT One of the data structures points to invalid data.
+		 * 3 - 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.
 		 */
-		expected_return = -EFAULT;
-		TEST(io_submit(ctx, 1, (void *)-1));
-		if (TEST_RETURN == 0) {
+		TEST(io_submit(ctx, -1, (struct iocb **)-1));
+		if (TEST_RETURN == 0)
 			tst_resm(TFAIL, "call succeeded unexpectedly");
-		} else if (TEST_RETURN == expected_return) {
+		else if (TEST_RETURN == -EFAULT
+				|| TEST_RETURN == -EINVAL)
 			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);
-		}
-
-		/* 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));
-			}
-
-		}
+					"returned value = %ld : %s",
+					TEST_RETURN, strerror(-1 * TEST_RETURN));
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s, "
+					"expected = %d : %s or %d : %s",
+					TEST_RETURN, strerror(-1 * TEST_RETURN),
+					-EFAULT, strerror(EFAULT),
+					-EINVAL, strerror(EINVAL));
 
 		/*
-		   EBADF  The file descriptor specified in the first iocb is invalid.
+		 * 4 - EBADF: fd in iocb is invalid
 		 */
-		expected_return = -EBADF;
-		io_prep_pread(&iocb, -1, (void *)buf, sizeof(buf), 0);
+		io_prep_pread(&iocb, -1, 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));
+		check_result(-EBADF, TEST_RETURN);
 
+		/* 5 - Positive test: nr == 0 */
+		TEST(io_submit(ctx, 0, NULL));
+		check_result(0, TEST_RETURN);
+
+		/* 6 - Positive test: valid fd */
+		fd = open(TESTFILE, O_RDONLY);
+		if (fd == -1)
+			tst_resm(TBROK|TERRNO, "open");
+		io_prep_pread(&iocb, fd, buf, sizeof(buf), 0);
+		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);
-		}
+		check_result(1, TEST_RETURN);
+		if (close(fd) == -1)
+			tst_resm(TBROK|TERRNO, "close");
+
 	}
 	cleanup();
 

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw

Hi!

Quoted 16 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +16 -0
+static void check_result(long exp, long act)
+{
+	if (exp >= 0)
+	{
+		if (act == exp)
+			tst_resm(TPASS, "expected success - "
+					"returned value = %ld", act);
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s",
+					act, strerror(-1 * act));
+	} else {
+		if (act == exp)
+			tst_resm(TPASS, "expected failure - "
+					"returned value = %ld : %s",
+					act, strerror(-1 * act));

testcases/kernel/syscalls/io_submit/io_submit01.c int TST_TOTAL = 3; · line 89

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit01.c +9 -0
+		else if (act == 0)
+			tst_resm(TFAIL, "call succeeded unexpectedly");
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s, "
+					"expected value = %ld : %s",
+					act, strerror(-1 * act),
+					exp, strerror(-1 * exp));
+	}
 }

I hate being CodingStyle nazi (and that is one more reason why you should learn how to use linux/scripts/checkpatch.pl...).

But here the curly bracket should be located at the end of if (exp >= 0) and not on the new line.

Also it could be a little better if there were an return statement in the first code block, something like:

if (exp >= 0) {
	...
	return;
}

if (act == exp)

	...

Which would make the code IMHO more readable.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#9 lore raw

PATCH v4 1/1 io_submit: fix broken testcase

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  :  expected success - returned value = 0
io_submit01    8  TPASS  :  expected success - returned value = 1

v2: use tempfile instead of read /etc/fstab directly
v3: add a function to check results
v4: code style improvement

---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  190 +++++++++++----------
 1 files changed, 100 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/io_submit/io_submit01.c +100 -90
index 44580e6..da15aa0 100644
@@ -33,48 +33,72 @@ int TST_TOTAL = 3;
 #include <libaio.h>
 #include <errno.h>
 #include <string.h>
+#include <fcntl.h>
+
+#define TESTFILE	"testfile"
 
 static void cleanup(void)
 {
 	TEST_CLEANUP;
+
+	tst_rmdir();
 }
 
 static void setup(void)
 {
+	int fd;
+
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	fd = open(TESTFILE, O_CREAT|O_RDWR, 0755);
+	if (fd == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "open");
+	if (close(fd) == -1)
+		tst_brkm(TBROK|TERRNO, cleanup, "close");
+}
+
+static void check_result(long exp, long act)
+{
+	if (exp >= 0) {
+		if (act == exp)
+			tst_resm(TPASS, "expected success - "
+					"returned value = %ld", act);
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s",
+					act, strerror(-1 * act));
+		return;
+	}
+
+	/* if return value is expected to be < 0 */
+	if (act == exp)
+		tst_resm(TPASS, "expected failure - "
+				"returned value = %ld : %s",
+				act, strerror(-1 * act));
+	else if (act == 0)
+		tst_resm(TFAIL, "call succeeded unexpectedly");
+	else
+		tst_resm(TFAIL, "unexpected failure - "
+				"returned value = %ld : %s, "
+				"expected value = %ld : %s",
+				act, strerror(-1 * act),
+				exp, strerror(-1 * exp));
 }
 
-/*
-   DESCRIPTION
-   io_submit() queues nr I/O request blocks for processing in the AIO con-
-   text ctx_id.  iocbpp should be an array of nr AIO request blocks, which
-   will be submitted to context ctx_id.
-
-   RETURN VALUE
-   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[])
 {
 	int lc;
 	char *msg;
 
-	long expected_return;
-
-	int rval;
+	int rval, fd;
 	char buf[256];
 	struct iocb iocb;
 	struct iocb *iocbs[1];
-	
+
 	io_context_t ctx;
 
 	memset(&ctx, 0, sizeof(ctx));
@@ -87,87 +111,73 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
 
-		expected_return = -EINVAL;
+		/* 1 - EINVAL */
+		/* 1.1 - EINVAL: invalid ctx */
 		TEST(io_submit(ctx, 0, 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);
-		}
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 1.2 - EINVAL: invalid nr */
+		rval = io_setup(1, &ctx);
+		if (rval != 0)
+			tst_brkm(TBROK, cleanup, "io_setup failed: %d", rval);
+		TEST(io_submit(ctx, -1, NULL));
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 1.3 - EINVAL: uninitialized iocb */
+		iocbs[0] = &iocb;
+		TEST(io_submit(ctx, 1, iocbs));
+		check_result(-EINVAL, TEST_RETURN);
+
+		/* 2 - EFAULT: iocb points to invalid data */
+		TEST(io_submit(ctx, 1, (struct iocb **)-1));
+		check_result(-EFAULT, TEST_RETURN);
 
 		/*
-		   EFAULT One of the data structures points to invalid data.
+		 * 3 - 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.
 		 */
-		expected_return = -EFAULT;
-		TEST(io_submit(ctx, 1, (void *)-1));
-		if (TEST_RETURN == 0) {
+		TEST(io_submit(ctx, -1, (struct iocb **)-1));
+		if (TEST_RETURN == 0)
 			tst_resm(TFAIL, "call succeeded unexpectedly");
-		} else if (TEST_RETURN == expected_return) {
+		else if (TEST_RETURN == -EFAULT
+				|| TEST_RETURN == -EINVAL)
 			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);
-		}
-
-		/* 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));
-			}
-
-		}
+					"returned value = %ld : %s",
+					TEST_RETURN, strerror(-1 * TEST_RETURN));
+		else
+			tst_resm(TFAIL, "unexpected failure - "
+					"returned value = %ld : %s, "
+					"expected = %d : %s or %d : %s",
+					TEST_RETURN, strerror(-1 * TEST_RETURN),
+					-EFAULT, strerror(EFAULT),
+					-EINVAL, strerror(EINVAL));
 
 		/*
-		   EBADF  The file descriptor specified in the first iocb is invalid.
+		 * 4 - EBADF: fd in iocb is invalid
 		 */
-		expected_return = -EBADF;
-		io_prep_pread(&iocb, -1, (void *)buf, sizeof(buf), 0);
+		io_prep_pread(&iocb, -1, 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));
+		check_result(-EBADF, TEST_RETURN);
 
+		/* 5 - Positive test: nr == 0 */
+		TEST(io_submit(ctx, 0, NULL));
+		check_result(0, TEST_RETURN);
+
+		/* 6 - Positive test: valid fd */
+		fd = open(TESTFILE, O_RDONLY);
+		if (fd == -1)
+			tst_resm(TBROK|TERRNO, "open");
+		io_prep_pread(&iocb, fd, buf, sizeof(buf), 0);
+		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);
-		}
+		check_result(1, TEST_RETURN);
+		if (close(fd) == -1)
+			tst_resm(TBROK|TERRNO, "close");
+
 	}
 	cleanup();
 

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reviewed-by on v4 1/1
#10 lore raw
Quoted 24 lines

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  :  expected success - returned value = 0
io_submit01    8  TPASS  :  expected success - returned value = 1
Quoted 9 lines

v2: use tempfile instead of read /etc/fstab directly
v3: add a function to check results
v4: code style improvement

---
 testcases/kernel/syscalls/io_submit/io_submit01.c |  190 +++++++++++----------
 1 files changed, 100 insertions(+), 90 deletions(-)

Looks good.

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#11 lore raw
In reply to Caspar Zhang

Hi!
I personally wouldn't feel the need to comment that there is return in check_result() but as it is it's good enough.

Commited, thanks.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list