public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] diotest: set errno with zero before test with zero
@ 2014-12-05 10:47 Zorro Lang
  2014-12-08 11:53 ` Cyril Hrubis
  2014-12-08 13:43 ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Zorro Lang @ 2014-12-05 10:47 UTC (permalink / raw)
  To: ltp-list

some code logic in diotest4.c likes below:
----
    ret = lseek(fd, offset, SEEK_SET);
    if ((ret >= 0) || (errno != EINVAL)) {
        tst_resm(TFAIL, "lseek allows negative offset. returns %d:%s", ret, strerror(errno));
        failed = TRUE;
        fail_count++;
    } else
        tst_resm(TPASS, "Negative Offset");

    ....
    ....

    ret = read(fd, buf, count);
    if (ret >= 0 || errno != errnum) {
        tst_resm(TFAIL, "read allows %s. returns %d: %s", msg, ret, strerror(errno));
        l_fail = TRUE;
    }
----

If lseek() EINVAL and read() return >= 0, the errno will not be setted to 0. The
errno will still be EINVAL.

I hit this problem when test on nfs. In NFS, lseek() return EINVAL as excepted,
but the read() will return 1, when count = 1. But the errno is still EINVAL.
That's incorrect.

So I set errno = 0, before read() and all other functions which like this.

Signed-off-by: Zorro Lang <zlang@redhat.com>
---

Hi,

The problem likes above commit messge. Please review.

Thank you,
Zorro Lang

 testcases/kernel/io/direct_io/diotest4.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/testcases/kernel/io/direct_io/diotest4.c b/testcases/kernel/io/direct_io/diotest4.c
index fa90a1e..82c5b33 100644
--- a/testcases/kernel/io/direct_io/diotest4.c
+++ b/testcases/kernel/io/direct_io/diotest4.c
@@ -107,6 +107,7 @@ runtest_f(int fd, char *buf, int offset, int count, int errnum, int testnum,
 			l_fail = TRUE;
 		}
 	} else {
+		errno = 0;
 		ret = read(fd, buf, count);
 		if (ret >= 0 || errno != errnum) {
 			tst_resm(TFAIL, "read allows %s. returns %d: %s",
@@ -121,6 +122,7 @@ runtest_f(int fd, char *buf, int offset, int count, int errnum, int testnum,
 			l_fail = TRUE;
 		}
 	} else {
+		errno = 0;
 		ret = write(fd, buf, count);
 		if (ret >= 0 || errno != errnum) {
 			tst_resm(TFAIL, "write allows %s.returns %d: %s",
@@ -247,6 +249,7 @@ int main(int argc, char *argv[])
 	/* Test-1: Negative Offset */
 	offset = -1;
 	count = bufsize;
+	errno = 0;
 	ret = lseek(fd, offset, SEEK_SET);
 	if ((ret >= 0) || (errno != EINVAL)) {
 		tst_resm(TFAIL, "lseek allows negative offset. returns %d:%s",
@@ -284,6 +287,7 @@ int main(int argc, char *argv[])
 		fail_count++;
 		tst_resm(TFAIL, "Read beyond the file size");
 	} else {
+		errno = 0;
 		ret = read(fd, buf2, count);
 		if (ret > 0 || (ret < 0 && errno != EINVAL)) {
 			tst_resm(TFAIL,
@@ -392,6 +396,7 @@ int main(int argc, char *argv[])
 		failed = TRUE;
 		fail_count++;
 	} else {
+		errno = 0;
 		ret = read(fd, buf2, count);
 		if (ret >= 0 || errno != EBADF) {
 			tst_resm(TFAIL,
@@ -417,6 +422,7 @@ int main(int argc, char *argv[])
 		failed = TRUE;
 		fail_count++;
 	} else {
+		errno = 0;
 		ret = write(fd, buf2, count);
 		if (ret >= 0 || errno != EBADF) {
 			tst_resm(TFAIL,
@@ -460,6 +466,7 @@ int main(int argc, char *argv[])
 			 strerror(errno));
 		l_fail = TRUE;
 	} else {
+		errno = 0;
 		ret = read(fd, (char *)((ulong) ADDRESS_OF_MAIN & pagemask),
 			 count);
 		if (ret >= 0 || errno != EFAULT) {
-- 
1.9.3


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-12-08 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-05 10:47 [LTP] [PATCH] diotest: set errno with zero before test with zero Zorro Lang
2014-12-08 11:53 ` Cyril Hrubis
     [not found]   ` <648997700.14823290.1418040193631.JavaMail.zimbra@redhat.com>
2014-12-08 12:13     ` Cyril Hrubis
2014-12-08 13:43 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox