Skip to contentSkip to conversation

regression test for 64bit sendfile capped at 2G

RFC PATCH In review Han Pingtian 4 participants 13 messages Jul 4, 2014 – Jul 15, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 regression test for 64bit sendfile capped at 2G

Hi,

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 testcases/kernel/syscalls/sendfile/sendfile09.c | 245 ++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
testcases/kernel/syscalls/sendfile/sendfile09.c new file +245 -0
new file mode 100644
index 0000000..d88a72f
@@ -0,0 +1,245 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * NAME
+ *	sendfile09.c
+ *
+ * DESCRIPTION
+ *	Testcase copied from sendfile02.c to test the basic functionality of the sendfile(2) system call on large file.
+ *
+ * ALGORITHM
+ *	1. call sendfile(2) with offset = 0
+ *	2. call sendfile(2) with offset in the middle of the file
+ *
+ * USAGE:  <for command-line>
+ *  sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
+ *     where,
+ *             -i n : Execute test n times.
+ *             -I x : Execute test for x seconds.
+ *             -P x : Pause for x seconds between iterations.
+ *             -t   : Turn on syscall timing.
+ *
+ *
+ * RESTRICTIONS
+ *	Only supports 64bit systems and kernel 2.6.33 or above
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "usctest.h"
+#include "test.h"
+
+#ifndef OFF_T
+#define OFF_T off_t
+#endif /* Not def: OFF_T */
+
+TCID_DEFINE(sendfile09);
+int TST_TOTAL = 4;
+
+char in_file[100];
+char out_file[100];
+int out_fd;
+
+void cleanup(void);
+void setup(void);
+
+struct test_case_t {
+	char *desc;
+	int offset;
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} testcases[] = {
+	{
+	"Test sendfile(2) with offset = 0", 0, 4294967296, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 2, 4294967294, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 4, 4294967292, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 6, 4294967290, 4294967296}
+};
+
+#ifdef UCLINUX
+static char *argv0;
+#endif
+
+void do_sendfile(OFF_T offset, int i)
+{
+	int in_fd;
+	struct stat sb;
+	int wait_status;
+	int wait_stat;
+	off_t before_pos, after_pos;
+
+	if ((out_fd = open(out_file, O_WRONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}
+
+	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}
+
+	if (stat(in_file, &sb) < 0) {
+		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
+	}
+
+	if ((before_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek before invoking sendfile failed: %d", errno);
+	}
+
+	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+
+	if (TEST_RETURN == -1) {
+		tst_brkm(TBROK, cleanup, "sendfile(2) failed: %s",
+			strerror(TEST_RETURN));
+	}
+
+	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek after invoking sendfile failed: %d", errno);
+	}
+
+	if (TEST_RETURN != testcases[i].exp_retval) {
+		tst_resm(TFAIL, "sendfile(2) failed to return "
+			 "expected value, expected: %" PRId64 ", "
+			 "got: %" PRId64, testcases[i].exp_retval,
+			 TEST_RETURN);
+	} else if (offset != testcases[i].exp_updated_offset) {
+		tst_resm(TFAIL, "sendfile(2) failed to update "
+			 "OFFSET parameter to expected value, "
+			 "expected: %" PRId64 ", got: %" PRId64,
+			 testcases[i].exp_updated_offset,
+			 (int64_t) offset);
+	} else if (before_pos != after_pos) {
+		tst_resm(TFAIL, "sendfile(2) updated the file position "
+			 " of in_fd unexpectedly, expected file position: %"
+			 PRId64 ", " " actual file position %" PRId64,
+			 (int64_t) before_pos, (int64_t) after_pos);
+	} else {
+		tst_resm(TPASS, "functionality of sendfile() is "
+			 "correct");
+		wait_status = waitpid(-1, &wait_stat, 0);
+	}
+
+	close(in_fd);
+	close(out_fd);
+}
+
+/*
+ * setup() - performs all ONE TIME setup for this test.
+ */
+void setup(void)
+{
+	int fd;
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	/* make a temporary directory and cd to it */
+	tst_tmpdir();
+	sprintf(in_file, "in.%d", getpid());
+	if ((fd = creat(in_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+
+	/* create a 4G file */
+	for (i = 1; i <= (4 * 1024); i++) {
+		if (lseek(fd, (1024 * 1024 - 1), SEEK_CUR) < 0) {
+			tst_brkm(TBROK, cleanup, "lseek failed, errno: %d", errno);
+		}
+
+		if (write(fd, "C", 1) < 0) {
+			tst_brkm(TBROK, cleanup, "write failed, errno: %d", errno);
+		}
+	}
+
+	close(fd);
+	sprintf(out_file, "out.%d", getpid());
+	if ((fd = creat(out_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+	close(fd);
+}
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ *	       completion or premature exit.
+ */
+void cleanup(void)
+{
+	/*
+	 * print timing stats if that option was specified.
+	 * print errno log if that option was specified.
+	 */
+	TEST_CLEANUP;
+
+	close(out_fd);
+	/* delete the test directory created in setup() */
+	tst_rmdir();
+
+}
+
+int main(int ac, char **av)
+{
+	int i;
+	int lc;
+	const char *msg;		/* parse_opts() return message */
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#endif
+
+	if (tst_kvercmp(2, 6, 33) < 0) {
+		tst_resm(TINFO, "sendfile(2) on large file skipped for kernels < 2.6.33");
+		return;
+	}
+
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+	}
+#ifdef UCLINUX
+	argv0 = av[0];
+#endif
+
+	setup();
+
+	/*
+	 * The following loop checks looping state if -c option given
+	 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; ++i) {
+			do_sendfile(testcases[i].offset, i);
+		}
+	}
+	cleanup();
+
+	tst_exit();
+}
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi,

Quoted 7 lines · Han Pingtian

Hi,

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

I'd like to ask an irrelevant question about that where can we get such bug report or similar issues about syscalls from a stable place(url), or how did you found this issue, thanks.

Give that currently there are 1039 test cases about syscalls in LTP(cat runtest/syscalls | grep -v "^#" | sed -e '/^$/d' | wc -l), we can tell that syscalls is a very big test suite in LTP, so I'd like to add all similar regression test about syscalls to LTP, which will expand ltp's test coverage, thanks.

Regards,
Xiaoguang Wang

Quoted 250 lines

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 testcases/kernel/syscalls/sendfile/sendfile09.c | 245 ++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
testcases/kernel/syscalls/sendfile/sendfile09.c new file +235 -0
new file mode 100644
index 0000000..d88a72f
@@ -0,0 +1,245 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * NAME
+ *	sendfile09.c
+ *
+ * DESCRIPTION
+ *	Testcase copied from sendfile02.c to test the basic functionality of the sendfile(2) system call on large file.
+ *
+ * ALGORITHM
+ *	1. call sendfile(2) with offset = 0
+ *	2. call sendfile(2) with offset in the middle of the file
+ *
+ * USAGE:  <for command-line>
+ *  sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
+ *     where,
+ *             -i n : Execute test n times.
+ *             -I x : Execute test for x seconds.
+ *             -P x : Pause for x seconds between iterations.
+ *             -t   : Turn on syscall timing.
+ *
+ *
+ * RESTRICTIONS
+ *	Only supports 64bit systems and kernel 2.6.33 or above
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "usctest.h"
+#include "test.h"
+
+#ifndef OFF_T
+#define OFF_T off_t
+#endif /* Not def: OFF_T */
+
+TCID_DEFINE(sendfile09);
+int TST_TOTAL = 4;
+
+char in_file[100];
+char out_file[100];
+int out_fd;
+
+void cleanup(void);
+void setup(void);
+
+struct test_case_t {
+	char *desc;
+	int offset;
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} testcases[] = {
+	{
+	"Test sendfile(2) with offset = 0", 0, 4294967296, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 2, 4294967294, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 4, 4294967292, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 6, 4294967290, 4294967296}
+};
+
+#ifdef UCLINUX
+static char *argv0;
+#endif
+
+void do_sendfile(OFF_T offset, int i)
+{
+	int in_fd;
+	struct stat sb;
+	int wait_status;
+	int wait_stat;
+	off_t before_pos, after_pos;
+
+	if ((out_fd = open(out_file, O_WRONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}
+
+	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}
+
+	if (stat(in_file, &sb) < 0) {
+		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
+	}
+
+	if ((before_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek before invoking sendfile failed: %d", errno);
+	}
+
+	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+
+	if (TEST_RETURN == -1) {
+		tst_brkm(TBROK, cleanup, "sendfile(2) failed: %s",
+			strerror(TEST_RETURN));
+	}
+
+	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek after invoking sendfile failed: %d", errno);
+	}
+
+	if (TEST_RETURN != testcases[i].exp_retval) {
+		tst_resm(TFAIL, "sendfile(2) failed to return "
+			 "expected value, expected: %" PRId64 ", "
+			 "got: %" PRId64, testcases[i].exp_retval,
+			 TEST_RETURN);
+	} else if (offset != testcases[i].exp_updated_offset) {
+		tst_resm(TFAIL, "sendfile(2) failed to update "
+			 "OFFSET parameter to expected value, "
+			 "expected: %" PRId64 ", got: %" PRId64,
+			 testcases[i].exp_updated_offset,
+			 (int64_t) offset);
+	} else if (before_pos != after_pos) {
+		tst_resm(TFAIL, "sendfile(2) updated the file position "
+			 " of in_fd unexpectedly, expected file position: %"
+			 PRId64 ", " " actual file position %" PRId64,
+			 (int64_t) before_pos, (int64_t) after_pos);
+	} else {
+		tst_resm(TPASS, "functionality of sendfile() is "
+			 "correct");
+		wait_status = waitpid(-1, &wait_stat, 0);
+	}
+
+	close(in_fd);
+	close(out_fd);
+}
+
+/*
+ * setup() - performs all ONE TIME setup for this test.
+ */
+void setup(void)
+{
+	int fd;
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	/* make a temporary directory and cd to it */
+	tst_tmpdir();
+	sprintf(in_file, "in.%d", getpid());
+	if ((fd = creat(in_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+
+	/* create a 4G file */
+	for (i = 1; i <= (4 * 1024); i++) {
+		if (lseek(fd, (1024 * 1024 - 1), SEEK_CUR) < 0) {
+			tst_brkm(TBROK, cleanup, "lseek failed, errno: %d", errno);
+		}
+
+		if (write(fd, "C", 1) < 0) {
+			tst_brkm(TBROK, cleanup, "write failed, errno: %d", errno);
+		}
+	}
+
+	close(fd);
+	sprintf(out_file, "out.%d", getpid());
+	if ((fd = creat(out_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+	close(fd);
+}
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ *	       completion or premature exit.
+ */
+void cleanup(void)
+{
+	/*
+	 * print timing stats if that option was specified.
+	 * print errno log if that option was specified.
+	 */
+	TEST_CLEANUP;
+
+	close(out_fd);
+	/* delete the test directory created in setup() */
+	tst_rmdir();
+
+}
+
+int main(int ac, char **av)
+{
+	int i;
+	int lc;
+	const char *msg;		/* parse_opts() return message */
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#endif
+
+	if (tst_kvercmp(2, 6, 33) < 0) {
+		tst_resm(TINFO, "sendfile(2) on large file skipped for kernels < 2.6.33");
+		return;
+	}
+
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+	}
+#ifdef UCLINUX
+	argv0 = av[0];
+#endif
+
+	setup();
+
+	/*
+	 * The following loop checks looping state if -c option given
+	 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {

testcases/kernel/syscalls/sendfile/sendfile09.c line 245

Quoted 10 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +10 -0
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; ++i) {
+			do_sendfile(testcases[i].offset, i);
+		}
+	}
+	cleanup();
+
+	tst_exit();
+}

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
Quoted 14 lines · Xiaoguang Wang

Hi,

Quoted 7 lines · Han Pingtian

Hi,

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

I'd like to ask an irrelevant question about that where can we get such bug report or similar issues about syscalls from a stable place(url), or how did you found this issue, thanks.

Quoted 7 lines

Give that currently there are 1039 test cases about syscalls in LTP(cat runtest/syscalls | grep -v "^#" | sed -e '/^$/d' | wc -l), we can tell that syscalls is a very big test suite in LTP, so I'd like to add all similar regression test about syscalls to LTP, which will expand ltp's test coverage, thanks.

Regards,
Xiaoguang Wang

Thanks for your reply. I knew this problem just by accidental. It wasn't found by me, but someone else. We are asked why we couldn't find it at first time though we had run ltp to test the syscalls. So I think it would be better to include a regession test for it to ltp. I think we can find out all those regressions by mointoring bug report web site and kernel's mailing list and something like these.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Hi,

Quoted 22 lines · Han Pingtian
Quoted 14 lines · Xiaoguang Wang

Hi,

Quoted 7 lines · Han Pingtian

Hi,

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

I'd like to ask an irrelevant question about that where can we get such bug report or similar issues about syscalls from a stable place(url), or how did you found this issue, thanks.

Quoted 7 lines

Give that currently there are 1039 test cases about syscalls in LTP(cat runtest/syscalls | grep -v "^#" | sed -e '/^$/d' | wc -l), we can tell that syscalls is a very big test suite in LTP, so I'd like to add all similar regression test about syscalls to LTP, which will expand ltp's test coverage, thanks.

Regards,
Xiaoguang Wang

Quoted 6 lines

Thanks for your reply. I knew this problem just by accidental. It wasn't found by me, but someone else. We are asked why we couldn't find it at first time though we had run ltp to test the syscalls. So I think it would be better to include a regession test for it to ltp. I think we can find out all those regressions by mointoring bug report web site and kernel's mailing list and something like these.

Yeah, kernel mail list would be the best place to find such issues, but usually it needs more time to figure them out :)

As for you patch, I don't know whether you have read the test-writing-guidelines.txt first, if not, please see https://github.com/linux-test-project/ltp/blob/master/doc/test-writing-guidelines.txt.
For example, there are already many safe_* in ltp, you can use them, which will simplify your error checking, thanks.

Regards,
Xiaoguang Wang

Quoted 13 lines

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
Quoted 35 lines · Xiaoguang Wang

Hi,

Quoted 22 lines · Han Pingtian
Quoted 14 lines · Xiaoguang Wang

Hi,

Quoted 7 lines · Han Pingtian

Hi,

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

I'd like to ask an irrelevant question about that where can we get such bug report or similar issues about syscalls from a stable place(url), or how did you found this issue, thanks.

Quoted 7 lines

Give that currently there are 1039 test cases about syscalls in LTP(cat runtest/syscalls | grep -v "^#" | sed -e '/^$/d' | wc -l), we can tell that syscalls is a very big test suite in LTP, so I'd like to add all similar regression test about syscalls to LTP, which will expand ltp's test coverage, thanks.

Regards,
Xiaoguang Wang

Quoted 6 lines

Thanks for your reply. I knew this problem just by accidental. It wasn't found by me, but someone else. We are asked why we couldn't find it at first time though we had run ltp to test the syscalls. So I think it would be better to include a regession test for it to ltp. I think we can find out all those regressions by mointoring bug report web site and kernel's mailing list and something like these.

Yeah, kernel mail list would be the best place to find such issues, but usually it needs more time to figure them out :)

Quoted 6 lines

As for you patch, I don't know whether you have read the test-writing-guidelines.txt first, if not, please see https://github.com/linux-test-project/ltp/blob/master/doc/test-writing-guidelines.txt.
For example, there are already many safe_* in ltp, you can use them, which will simplify your error checking, thanks.

Regards,
Xiaoguang Wang

I have modified the patch according to this guide. Please take a look. Thanks.

From 15dbd7f21332cb7b08699be035c91bfdea31b6c0 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Thu, 3 Jul 2014 15:29:35 +0800
Subject: [PATCH] regression test for 64bit sendfile capped at 2G

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/sendfile/sendfile09.c | 239 ++++++++++++++++++++++++
 2 files changed, 241 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
runtest/syscalls +2 -0
index 66d6a65..fbed9cb 100644
@@ -937,6 +937,8 @@ sendfile07 sendfile07
 sendfile07_64 sendfile07_64
 sendfile08 sendfile08
 sendfile08_64 sendfile08_64
+sendfile09 sendfile09
+sendfile09_64 sendfile09_64
 
 
 sendmsg01 sendmsg01
testcases/kernel/syscalls/sendfile/sendfile09.c new file +239 -0

239 lines not on this page · raw message

Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw
In reply to Xiaoguang Wang

Hi!

Quoted 8 lines
Quoted 5 lines

Please review this patch. Thanks.

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

I'd like to ask an irrelevant question about that where can we get such bug report or similar issues about syscalls from a stable place(url), or how did you found this issue, thanks.

This is IMHO most problematic part of producing LTP testcases. There is no single place to pickup kernel regression/bug reports and produce testcases for them. This is partly caused by the nature of how the community works and partly because nobody cared about this (this happens to change slowly now).

Quoted 3 lines

Give that currently there are 1039 test cases about syscalls in LTP(cat runtest/syscalls | grep -v "^#" | sed -e '/^$/d' | wc -l), we can tell that syscalls is a very big test suite in LTP, so I'd like to add all similar regression test about syscalls to LTP, which will expand ltp's test coverage, thanks.

And we don't have 100% coverage either, there are numerous syscalls/ioctls/... that are not even documented properly.

But at least new syscalls along with documentation and example source code are starting to appear on linux-api mailing list.

See also:

https://www.kernel.org/doc/man-pages/maintaining.html

which lists various sources where to get information about kernel/libc interfaces.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#6 lore raw
In reply to Han Pingtian

----- Original Message -----

Quoted 8 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Friday, 4 July, 2014 5:16:41 AM
Subject: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at 2G

Hi,

Please review this patch. Thanks.

Hi,

Quoted 7 lines

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

Missing Signed-off-by: line(s)

Quoted 39 lines
---
 testcases/kernel/syscalls/sendfile/sendfile09.c | 245
 ++++++++++++++++++++++++
 1 file changed, 245 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
testcases/kernel/syscalls/sendfile/sendfile09.c new file +17 -0
new file mode 100644
index 0000000..d88a72f
@@ -0,0 +1,245 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

02110-1301 USA
+ */

testcases/kernel/syscalls/sendfile/sendfile09.c new file +7 -0
+
+/*
+ * NAME
+ *	sendfile09.c
+ *
+ * DESCRIPTION
+ *	Testcase copied from sendfile02.c to test the basic functionality of the
Quoted 1 line

sendfile(2) system call on large file.

^^ this line is too long. You can also reference relevant commit ids, which introduce/fix the problem.

Quoted 17 lines

+ *
+ * ALGORITHM
+ * 1. call sendfile(2) with offset = 0
+ * 2. call sendfile(2) with offset in the middle of the file
+ *
+ * USAGE: <for command-line>
+ * sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
+ * where,

+ *             -i n : Execute test n times.
+ *             -I x : Execute test for x seconds.
+ *             -P x : Pause for x seconds between iterations.
+ *             -t   : Turn on syscall timing.

+ *
+ *
+ * RESTRICTIONS
+ * Only supports 64bit systems and kernel 2.6.33 or above
+ */

testcases/kernel/syscalls/sendfile/sendfile09.c line 49

Quoted 7 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +7 -0
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <sys/types.h>
+#include <sys/wait.h>

Is wait.h/waitpid() needed? (see below)

testcases/kernel/syscalls/sendfile/sendfile09.c line 61

Quoted 12 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +12 -0
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "usctest.h"
+#include "test.h"
+
+#ifndef OFF_T
+#define OFF_T off_t
+#endif /* Not def: OFF_T */
+
+TCID_DEFINE(sendfile09);
+int TST_TOTAL = 4;

Please use ARRAY_SIZE macro.

testcases/kernel/syscalls/sendfile/sendfile09.c line 68

Quoted 7 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +7 -0
+
+char in_file[100];
+char out_file[100];
+int out_fd;
+
+void cleanup(void);
+void setup(void);

Please make all above static.

testcases/kernel/syscalls/sendfile/sendfile09.c line 72

Quoted 4 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +4 -0
+
+struct test_case_t {
+	char *desc;
+	int offset;

Shouldn't this be OFF_T?

Quoted 11 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +6 -0
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} testcases[] = {
+	{
+	"Test sendfile(2) with offset = 0", 0, 4294967296, 4294967296}, {
+	"Test sendfile(2) with offset in the middle of file", 2, 4294967294,

4294967296}, {

testcases/kernel/syscalls/sendfile/sendfile09.c new file +1 -0
+	"Test sendfile(2) with offset in the middle of file", 4, 4294967292,

4294967296}, {

testcases/kernel/syscalls/sendfile/sendfile09.c new file +1 -0
+	"Test sendfile(2) with offset in the middle of file", 6, 4294967290,

4294967296}

These lines are long.
Is it necessary to repeat the test 4 times? Would it be enough to do it twice as suggested in comments above (once with offset 0 and once with offset beyond 2G)?

+ * 1. call sendfile(2) with offset = 0
+ * 2. call sendfile(2) with offset in the middle of the file

testcases/kernel/syscalls/sendfile/sendfile09.c line 92

Quoted 12 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +12 -0
+};
+
+#ifdef UCLINUX
+static char *argv0;
+#endif
+
+void do_sendfile(OFF_T offset, int i)
+{
+	int in_fd;
+	struct stat sb;
+	int wait_status;
+	int wait_stat;

Is wait_status and wait_stat needed? (see below)

testcases/kernel/syscalls/sendfile/sendfile09.c line 97

Quoted 5 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +5 -0
+	off_t before_pos, after_pos;
+
+	if ((out_fd = open(out_file, O_WRONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}

braces {} are not necessary for single statement blocks You can use kernel's scripts/checkpatch.pl to list all instances.

Quoted 9 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +9 -0
+
+	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
+		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
+	}
+
+	if (stat(in_file, &sb) < 0) {
+		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
+	}
+

testcases/kernel/syscalls/sendfile/sendfile09.c line 116

Quoted 10 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +10 -0
+	if ((before_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek before invoking sendfile failed: %d", errno);
+	}
+
+	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+
+	if (TEST_RETURN == -1) {
+		tst_brkm(TBROK, cleanup, "sendfile(2) failed: %s",
+			strerror(TEST_RETURN));

Did you mean stderror(TEST_ERRNO)?

You can use "TBROK | TERRNO" or "TBROK | TTERRNO" instead, that applies for all tst_* calls above and below.

Quoted 17 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +17 -0
+	}
+
+	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
+		tst_brkm(TBROK, cleanup,
+			 "lseek after invoking sendfile failed: %d", errno);
+	}
+
+	if (TEST_RETURN != testcases[i].exp_retval) {
+		tst_resm(TFAIL, "sendfile(2) failed to return "
+			 "expected value, expected: %" PRId64 ", "
+			 "got: %" PRId64, testcases[i].exp_retval,
+			 TEST_RETURN);
+	} else if (offset != testcases[i].exp_updated_offset) {
+		tst_resm(TFAIL, "sendfile(2) failed to update "
+			 "OFFSET parameter to expected value, "
+			 "expected: %" PRId64 ", got: %" PRId64,
+			 testcases[i].exp_updated_offset,

testcases/kernel/syscalls/sendfile/sendfile09.c line 143

Quoted 10 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +10 -0
+			 (int64_t) offset);
+	} else if (before_pos != after_pos) {
+		tst_resm(TFAIL, "sendfile(2) updated the file position "
+			 " of in_fd unexpectedly, expected file position: %"
+			 PRId64 ", " " actual file position %" PRId64,
+			 (int64_t) before_pos, (int64_t) after_pos);
+	} else {
+		tst_resm(TPASS, "functionality of sendfile() is "
+			 "correct");
+		wait_status = waitpid(-1, &wait_stat, 0);

What is this waiting for?

Quoted 9 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +9 -0
+	}
+
+	close(in_fd);
+	close(out_fd);
+}
+
+/*
+ * setup() - performs all ONE TIME setup for this test.
+ */

testcases/kernel/syscalls/sendfile/sendfile09.c line 162

Quoted 10 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +10 -0
+void setup(void)
+{
+	int fd;
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	/* make a temporary directory and cd to it */

you can remove this comment

testcases/kernel/syscalls/sendfile/sendfile09.c line 164

Quoted 2 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +2 -0
+	tst_tmpdir();
+	sprintf(in_file, "in.%d", getpid());

in and out files will be in unique temp directory, adding pid to file names seems unnecessary.

Quoted 46 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +46 -0
+	if ((fd = creat(in_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+
+	/* create a 4G file */
+	for (i = 1; i <= (4 * 1024); i++) {
+		if (lseek(fd, (1024 * 1024 - 1), SEEK_CUR) < 0) {
+			tst_brkm(TBROK, cleanup, "lseek failed, errno: %d", errno);
+		}
+
+		if (write(fd, "C", 1) < 0) {
+			tst_brkm(TBROK, cleanup, "write failed, errno: %d", errno);
+		}
+	}
+
+	close(fd);
+	sprintf(out_file, "out.%d", getpid());
+	if ((fd = creat(out_file, 00700)) < 0) {
+		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
+			 errno);
+	}
+	close(fd);
+}
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ *	       completion or premature exit.
+ */
+void cleanup(void)
+{
+	/*
+	 * print timing stats if that option was specified.
+	 * print errno log if that option was specified.
+	 */
+	TEST_CLEANUP;
+
+	close(out_fd);
+	/* delete the test directory created in setup() */
+	tst_rmdir();
+
+}
+
+int main(int ac, char **av)
+{
+	int i;

testcases/kernel/syscalls/sendfile/sendfile09.c line 220

Quoted 10 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +10 -0
+	int lc;
+	const char *msg;		/* parse_opts() return message */
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#endif
+
+	if (tst_kvercmp(2, 6, 33) < 0) {
+		tst_resm(TINFO, "sendfile(2) on large file skipped for kernels < 2.6.33");
+		return;

return with no value

testcases/kernel/syscalls/sendfile/sendfile09.c line 228

Quoted 8 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +8 -0
+	}
+
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+	}
+#ifdef UCLINUX
+	argv0 = av[0];
+#endif

UCLINUX ifdefs blocks don't appear to be needed any longer.

Regards,
Jan

Quoted 21 lines
testcases/kernel/syscalls/sendfile/sendfile09.c new file +17 -1
+
+	setup();
+
+	/*
+	 * The following loop checks looping state if -c option given
+	 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; ++i) {
+			do_sendfile(testcases[i].offset, i);
+		}
+	}
+	cleanup();
+
+	tst_exit();
+}
--

1.9.3

Quoted 11 lines

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#7 lore raw
Quoted 2 lines · Jan Stancek

Thanks so much. I have changed the patch according to you and Xiaoguang's suggestions. Please have a look.

From 5257dba5a2ce42e55d0ba61c2a6bd5fe30c5c7f7 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Thu, 3 Jul 2014 15:29:35 +0800
Subject: [PATCH] regression test for 64bit sendfile capped at 2G

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/sendfile/sendfile09.c | 233 ++++++++++++++++++++++++
 2 files changed, 235 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
runtest/syscalls +2 -0
index 66d6a65..fbed9cb 100644
@@ -937,6 +937,8 @@ sendfile07 sendfile07
 sendfile07_64 sendfile07_64
 sendfile08 sendfile08
 sendfile08_64 sendfile08_64
+sendfile09 sendfile09
+sendfile09_64 sendfile09_64
 
 
 sendmsg01 sendmsg01
testcases/kernel/syscalls/sendfile/sendfile09.c new file +233 -0

233 lines not on this page · raw message

Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#8 lore raw

----- Original Message -----

Quoted 10 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Tuesday, 8 July, 2014 9:23:08 AM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at 2G

Quoted 2 lines · Jan Stancek

Thanks so much. I have changed the patch according to you and Xiaoguang's suggestions. Please have a look.

Hi,

Below are some small suggestions, mostly to avoid int type related warnings when compiled as 32-bit.

Did you also test this testcase with kernel commit 5d73320a96fcc applied? I tried it with this commit applied on top of RHEL7 GA kernel, but I didn't get the expected result:

sendfile(3, 4, [0], 4294967296) = 2147418112
...
sendfile(3, 4, [2147483648], 2147483648) = 2147418112

Regards,
Jan

testcases/kernel/syscalls/.gitignore +2 -0
index 975c150..b9d49cf 100644
@@ -750,6 +750,8 @@
 /sendfile/sendfile07_64
 /sendfile/sendfile08
 /sendfile/sendfile08_64
+/sendfile/sendfile09
+/sendfile/sendfile09_64
 /sendmsg/sendmsg01
 /sendmsg/sendmsg02
 /sendto/sendto01
testcases/kernel/syscalls/sendfile/sendfile09.c +10 -13
index 1bab702..2b9de40 100644
@@ -54,7 +54,6 @@
 #include "usctest.h"
 #include "test.h"
 #include "safe_macros.h"
-#include "compiler.h"
 
 #ifndef OFF_T
 #define OFF_T off_t
@@ -71,28 +70,27 @@ static int out_fd;
 static void cleanup(void);
 static void setup(void);
 
-struct test_case_t {
+#define TWO_GB (INT64_C(1) << 31)
+#define FOUR_GB (INT64_C(1) << 32)
+
+static struct test_case_t {
        char *desc;
        OFF_T offset;
        int64_t exp_retval;
        int64_t exp_updated_offset;
 } testcases[] = {
        { "Test sendfile(2) with offset = 0",
-           0, 4294967296, 4294967296},
+           0, FOUR_GB, FOUR_GB},
        { "Test sendfile(2) with offset in the middle of file",
-           2147483648, 2147483648, 4294967296}
+           TWO_GB, TWO_GB, FOUR_GB}
 };
 
 int TST_TOTAL = ARRAY_SIZE(testcases);
 
-#ifdef UCLINUX
-static char *argv0;
-#endif
-
 void do_sendfile(OFF_T offset, int i)
 {
        struct stat sb;
-       off_t before_pos, after_pos;
+       OFF_T before_pos, after_pos;
 
        out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
 
@@ -105,14 +103,14 @@ void do_sendfile(OFF_T offset, int i)
        TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
 
        if (TEST_RETURN == -1)
-               tst_brkm(TBROK | TERRNO, cleanup, "sendfile(2) failed");
+               tst_brkm(TBROK | TTERRNO, cleanup, "sendfile(2) failed");
 
        after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
 
        if (TEST_RETURN != testcases[i].exp_retval) {
                tst_resm(TFAIL, "sendfile(2) failed to return "
                         "expected value, expected: %" PRId64 ", "
-                        "got: %" PRId64, testcases[i].exp_retval,
+                        "got: %ld", testcases[i].exp_retval,
                         TEST_RETURN);
        } else if (offset != testcases[i].exp_updated_offset) {
                tst_resm(TFAIL, "sendfile(2) failed to update "
@@ -149,8 +147,7 @@ void setup(void)
        tst_tmpdir();
 
        if (!tst_fs_has_free(NULL, ".", 8, TST_GB)) {
-               cleanup();
-               tst_brkm(TCONF, NULL, "sendfile(2) on large file"
+               tst_brkm(TCONF, cleanup, "sendfile(2) on large file"
                        " needs 8G free space.");
        }
 
Quoted 280 lines
Quoted 3 lines

From 5257dba5a2ce42e55d0ba61c2a6bd5fe30c5c7f7 Mon Sep 17 00:00:00 2001

From: Han Pingtian <[email protected]>
Date: Thu, 3 Jul 2014 15:29:35 +0800
Subject: [PATCH] regression test for 64bit sendfile capped at 2G

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/sendfile/sendfile09.c | 233
 ++++++++++++++++++++++++
 2 files changed, 235 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
runtest/syscalls +2 -0
index 66d6a65..fbed9cb 100644
@@ -937,6 +937,8 @@ sendfile07 sendfile07
 sendfile07_64 sendfile07_64
 sendfile08 sendfile08
 sendfile08_64 sendfile08_64
+sendfile09 sendfile09
+sendfile09_64 sendfile09_64
 
 
 sendmsg01 sendmsg01
testcases/kernel/syscalls/sendfile/sendfile09.c new file +17 -0
new file mode 100644
index 0000000..1bab702
@@ -0,0 +1,233 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2014
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

02110-1301 USA
+ */

testcases/kernel/syscalls/sendfile/sendfile09.c new file +215 -1
+
+/*
+ * NAME
+ *	sendfile09.c
+ *
+ * DESCRIPTION
+ *	Testcase copied from sendfile02.c to test the basic functionality of
+ *	the sendfile(2) system call on large file. There is a kernel bug which
+ *	introduced by commit 8f9c0119d7ba and fixed by commit 5d73320a96fcc.
+ *
+ * ALGORITHM
+ *	1. call sendfile(2) with offset = 0
+ *	2. call sendfile(2) with offset in the middle of the file
+ *
+ * USAGE:  <for command-line>
+ *  sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
+ *     where,
+ *             -i n : Execute test n times.
+ *             -I x : Execute test for x seconds.
+ *             -P x : Pause for x seconds between iterations.
+ *             -t   : Turn on syscall timing.
+ *
+ *
+ * RESTRICTIONS
+ *	Only supports 64bit systems and kernel 2.6.33 or above
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "compiler.h"
+
+#ifndef OFF_T
+#define OFF_T off_t
+#endif /* Not def: OFF_T */
+
+TCID_DEFINE(sendfile09);
+
+static char *in_file = "in";
+static char *out_file = "out";
+static int fd;
+static int in_fd;
+static int out_fd;
+
+static void cleanup(void);
+static void setup(void);
+
+struct test_case_t {
+	char *desc;
+	OFF_T offset;
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} testcases[] = {
+	{ "Test sendfile(2) with offset = 0",
+	    0, 4294967296, 4294967296},
+	{ "Test sendfile(2) with offset in the middle of file",
+	    2147483648, 2147483648, 4294967296}
+};
+
+int TST_TOTAL = ARRAY_SIZE(testcases);
+
+#ifdef UCLINUX
+static char *argv0;
+#endif
+
+void do_sendfile(OFF_T offset, int i)
+{
+	struct stat sb;
+	off_t before_pos, after_pos;
+
+	out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
+
+	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
+
+	SAFE_STAT(cleanup, in_file, &sb);
+
+	before_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+
+	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+
+	if (TEST_RETURN == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "sendfile(2) failed");
+
+	after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+
+	if (TEST_RETURN != testcases[i].exp_retval) {
+		tst_resm(TFAIL, "sendfile(2) failed to return "
+			 "expected value, expected: %" PRId64 ", "
+			 "got: %" PRId64, testcases[i].exp_retval,
+			 TEST_RETURN);
+	} else if (offset != testcases[i].exp_updated_offset) {
+		tst_resm(TFAIL, "sendfile(2) failed to update "
+			 "OFFSET parameter to expected value, "
+			 "expected: %" PRId64 ", got: %" PRId64,
+			 testcases[i].exp_updated_offset,
+			 (int64_t) offset);
+	} else if (before_pos != after_pos) {
+		tst_resm(TFAIL, "sendfile(2) updated the file position "
+			 " of in_fd unexpectedly, expected file position: %"
+			 PRId64 ", " " actual file position %" PRId64,
+			 (int64_t) before_pos, (int64_t) after_pos);
+	} else {
+		tst_resm(TPASS, "functionality of sendfile() is "
+			 "correct");
+	}
+
+	close(in_fd);
+	close(out_fd);
+}
+
+/*
+ * setup() - performs all ONE TIME setup for this test.
+ */
+void setup(void)
+{
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	/* make a temporary directory and cd to it */
+	tst_tmpdir();
+
+	if (!tst_fs_has_free(NULL, ".", 8, TST_GB)) {
+		cleanup();
+		tst_brkm(TCONF, NULL, "sendfile(2) on large file"
+			" needs 8G free space.");
+	}
+
+	fd = SAFE_CREAT(cleanup, in_file, 00700);
+
+	/* create a 4G file */
+	for (i = 1; i <= (4 * 1024); i++) {
+		SAFE_LSEEK(cleanup, fd, 1024 * 1024 - 1, SEEK_CUR);
+
+		SAFE_WRITE(cleanup, 1, fd, "C", 1);
+	}
+
+	close(fd);
+
+	fd = SAFE_CREAT(cleanup, out_file, 00700);
+
+	close(fd);
+}
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ *	       completion or premature exit.
+ */
+void cleanup(void)
+{
+	/*
+	 * print timing stats if that option was specified.
+	 * print errno log if that option was specified.
+	 */
+	TEST_CLEANUP;
+
+	if (fd > 0)
+		close(fd);
+
+	if (in_fd > 0)
+		close(in_fd);
+
+	if (out_fd > 0)
+		close(out_fd);
+
+	/* delete the test directory created in setup() */
+	tst_rmdir();
+
+}
+
+int main(int ac, char **av)
+{
+	int i;
+	int lc;
+	const char *msg;		/* parse_opts() return message */
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#endif
+
+	if (tst_kvercmp(2, 6, 33) < 0) {
+		tst_resm(TINFO, "sendfile(2) on large file "
+			"skipped for kernels < 2.6.33");
+		return 0;
+	}
+
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	/*
+	 * The following loop checks looping state if -c option given
+	 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; ++i)
+			do_sendfile(testcases[i].offset, i);
+	}
+
+	cleanup();
+
+	tst_exit();
+}
--

1.9.3

Quoted 11 lines

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#9 lore raw

----- Original Message -----

Quoted 26 lines

From: "Jan Stancek" <[email protected]>
To: "Han Pingtian" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 8 July, 2014 12:36:27 PM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at 2G

----- Original Message -----

Quoted 11 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Tuesday, 8 July, 2014 9:23:08 AM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at

	2G
Quoted 2 lines · Jan Stancek

Thanks so much. I have changed the patch according to you and Xiaoguang's suggestions. Please have a look.

Hi,

Below are some small suggestions, mostly to avoid int type related warnings when compiled as 32-bit.

Quoted 7 lines

Did you also test this testcase with kernel commit 5d73320a96fcc applied? I tried it with this commit applied on top of RHEL7 GA kernel, but I didn't get the expected result:

sendfile(3, 4, [0], 4294967296) = 2147418112
...
sendfile(3, 4, [2147483648], 2147483648) = 2147418112

do_sendfile()
rw_verify_area()

    return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;

#define MAX_RW_COUNT (INT_MAX & PAGE_CACHE_MASK)

which appears to match return value I get:
2147418112 == 0x7FFF0000

printf("%d %d\n", sizeof(int), getpagesize());
4 65536

Can sendfile work with sizes > 2GB?

Regards,
Jan

Quoted 391 lines

Regards,
Jan

testcases/kernel/syscalls/.gitignore +2 -0
index 975c150..b9d49cf 100644
@@ -750,6 +750,8 @@
 /sendfile/sendfile07_64
 /sendfile/sendfile08
 /sendfile/sendfile08_64
+/sendfile/sendfile09
+/sendfile/sendfile09_64
 /sendmsg/sendmsg01
 /sendmsg/sendmsg02
 /sendto/sendto01
testcases/kernel/syscalls/sendfile/sendfile09.c +10 -13
index 1bab702..2b9de40 100644
@@ -54,7 +54,6 @@
 #include "usctest.h"
 #include "test.h"
 #include "safe_macros.h"
-#include "compiler.h"
 
 #ifndef OFF_T
 #define OFF_T off_t
@@ -71,28 +70,27 @@ static int out_fd;
 static void cleanup(void);
 static void setup(void);
 
-struct test_case_t {
+#define TWO_GB (INT64_C(1) << 31)
+#define FOUR_GB (INT64_C(1) << 32)
+
+static struct test_case_t {
        char *desc;
        OFF_T offset;
        int64_t exp_retval;
        int64_t exp_updated_offset;
 } testcases[] = {
        { "Test sendfile(2) with offset = 0",
-           0, 4294967296, 4294967296},
+           0, FOUR_GB, FOUR_GB},
        { "Test sendfile(2) with offset in the middle of file",
-           2147483648, 2147483648, 4294967296}
+           TWO_GB, TWO_GB, FOUR_GB}
 };
 
 int TST_TOTAL = ARRAY_SIZE(testcases);
 
-#ifdef UCLINUX
-static char *argv0;
-#endif
-
 void do_sendfile(OFF_T offset, int i)
 {
        struct stat sb;
-       off_t before_pos, after_pos;
+       OFF_T before_pos, after_pos;
 
        out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
 
@@ -105,14 +103,14 @@ void do_sendfile(OFF_T offset, int i)
        TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
 
        if (TEST_RETURN == -1)
-               tst_brkm(TBROK | TERRNO, cleanup, "sendfile(2) failed");
+               tst_brkm(TBROK | TTERRNO, cleanup, "sendfile(2) failed");
 
        after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
 
        if (TEST_RETURN != testcases[i].exp_retval) {
                tst_resm(TFAIL, "sendfile(2) failed to return "
                         "expected value, expected: %" PRId64 ", "
-                        "got: %" PRId64, testcases[i].exp_retval,
+                        "got: %ld", testcases[i].exp_retval,
                         TEST_RETURN);
        } else if (offset != testcases[i].exp_updated_offset) {
                tst_resm(TFAIL, "sendfile(2) failed to update "
@@ -149,8 +147,7 @@ void setup(void)
        tst_tmpdir();
 
        if (!tst_fs_has_free(NULL, ".", 8, TST_GB)) {
-               cleanup();
-               tst_brkm(TCONF, NULL, "sendfile(2) on large file"
+               tst_brkm(TCONF, cleanup, "sendfile(2) on large file"
                        " needs 8G free space.");
        }
 
Quoted 282 lines
Quoted 5 lines

From 5257dba5a2ce42e55d0ba61c2a6bd5fe30c5c7f7 Mon Sep 17 00:00:00 2001

From: Han Pingtian <[email protected]>
Date: Thu, 3 Jul 2014 15:29:35 +0800
Subject: [PATCH] regression test for 64bit sendfile capped at 2G

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/sendfile/sendfile09.c | 233
 ++++++++++++++++++++++++
 2 files changed, 235 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
runtest/syscalls +2 -0
index 66d6a65..fbed9cb 100644
@@ -937,6 +937,8 @@ sendfile07 sendfile07
 sendfile07_64 sendfile07_64
 sendfile08 sendfile08
 sendfile08_64 sendfile08_64
+sendfile09 sendfile09
+sendfile09_64 sendfile09_64
 
 
 sendmsg01 sendmsg01
testcases/kernel/syscalls/sendfile/sendfile09.c new file +17 -0
new file mode 100644
index 0000000..1bab702
@@ -0,0 +1,233 @@
+/*
+ *
+ *   Copyright (c) International Business Machines  Corp., 2014
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

02110-1301 USA
+ */

testcases/kernel/syscalls/sendfile/sendfile09.c new file +215 -1
+
+/*
+ * NAME
+ *	sendfile09.c
+ *
+ * DESCRIPTION
+ *	Testcase copied from sendfile02.c to test the basic functionality of
+ *	the sendfile(2) system call on large file. There is a kernel bug which
+ *	introduced by commit 8f9c0119d7ba and fixed by commit 5d73320a96fcc.
+ *
+ * ALGORITHM
+ *	1. call sendfile(2) with offset = 0
+ *	2. call sendfile(2) with offset in the middle of the file
+ *
+ * USAGE:  <for command-line>
+ *  sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
+ *     where,
+ *             -i n : Execute test n times.
+ *             -I x : Execute test for x seconds.
+ *             -P x : Pause for x seconds between iterations.
+ *             -t   : Turn on syscall timing.
+ *
+ *
+ * RESTRICTIONS
+ *	Only supports 64bit systems and kernel 2.6.33 or above
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "compiler.h"
+
+#ifndef OFF_T
+#define OFF_T off_t
+#endif /* Not def: OFF_T */
+
+TCID_DEFINE(sendfile09);
+
+static char *in_file = "in";
+static char *out_file = "out";
+static int fd;
+static int in_fd;
+static int out_fd;
+
+static void cleanup(void);
+static void setup(void);
+
+struct test_case_t {
+	char *desc;
+	OFF_T offset;
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} testcases[] = {
+	{ "Test sendfile(2) with offset = 0",
+	    0, 4294967296, 4294967296},
+	{ "Test sendfile(2) with offset in the middle of file",
+	    2147483648, 2147483648, 4294967296}
+};
+
+int TST_TOTAL = ARRAY_SIZE(testcases);
+
+#ifdef UCLINUX
+static char *argv0;
+#endif
+
+void do_sendfile(OFF_T offset, int i)
+{
+	struct stat sb;
+	off_t before_pos, after_pos;
+
+	out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
+
+	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
+
+	SAFE_STAT(cleanup, in_file, &sb);
+
+	before_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+
+	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+
+	if (TEST_RETURN == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "sendfile(2) failed");
+
+	after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+
+	if (TEST_RETURN != testcases[i].exp_retval) {
+		tst_resm(TFAIL, "sendfile(2) failed to return "
+			 "expected value, expected: %" PRId64 ", "
+			 "got: %" PRId64, testcases[i].exp_retval,
+			 TEST_RETURN);
+	} else if (offset != testcases[i].exp_updated_offset) {
+		tst_resm(TFAIL, "sendfile(2) failed to update "
+			 "OFFSET parameter to expected value, "
+			 "expected: %" PRId64 ", got: %" PRId64,
+			 testcases[i].exp_updated_offset,
+			 (int64_t) offset);
+	} else if (before_pos != after_pos) {
+		tst_resm(TFAIL, "sendfile(2) updated the file position "
+			 " of in_fd unexpectedly, expected file position: %"
+			 PRId64 ", " " actual file position %" PRId64,
+			 (int64_t) before_pos, (int64_t) after_pos);
+	} else {
+		tst_resm(TPASS, "functionality of sendfile() is "
+			 "correct");
+	}
+
+	close(in_fd);
+	close(out_fd);
+}
+
+/*
+ * setup() - performs all ONE TIME setup for this test.
+ */
+void setup(void)
+{
+	int i;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	/* make a temporary directory and cd to it */
+	tst_tmpdir();
+
+	if (!tst_fs_has_free(NULL, ".", 8, TST_GB)) {
+		cleanup();
+		tst_brkm(TCONF, NULL, "sendfile(2) on large file"
+			" needs 8G free space.");
+	}
+
+	fd = SAFE_CREAT(cleanup, in_file, 00700);
+
+	/* create a 4G file */
+	for (i = 1; i <= (4 * 1024); i++) {
+		SAFE_LSEEK(cleanup, fd, 1024 * 1024 - 1, SEEK_CUR);
+
+		SAFE_WRITE(cleanup, 1, fd, "C", 1);
+	}
+
+	close(fd);
+
+	fd = SAFE_CREAT(cleanup, out_file, 00700);
+
+	close(fd);
+}
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ *	       completion or premature exit.
+ */
+void cleanup(void)
+{
+	/*
+	 * print timing stats if that option was specified.
+	 * print errno log if that option was specified.
+	 */
+	TEST_CLEANUP;
+
+	if (fd > 0)
+		close(fd);
+
+	if (in_fd > 0)
+		close(in_fd);
+
+	if (out_fd > 0)
+		close(out_fd);
+
+	/* delete the test directory created in setup() */
+	tst_rmdir();
+
+}
+
+int main(int ac, char **av)
+{
+	int i;
+	int lc;
+	const char *msg;		/* parse_opts() return message */
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#endif
+
+	if (tst_kvercmp(2, 6, 33) < 0) {
+		tst_resm(TINFO, "sendfile(2) on large file "
+			"skipped for kernels < 2.6.33");
+		return 0;
+	}
+
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	/*
+	 * The following loop checks looping state if -c option given
+	 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; ++i)
+			do_sendfile(testcases[i].offset, i);
+	}
+
+	cleanup();
+
+	tst_exit();
+}
--

1.9.3

Quoted 11 lines

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse

Quoted 9 lines

Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#10 lore raw

----- Original Message -----

Quoted 53 lines

From: "Jan Stancek" <[email protected]>
To: "Han Pingtian" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 8 July, 2014 1:55:47 PM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at 2G

----- Original Message -----

Quoted 28 lines

From: "Jan Stancek" <[email protected]>
To: "Han Pingtian" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 8 July, 2014 12:36:27 PM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at

	2G

----- Original Message -----

Quoted 5 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Tuesday, 8 July, 2014 9:23:08 AM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at

Quoted 7 lines
	2G
Quoted 2 lines · Jan Stancek

Thanks so much. I have changed the patch according to you and Xiaoguang's suggestions. Please have a look.

Hi,

Below are some small suggestions, mostly to avoid int type related warnings when compiled as 32-bit.

Quoted 7 lines

Did you also test this testcase with kernel commit 5d73320a96fcc applied? I tried it with this commit applied on top of RHEL7 GA kernel, but I didn't get the expected result:

sendfile(3, 4, [0], 4294967296) = 2147418112
...
sendfile(3, 4, [2147483648], 2147483648) = 2147418112

do_sendfile()
rw_verify_area()

    return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;

#define MAX_RW_COUNT (INT_MAX & PAGE_CACHE_MASK)

Quoted 7 lines

which appears to match return value I get:
2147418112 == 0x7FFF0000

printf("%d %d\n", sizeof(int), getpagesize());
4 65536

Can sendfile work with sizes > 2GB?

I think the problem addressed in commit 5d73320a96fcc was using sendfile on large files, and not making large (count > 2GB) sendfile() calls.

Taking this into account, I can see the difference with/without commit 5d73320a96fcc. Second case here fails on unpatched kernel with:

sendfile(3, 4, [3221225472], 1073741824) = -1 EOVERFLOW (Value too large for defined data type)

testcases/kernel/syscalls/.gitignore +2 -0
index 975c150..b9d49cf 100644
@@ -750,6 +750,8 @@
 /sendfile/sendfile07_64
 /sendfile/sendfile08
 /sendfile/sendfile08_64
+/sendfile/sendfile09
+/sendfile/sendfile09_64
 /sendmsg/sendmsg01
 /sendmsg/sendmsg02
 /sendto/sendto01
testcases/kernel/syscalls/sendfile/sendfile09.c +16 -21
index 1bab702..c33b084 100644
@@ -71,55 +71,51 @@ static int out_fd;
 static void cleanup(void);
 static void setup(void);
 
-struct test_case_t {
+#define ONE_GB (INT64_C(1) << 30)
+
+static struct test_case_t {
        char *desc;
        OFF_T offset;
+       int64_t count;
        int64_t exp_retval;
        int64_t exp_updated_offset;
 } testcases[] = {
        { "Test sendfile(2) with offset = 0",
-           0, 4294967296, 4294967296},
+           0, ONE_GB, ONE_GB, ONE_GB},
        { "Test sendfile(2) with offset in the middle of file",
-           2147483648, 2147483648, 4294967296}
+           3*ONE_GB, ONE_GB, ONE_GB, 4*ONE_GB}
 };
 
 int TST_TOTAL = ARRAY_SIZE(testcases);
 
-#ifdef UCLINUX
-static char *argv0;
-#endif
-
-void do_sendfile(OFF_T offset, int i)
+void do_sendfile(struct test_case_t *t)
 {
-       struct stat sb;
        off_t before_pos, after_pos;
 
        out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
 
        in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
 
-       SAFE_STAT(cleanup, in_file, &sb);
-
        before_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
 
-       TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
+       TEST(sendfile(out_fd, in_fd, &t->offset, t->count));
 
        if (TEST_RETURN == -1)
-               tst_brkm(TBROK | TERRNO, cleanup, "sendfile(2) failed");
+               tst_brkm(TBROK | TTERRNO, cleanup, "sendfile(2) failed");
 
        after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
 
-       if (TEST_RETURN != testcases[i].exp_retval) {
+       if (TEST_RETURN != t->exp_retval) {
                tst_resm(TFAIL, "sendfile(2) failed to return "
                         "expected value, expected: %" PRId64 ", "
-                        "got: %" PRId64, testcases[i].exp_retval,
+                        "got: %ld", t->exp_retval,
                         TEST_RETURN);
-       } else if (offset != testcases[i].exp_updated_offset) {
+       } else if (t->offset != t->exp_updated_offset) {
                tst_resm(TFAIL, "sendfile(2) failed to update "
                         "OFFSET parameter to expected value, "
                         "expected: %" PRId64 ", got: %" PRId64,
-                        testcases[i].exp_updated_offset,
-                        (int64_t) offset);
+                        t->exp_updated_offset,
+                        (int64_t) t->offset);
        } else if (before_pos != after_pos) {
                tst_resm(TFAIL, "sendfile(2) updated the file position "
                         " of in_fd unexpectedly, expected file position: %"
@@ -149,8 +145,7 @@ void setup(void)
        tst_tmpdir();
 
        if (!tst_fs_has_free(NULL, ".", 8, TST_GB)) {
-               cleanup();
-               tst_brkm(TCONF, NULL, "sendfile(2) on large file"
+               tst_brkm(TCONF, cleanup, "sendfile(2) on large file"
                        " needs 8G free space.");
        }
 
@@ -224,7 +219,7 @@ int main(int ac, char **av)
                tst_count = 0;
 
                for (i = 0; i < TST_TOTAL; ++i)
-                       do_sendfile(testcases[i].offset, i);
+                       do_sendfile(&testcases[i]);
        }
 
        cleanup();

Regards,
Jan

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#11 lore raw
Quoted 9 lines · Jan Stancek

I think the problem addressed in commit 5d73320a96fcc was using sendfile on large files, and not making large (count > 2GB) sendfile() calls.

Taking this into account, I can see the difference with/without commit 5d73320a96fcc. Second case here fails on unpatched kernel with:

sendfile(3, 4, [3221225472], 1073741824) = -1 EOVERFLOW (Value too large for defined data type)

Great! I have combined these patches, please have a look. Many Thanks!

From 1bd0231a240629b42dc83e151badb4f0a18b9d22 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Thu, 3 Jul 2014 15:29:35 +0800
Subject: [PATCH] regression test for 64bit sendfile capped at 2G

There is a bug on 64bit sendfile() with large file, please see
https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-June/118128.html
for details.

This sendfile09.c was copied from sendfile02.c and using plain file as the out_file. The file size is 4G (4294967296 bytes).

The count cannot be large than 2G, but the offset can. So the second case tests with 3G offset and 1G count. Many thanks to Jan Stancek's help.

---
 runtest/syscalls                                |   2 +
 testcases/kernel/syscalls/.gitignore            |   2 +
 testcases/kernel/syscalls/sendfile/sendfile09.c | 226 ++++++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sendfile/sendfile09.c
runtest/syscalls +2 -0
index 66d6a65..fbed9cb 100644
@@ -937,6 +937,8 @@ sendfile07 sendfile07
 sendfile07_64 sendfile07_64
 sendfile08 sendfile08
 sendfile08_64 sendfile08_64
+sendfile09 sendfile09
+sendfile09_64 sendfile09_64
 
 
 sendmsg01 sendmsg01
testcases/kernel/syscalls/.gitignore +2 -0
index 975c150..b9d49cf 100644
@@ -750,6 +750,8 @@
 /sendfile/sendfile07_64
 /sendfile/sendfile08
 /sendfile/sendfile08_64
+/sendfile/sendfile09
+/sendfile/sendfile09_64
 /sendmsg/sendmsg01
 /sendmsg/sendmsg02
 /sendto/sendto01
testcases/kernel/syscalls/sendfile/sendfile09.c new file +226 -0

226 lines not on this page · raw message

Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#12 lore raw

----- Original Message -----

Quoted 14 lines

From: "Han Pingtian" <[email protected]>
To: [email protected]
Sent: Tuesday, 8 July, 2014 4:42:54 PM
Subject: Re: [LTP] [RFC PATCH] regression test for 64bit sendfile capped at 2G

Quoted 8 lines · Jan Stancek

I think the problem addressed in commit 5d73320a96fcc was using sendfile on large files,
and not making large (count > 2GB) sendfile() calls.

Taking this into account, I can see the difference with/without commit 5d73320a96fcc.
Second case here fails on unpatched kernel with:

Quoted 5 lines
Quoted 4 lines

sendfile(3, 4, [3221225472], 1073741824) = -1 EOVERFLOW (Value too large for defined data type)

Great! I have combined these patches, please have a look. Many Thanks!

Pushed with small changes. Mostly comment updates to reflect that we are testing at 0 and 3GB offsets. Also, I changed test for required space to 5GB.

Regards,
Jan

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck&#174; Code Sight&#153; - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list