All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 2/3] syscalls/copy_file_range01: add cross-device test
Date: Wed, 17 Jul 2019 17:44:35 +0800	[thread overview]
Message-ID: <1563356676-2384-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> (raw)
In-Reply-To: <1563356676-2384-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Amir has relaxed cross-device constraint since kernel commit 5dae222a5(vfs:
allow copy_file_range to copy across devices), I think we can test it in
copy_file_range01.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
 .../copy_file_range/copy_file_range01.c       | 58 ++++++++++++++-----
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
index a5bd5e7f7..ec55e5da1 100644
--- a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
+++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
@@ -24,7 +24,16 @@
 
 static int page_size;
 static int errcount, numcopies;
-static int fd_in, fd_out;
+static int fd_in, fd_out, cross_sup;
+
+static struct tcase {
+	char    *path;
+	int     flags;
+	char    *message;
+} tcases[] = {
+	{FILE_DEST_PATH,  0, "non cross-device"},
+	{FILE_MNTED_PATH, 1, "cross-device"},
+};
 
 static int check_file_content(const char *fname1, const char *fname2,
 	loff_t *off1, loff_t *off2, size_t len)
@@ -90,7 +99,7 @@ static int check_file_offset(const char *m, int fd, loff_t len,
 	return ret;
 }
 
-static void test_one(size_t len, loff_t *off_in, loff_t *off_out)
+static void test_one(size_t len, loff_t *off_in, loff_t *off_out, char *path)
 {
 	int ret;
 	size_t to_copy = len;
@@ -131,7 +140,7 @@ static void test_one(size_t len, loff_t *off_in, loff_t *off_out)
 		to_copy -= TST_RET;
 	} while (to_copy > 0);
 
-	ret = check_file_content(FILE_SRC_PATH, FILE_DEST_PATH,
+	ret = check_file_content(FILE_SRC_PATH, path,
 		off_in, off_out, len);
 	if (ret) {
 		tst_res(TFAIL, "file contents do not match");
@@ -149,10 +158,10 @@ static void test_one(size_t len, loff_t *off_in, loff_t *off_out)
 	}
 }
 
-static void open_files(void)
+static void open_files(char *path)
 {
 	fd_in  = SAFE_OPEN(FILE_SRC_PATH, O_RDONLY);
-	fd_out = SAFE_OPEN(FILE_DEST_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+	fd_out = SAFE_OPEN(path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
 }
 
 static void close_files(void)
@@ -163,9 +172,16 @@ static void close_files(void)
 		SAFE_CLOSE(fd_in);
 }
 
-static void copy_file_range_verify(void)
+static void copy_file_range_verify(unsigned int n)
 {
 	int i, j, k;
+	struct tcase *tc = &tcases[n];
+
+	if (tc->flags && !cross_sup) {
+		tst_res(TCONF,
+			"copy_file_range doesn't support cross-device, skip it");
+		return;
+	}
 
 	errcount = numcopies = 0;
 	size_t len_arr[]	= {11, page_size-1, page_size, page_size+1};
@@ -182,33 +198,41 @@ static void copy_file_range_verify(void)
 	for (i = 0; i < (int)ARRAY_SIZE(len_arr); i++)
 		for (j = 0; j < num_offsets; j++)
 			for (k = 0; k < num_offsets; k++) {
-				open_files();
-				test_one(len_arr[i], off_arr[j], off_arr[k]);
+				open_files(tc->path);
+				test_one(len_arr[i], off_arr[j], off_arr[k], tc->path);
 				close_files();
 				numcopies++;
 			}
 
 	if (errcount == 0)
 		tst_res(TPASS,
-			"copy_file_range completed all %d copy jobs successfully!",
-			numcopies);
+			"%s copy_file_range completed all %d copy jobs successfully!",
+			tc->message, numcopies);
 	else
-		tst_res(TFAIL, "copy_file_range failed %d of %d copy jobs.",
-				errcount, numcopies);
+		tst_res(TFAIL, "%s copy_file_range failed %d of %d copy jobs.",
+			tc->message, errcount, numcopies);
 }
 
 static void setup(void)
 {
-	int i, fd;
+	int i, fd, fd_test;
 
 	syscall_info();
 
 	page_size = getpagesize();
-
+	cross_sup = 1;
 	fd = SAFE_OPEN(FILE_SRC_PATH, O_RDWR | O_CREAT, 0664);
 	/* Writing page_size * 4 of data into test file */
 	for (i = 0; i < (int)(page_size * 4); i++)
 		SAFE_WRITE(1, fd, CONTENT, CONTSIZE);
+
+	fd_test = SAFE_OPEN(FILE_MNTED_PATH, O_RDWR | O_CREAT, 0664);
+	TEST(sys_copy_file_range(fd, 0, fd_test, 0, CONTSIZE, 0));
+	if (TST_ERR == EXDEV)
+		cross_sup = 0;
+
+	SAFE_CLOSE(fd_test);
+	remove(FILE_MNTED_PATH);
 	SAFE_CLOSE(fd);
 }
 
@@ -220,7 +244,11 @@ static void cleanup(void)
 static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
 	.needs_tmpdir = 1,
-	.test_all = copy_file_range_verify,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.test = copy_file_range_verify,
 	.test_variants = TEST_VARIANTS,
 };
-- 
2.18.1




  reply	other threads:[~2019-07-17  9:44 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03  3:41 [LTP] [PATCH] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-05 15:22 ` Amir Goldstein
2019-07-05 20:42   ` [LTP] [PATCH v2] " Yang Xu
2019-07-08 15:17     ` Amir Goldstein
2019-07-09  6:57       ` Yang Xu
2019-07-09 10:06         ` Amir Goldstein
2019-07-10  7:18           ` [LTP] [PATCH v3 1/3] lib: alter find_free_loopdev() Yang Xu
2019-07-10  7:18             ` [LTP] [PATCH v3 2/3] syscalls/copy_file_range01: add cross-device test Yang Xu
2019-07-10  7:50               ` Amir Goldstein
2019-07-10  8:22                 ` Yang Xu
2019-07-10  7:18             ` [LTP] [PATCH v3 3/3] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-10  7:57               ` Amir Goldstein
2019-07-10  9:31                 ` Yang Xu
2019-07-10 10:53                   ` [LTP] [PATCH v4 1/3] lib: alter find_free_loopdev() Yang Xu
2019-07-10 10:53                     ` [LTP] [PATCH v4 2/3] syscalls/copy_file_range01: add cross-device test Yang Xu
2019-07-10 15:56                       ` Xiao Yang
2019-07-11  6:18                         ` Yang Xu
2019-07-10 10:53                     ` [LTP] [PATCH v4 3/3] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-10 13:57                     ` [LTP] [PATCH v4 1/3] lib: alter find_free_loopdev() Cyril Hrubis
2019-07-11  4:00                       ` Yang Xu
2019-07-11 12:51                         ` Cyril Hrubis
2019-07-12  5:25                           ` Yang Xu
2019-07-17  5:29                             ` Yang Xu
2019-07-17  6:10                             ` Amir Goldstein
2019-07-17  9:44                           ` [LTP] [PATCH v5 " Yang Xu
2019-07-17  9:44                             ` Yang Xu [this message]
2019-07-29 13:56                               ` [LTP] [PATCH v5 2/3] syscalls/copy_file_range01: add cross-device test Petr Vorel
2019-07-29 13:59                                 ` Petr Vorel
2019-07-17  9:44                             ` [LTP] [PATCH v5 3/3] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-17 10:14                             ` [LTP] [PATCH v5 1/3] lib: alter find_free_loopdev() Amir Goldstein
2019-07-17 10:34                               ` Yang Xu
2019-07-17 10:54                                 ` Cyril Hrubis
2019-07-18  7:30                                   ` Yang Xu
2019-07-25  5:01                                     ` [LTP] [PATCH v6 " Yang Xu
2019-07-25  5:01                                       ` [LTP] [PATCH v6 2/3] syscalls/copy_file_range01: add cross-device test Yang Xu
2019-07-29 14:00                                         ` Petr Vorel
2019-07-29 14:10                                           ` Petr Vorel
2019-07-30  8:31                                             ` Yang Xu
2019-07-30 13:35                                               ` Petr Vorel
2019-07-31  7:01                                                 ` Yang Xu
2019-07-31  7:47                                                   ` Petr Vorel
2019-07-25  5:01                                       ` [LTP] [PATCH v6 3/3] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-25  5:24                                         ` Amir Goldstein
2019-07-25  5:44                                           ` Yang Xu
2019-07-25  8:08                                             ` Amir Goldstein
2019-07-25 10:13                                               ` Yang Xu
2019-07-25 11:02                                                 ` Amir Goldstein
2019-07-30 13:26                                         ` Petr Vorel
2019-07-31  7:09                                           ` Yang Xu
2019-07-29 13:01                                       ` [LTP] [PATCH v6 1/3] lib: alter find_free_loopdev() Cyril Hrubis
2019-07-30 10:42                                         ` Yang Xu
2019-07-30 11:05                                           ` Cyril Hrubis
2019-07-31 10:40                                             ` [LTP] [PATCH v7 " Yang Xu
2019-07-31 10:40                                               ` [LTP] [PATCH v7 2/3] syscalls/copy_file_range01: add cross-device test Yang Xu
2019-07-31 12:28                                                 ` Petr Vorel
2019-07-31 10:40                                               ` [LTP] [PATCH v7 3/3] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-31 12:28                                                 ` Petr Vorel
2019-08-05  6:58                                                 ` Murphy Zhou
2019-08-05  7:11                                                   ` Yang Xu
2019-08-05 10:22                                                     ` Murphy Zhou
2019-08-05 11:01                                                       ` Yang Xu
2019-08-06  6:37                                                         ` Yang Xu
2019-08-06  9:29                                                           ` Murphy Zhou
2019-08-06 16:27                                                       ` Petr Vorel
2019-08-07 10:17                                                         ` Murphy Zhou
2019-08-07 10:17                                                           ` Murphy Zhou
2019-08-07 12:12                                                           ` Dave Chinner
2019-08-07 12:12                                                             ` Dave Chinner
2019-08-08  3:46                                                             ` Murphy Zhou
2019-08-08  3:46                                                               ` Murphy Zhou
2019-08-08  3:11                                                           ` Yang Xu
2019-08-08  3:11                                                             ` Yang Xu
2019-08-08  3:11                                                             ` Yang Xu
2019-08-08  3:57                                                             ` Murphy Zhou
2019-08-08  3:57                                                               ` Murphy Zhou
2019-08-27 10:04                                                               ` Petr Vorel
2019-08-27 10:04                                                                 ` Petr Vorel
2019-07-31 12:05                                               ` [LTP] [PATCH v7 1/3] lib: alter find_free_loopdev() Petr Vorel
2019-07-31 12:28                                                 ` Cyril Hrubis
2019-07-31 12:48                                                   ` Petr Vorel
2019-07-31 13:25                                                     ` Cyril Hrubis
2019-07-31 21:06                                                       ` Petr Vorel
2019-07-31 12:07                                               ` Petr Vorel
2019-07-10  7:47             ` [LTP] [PATCH v3 " Amir Goldstein
2019-07-10  7:32           ` [LTP] [PATCH v2] syscalls/copy_file_range02: increase coverage and remove EXDEV test Yang Xu
2019-07-08 10:38   ` [LTP] [PATCH] " Yang Xu

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=1563356676-2384-2-git-send-email-xuyang2018.jy@cn.fujitsu.com \
    --to=xuyang2018.jy@cn.fujitsu.com \
    --cc=ltp@lists.linux.it \
    /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.