From: Caspar Zhang <czhang@redhat.com>
To: LTP List <ltp-list@lists.sourceforge.net>
Subject: [LTP] [PATCH v2] [syscalls] io_submit: fix broken testcase
Date: Thu, 7 Apr 2011 15:31:28 +0800 [thread overview]
Message-ID: <1302161488-12997-1-git-send-email-czhang@redhat.com> (raw)
In-Reply-To: <20110401144407.GA24854@saboteur.suse.cz>
[-- 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
next prev parent reply other threads:[~2011-04-07 7:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Caspar Zhang [this message]
2011-04-12 8:06 ` [LTP] [PATCH v2] " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302161488-12997-1-git-send-email-czhang@redhat.com \
--to=czhang@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.