* [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* Re: [LTP] [PATCH] [syscalls] io_submit: fix broken testcase
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
1 sibling, 0 replies; 12+ messages in thread
From: Caspar Zhang @ 2011-03-27 14:04 UTC (permalink / raw)
To: ltp-list; +Cc: czhang, emcnabb
Sorry, there are some trailing whitespace in the patch, please ignore
this one, I'll workout a newer version.
On 03/27/2011 09:41 PM, czhang@redhat.com 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
>
> Signed-off-by: Caspar Zhang <czhang@redhat.com>
> ---
> testcases/kernel/syscalls/io_submit/io_submit01.c | 143 ++++++++++++++-------
> 1 files changed, 98 insertions(+), 45 deletions(-)
>
--
/---------------------------------------\
| 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [PATCH] [syscalls] io_submit: fix broken testcase
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
1 sibling, 1 reply; 12+ messages in thread
From: czhang @ 2011-03-27 14:13 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: 1591 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 | 147 ++++++++++++++-------
1 files changed, 101 insertions(+), 46 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: 6943 bytes --]
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..fc9fc1c 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -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();
[-- 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* Re: [LTP] [PATCH] [syscalls] io_submit: fix broken testcase
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
0 siblings, 2 replies; 12+ messages in thread
From: Cyril Hrubis @ 2011-04-01 14:44 UTC (permalink / raw)
To: czhang; +Cc: ltp-list, emcnabb
Hi!
> + /* 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);
> + }
> +
I would preffer to write a function that does this instead of copying
this code block several times.
> 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...
> @@ -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));
Here too.
> + 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);
The void cast is not needed here. Generally all pointers in C are
compatible with void * pointer and casted automatically.
> 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);
Hmm, I would preffer to create temporary file for this rather than
relying on that some magical file exists in system.
> + if (fd == -1)
> + tst_resm(TBROK, "open /etc/fstab fail");
> + io_prep_pread(&iocb, fd, (void *)buf, sizeof(buf), 0);
The cast again.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread* [LTP] [PATCH v2] [syscalls] io_submit: fix broken testcase
2011-04-01 14:44 ` Cyril Hrubis
@ 2011-04-07 7:31 ` Caspar Zhang
2011-04-12 8:06 ` Caspar Zhang
1 sibling, 0 replies; 12+ messages in thread
From: Caspar Zhang @ 2011-04-07 7:31 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 1621 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 : expected success - returned value = 0
io_submit01 8 TPASS : expected success - returned value = 1
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/io_submit/io_submit01.c | 208 +++++++++++----------
1 files changed, 109 insertions(+), 99 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-syscalls-io_submit-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscalls-io_submit-fix-broken-testcase.patch", Size: 7314 bytes --]
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..cd94649 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -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[])
{
[-- Attachment #3: Type: text/plain, Size: 250 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: 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* [LTP] [PATCH v2] [syscalls] io_submit: fix broken testcase
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
1 sibling, 1 reply; 12+ messages in thread
From: Caspar Zhang @ 2011-04-12 8:06 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 1757 bytes --]
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
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/io_submit/io_submit01.c | 208 +++++++++++----------
1 files changed, 109 insertions(+), 99 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-syscalls-io_submit-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscalls-io_submit-fix-broken-testcase.patch", Size: 7314 bytes --]
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..cd94649 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -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[])
{
[-- Attachment #3: Type: text/plain, Size: 434 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: 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* Re: [LTP] [PATCH v2] [syscalls] io_submit: fix broken testcase
2011-04-12 8:06 ` Caspar Zhang
@ 2011-04-13 17:33 ` Cyril Hrubis
2011-04-14 3:33 ` [LTP] [PATCH v3] " Caspar Zhang
0 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2011-04-13 17:33 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
Hi!
> -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));\
> + } \
> }
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.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread* [LTP] [PATCH v3] [syscalls] io_submit: fix broken testcase
2011-04-13 17:33 ` Cyril Hrubis
@ 2011-04-14 3:33 ` Caspar Zhang
2011-04-14 14:44 ` Cyril Hrubis
0 siblings, 1 reply; 12+ messages in thread
From: Caspar Zhang @ 2011-04-14 3:33 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 1710 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 : 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
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/io_submit/io_submit01.c | 189 +++++++++++----------
1 files changed, 99 insertions(+), 90 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-syscalls-io_submit-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscalls-io_submit-fix-broken-testcase.patch", Size: 7031 bytes --]
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..82cb1a2 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -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();
[-- Attachment #3: Type: text/plain, Size: 438 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: 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* Re: [LTP] [PATCH v3] [syscalls] io_submit: fix broken testcase
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
0 siblings, 1 reply; 12+ messages in thread
From: Cyril Hrubis @ 2011-04-14 14:44 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
Hi!
> +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));
> + }
> }
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.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread* [LTP] [PATCH v4] [syscalls] io_submit: fix broken testcase
2011-04-14 14:44 ` Cyril Hrubis
@ 2011-04-14 14:28 ` Caspar Zhang
2011-04-14 14:46 ` Masatake YAMATO
2011-04-14 16:33 ` Cyril Hrubis
0 siblings, 2 replies; 12+ messages in thread
From: Caspar Zhang @ 2011-04-14 14:28 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 1738 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 : 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
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/io_submit/io_submit01.c | 190 +++++++++++----------
1 files changed, 100 insertions(+), 90 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-syscalls-io_submit-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-syscalls-io_submit-fix-broken-testcase.patch", Size: 7065 bytes --]
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 44580e6..da15aa0 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -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();
[-- Attachment #3: Type: text/plain, Size: 438 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: 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* Re: [LTP] [PATCH v4] [syscalls] io_submit: fix broken testcase
2011-04-14 14:28 ` [LTP] [PATCH v4] " Caspar Zhang
@ 2011-04-14 14:46 ` Masatake YAMATO
2011-04-14 16:33 ` Cyril Hrubis
1 sibling, 0 replies; 12+ messages in thread
From: Masatake YAMATO @ 2011-04-14 14:46 UTC (permalink / raw)
To: czhang; +Cc: ltp-list
>
> 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
>
> Signed-off-by: Caspar Zhang <czhang@redhat.com>
> ---
> testcases/kernel/syscalls/io_submit/io_submit01.c | 190 +++++++++++----------
> 1 files changed, 100 insertions(+), 90 deletions(-)
>
Looks good.
Reviewed-by: Masatake YAMATO <yamato@redhat.com>
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [LTP] [PATCH v4] [syscalls] io_submit: fix broken testcase
2011-04-14 14:28 ` [LTP] [PATCH v4] " Caspar Zhang
2011-04-14 14:46 ` Masatake YAMATO
@ 2011-04-14 16:33 ` Cyril Hrubis
1 sibling, 0 replies; 12+ messages in thread
From: Cyril Hrubis @ 2011-04-14 16:33 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
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.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [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.