Skip to contentSkip to conversation

syscalls: add new test for copy_file_range(2)

PATCH Superseded Li Wang 2 participants 9 messages Apr 20, 2017 – May 19, 2017

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

---

Notes:
v2 --> v3
* writing page_size * 4 of data into test file
* avoid pointer cast in the struct
* remove copy_file_range() definition
* use SAFE_MACRO and improve TPASS msg

 runtest/syscalls                                   |   2 +
 testcases/kernel/include/aarch64.in                |   1 +
 testcases/kernel/include/arm.in                    |   1 +
 testcases/kernel/include/hppa.in                   |   1 +
 testcases/kernel/include/i386.in                   |   1 +
 testcases/kernel/include/ia64.in                   |   1 +
 testcases/kernel/include/powerpc.in                |   1 +
 testcases/kernel/include/powerpc64.in              |   1 +
 testcases/kernel/include/regen.sh                  |   2 +-
 testcases/kernel/include/s390.in                   |   1 +
 testcases/kernel/include/s390x.in                  |   1 +
 testcases/kernel/include/sh.in                     |   1 +
 testcases/kernel/include/sparc.in                  |   1 +
 testcases/kernel/include/sparc64.in                |   1 +
 testcases/kernel/include/x86_64.in                 |   1 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 testcases/kernel/syscalls/copy_file_range/Makefile |  19 +++
 .../syscalls/copy_file_range/copy_file_range01.c   | 158 +++++++++++++++++++++
 18 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/copy_file_range/Makefile
 create mode 100644 testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
runtest/syscalls +2 -0
index 5909456..019ee32 100644
@@ -1458,3 +1458,5 @@ futex_wait_bitset02 futex_wait_bitset02
 
 memfd_create01 memfd_create01
 memfd_create02 memfd_create02
+
+copy_file_range01 copy_file_range01
testcases/kernel/include/aarch64.in +1 -0
index b81c068..8b725e3 100644
@@ -256,3 +256,4 @@ sendmmsg 269
 kcmp 272
 getrandom 278
 memfd_create 279
+copy_file_range 391
testcases/kernel/include/arm.in +1 -0
index 0a5dde1..1a13661 100644
@@ -339,3 +339,4 @@ sched_getattr (__NR_SYSCALL_BASE+381)
 renameat2 (__NR_SYSCALL_BASE+382)
 getrandom (__NR_SYSCALL_BASE+384)
 memfd_create (__NR_SYSCALL_BASE+385)
+copy_file_range (__NR_SYSCALL_BASE+391)
testcases/kernel/include/hppa.in +1 -0
index 3946155..bb7a694 100644
@@ -16,3 +16,4 @@ splice 291
 tee 293
 vmsplice 294
 memfd_create 340
+copy_file_range 346
testcases/kernel/include/i386.in +1 -0
index 42c5e3f..9cbb139 100644
@@ -339,3 +339,4 @@ sched_getattr 352
 renameat2 354
 getrandom 355
 memfd_create 356
+copy_file_range 377
testcases/kernel/include/ia64.in +1 -0
index dad25f4..1d5b21c 100644
@@ -295,3 +295,4 @@ prlimit64 1325
 renameat2 1338
 getrandom 1339
 memfd_create 1340
+copy_file_range 1347
testcases/kernel/include/powerpc.in +1 -0
index 10a6e5d..f87192e 100644
@@ -346,3 +346,4 @@ sched_getattr 356
 renameat2 357
 getrandom 359
 memfd_create 360
+copy_file_range 379
testcases/kernel/include/powerpc64.in +1 -0
index 10a6e5d..f87192e 100644
@@ -346,3 +346,4 @@ sched_getattr 356
 renameat2 357
 getrandom 359
 memfd_create 360
+copy_file_range 379
testcases/kernel/include/regen.sh +1 -1
index 3755bbf..929a3f8 100755
@@ -60,7 +60,7 @@ cat << EOF > "${output_pid}"
 		tst_ret = syscall(NR, ##__VA_ARGS__); \\
 	} \\
 	if (tst_ret == -1 && errno == ENOSYS) { \\
-		tst_brk(TCONF, "syscall(%d) " #NR "not supported", NR); \\
+		tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \\
 	} \\
 	tst_ret; \\
 })
testcases/kernel/include/s390.in +1 -0
index 770db7f..2526f38 100644
@@ -330,3 +330,4 @@ sched_getattr 346
 renameat2 347
 getrandom 349
 memfd_create 350
+copy_file_range 375
testcases/kernel/include/s390x.in +1 -0
index 770db7f..2526f38 100644
@@ -330,3 +330,4 @@ sched_getattr 346
 renameat2 347
 getrandom 349
 memfd_create 350
+copy_file_range 375
testcases/kernel/include/sh.in +1 -0
index 0345f8d..b41b578 100644
@@ -363,3 +363,4 @@ fanotify_mark 368
 prlimit64 369
 kcmp 378
 memfd_create 385
+copy_file_range 391
testcases/kernel/include/sparc.in +1 -0
index b84c844..729768b 100644
@@ -335,3 +335,4 @@ kcmp 341
 renameat2 345
 getrandom 347
 memfd_create 348
+copy_file_range 357
testcases/kernel/include/sparc64.in +1 -0
index 7e0be30..9eb21ee 100644
@@ -311,3 +311,4 @@ kcmp 341
 renameat2 345
 getrandom 347
 memfd_create 348
+copy_file_range 357
testcases/kernel/include/x86_64.in +1 -0
index dec7742..29051d4 100644
@@ -306,3 +306,4 @@ sched_getattr 315
 renameat2 316
 getrandom 318
 memfd_create 319
+copy_file_range 326
testcases/kernel/syscalls/.gitignore +1 -0
index d5985cd..db6d7e9 100644
@@ -1125,3 +1125,4 @@
 /perf_event_open/perf_event_open02
 /memfd_create/memfd_create01
 /memfd_create/memfd_create02
+/copy_file_range/copy_file_range01
testcases/kernel/syscalls/copy_file_range/Makefile new file +19 -0
new file mode 100644
index 0000000..0143bde
@@ -0,0 +1,19 @@
+#
+#  Copyright (c) Linux Test Project, 2017
+#
+# 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.
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/copy_file_range/copy_file_range01.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.9.3
#1 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

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

Quoted 32 lines
testcases/kernel/syscalls/copy_file_range/copy_file_range01.c new file +28 -0
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "linux_syscall_numbers.h"
+
+#define TEST_FILE_1 "copy_file_range_ltp01.txt"
+#define TEST_FILE_2 "copy_file_range_ltp02.txt"
+#define STR "abcdefghijklmnopqrstuvwxyz12345\n"
+
+static off_t len1 = 1;   /* 1 */
+static off_t len2;       /* stat.st_size */
+static off_t len3;       /* stat.st_size - 1 */
+static off_t page_size1; /* pagesize - 1 */
+static off_t page_size2; /* pagesize     */
+static off_t page_size3; /* pagesize + 1 */
+
+static struct tcase {
+	off_t *off_in;
+	off_t *off_out;
+	off_t *len;
+} tcases[] = {
+	{NULL,  NULL,  &len1}, /* NULL, NULL, 1 */
+	{NULL,  NULL,  &len2}, /* NULL, NULL, stat.st_size */
+	{&len3, &len3, &len1}, /* stat.st_size - 1, stat.st_size - 1, 1 */
+	{&page_size1, &page_size1, &page_size1}, /* pagesize - 1, pagesize - 1,

pagesize - 1 */

(quoted diff) +1 -0
+	{&page_size2, &page_size2, &page_size2}, /* pagesize,     pagesize,

pagesize */

(quoted diff) +1 -0
+	{&page_size3, &page_size3, &page_size3}, /* pagesize + 1, pagesize + 1,
Quoted 2 lines

pagesize + 1 */
+};

Hi,

These variables names are a bit confusing. But larger problem is that the values are not stable between iterations. Try:

$ ./copy_file_range01 -i 5

^^ this hangs for me.

Quoted 65 lines
testcases/kernel/syscalls/copy_file_range/copy_file_range01.c new file +28 -0
+static void copy_file_range_verify(unsigned int i)
+{
+	int fd_in, fd_out;
+	off_t off_in_ori = 0;
+	off_t off_out_ori = 0;
+
+	struct tcase *tc = &tcases[i];
+	off_t len = *(tc->len);
+
+	if (tc->off_in) {
+		/*
+		 * off_in/off_out will be changed if it is not NULL,
+		 * here save the original value first
+		 */
+		off_in_ori = *(tc->off_in);
+		off_out_ori = *(tc->off_out);
+	}
+	off_t len_ori = len;
+
+	fd_in = SAFE_OPEN(TEST_FILE_1, O_RDONLY);
+	fd_out = SAFE_OPEN(TEST_FILE_2, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+
+	/*
+	 * copy_file_range() will return the number of bytes copied between files.
+	 * This could be less than the length originally requested.
+	 */
+	do {
+		TEST(tst_syscall(__NR_copy_file_range, fd_in, tc->off_in, fd_out,

tc->off_out, len, 0));

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c new file +33 -0
+		if (TEST_RETURN == -1) {
+			tst_res(TFAIL | TTERRNO, "copy_file_range() failed");
+			SAFE_CLOSE(fd_in);
+			SAFE_CLOSE(fd_out);
+			return;
+		}
+
+		len -= TEST_RETURN;
+	} while (len > 0);
+
+	/* Compare these two file contents */
+	FILE *fp1, *fp2;
+	int ch1, ch2;
+	off_t count = 0;
+
+	fp1 = SAFE_FOPEN(TEST_FILE_1, "r");
+	if (fseek(fp1, off_in_ori, SEEK_SET))
+		tst_brk(TBROK | TERRNO, "fseek() failed");
+
+	fp2 = SAFE_FOPEN(TEST_FILE_2, "r");
+	if (fseek(fp2, off_out_ori, SEEK_SET))
+		tst_brk(TBROK | TERRNO, "fseek() failed");
+
+	do {
+		ch1 = getc(fp1);
+		ch2 = getc(fp2);
+		count++;
+	} while ((count < len_ori) && (ch1 == ch2));
+
+	if (ch1 == ch2) {
+		tst_res(TPASS, "file contents match %ld bytes", len_ori);
+		/*
+		 * If off_in is NULL, the file offset is adjusted by the number of bytes

copied.

(quoted diff) +1 -0
+		 * If off_in is not NULL, the file offset of fd_in is not changed, but

off_in is

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c line 138

Quoted 10 lines
testcases/kernel/syscalls/copy_file_range/copy_file_range01.c new file +10 -0
+		 * adjusted appropriately.
+		 */
+		if (!tc->off_in) {
+			if (SAFE_LSEEK(fd_in, 0, SEEK_CUR) == SAFE_LSEEK(fd_out, 0, SEEK_CUR))
+				tst_res(TPASS, "file offset are same");
+			else
+				tst_res(TFAIL, "file offset are not same");
+		} else {
+			if (*(tc->off_in) == (off_in_ori + len_ori))
+				tst_res(TPASS, "file off_in changed correctly");

What about off_out?

Regards,
Jan

author
#2 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

Quoted 40 lines · Jan Stancek

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

Quoted 28 lines
(quoted diff) +28 -0
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "linux_syscall_numbers.h"
+
+#define TEST_FILE_1 "copy_file_range_ltp01.txt"
+#define TEST_FILE_2 "copy_file_range_ltp02.txt"
+#define STR "abcdefghijklmnopqrstuvwxyz12345\n"
+
+static off_t len1 = 1;   /* 1 */
+static off_t len2;       /* stat.st_size */
+static off_t len3;       /* stat.st_size - 1 */
+static off_t page_size1; /* pagesize - 1 */
+static off_t page_size2; /* pagesize     */
+static off_t page_size3; /* pagesize + 1 */
+
+static struct tcase {
+     off_t *off_in;
+     off_t *off_out;
+     off_t *len;
+} tcases[] = {
+     {NULL,  NULL,  &len1}, /* NULL, NULL, 1 */
+     {NULL,  NULL,  &len2}, /* NULL, NULL, stat.st_size */
+     {&len3, &len3, &len1}, /* stat.st_size - 1, stat.st_size - 1, 1 */
+     {&page_size1, &page_size1, &page_size1}, /* pagesize - 1, pagesize - 1,
Quoted 6 lines

pagesize - 1 */
+ {&page_size2, &page_size2, &page_size2}, /* pagesize, pagesize,
pagesize */
+ {&page_size3, &page_size3, &page_size3}, /* pagesize + 1, pagesize + 1,
pagesize + 1 */
+};

Hi,

Quoted 6 lines

These variables names are a bit confusing. But larger problem is that the values are not stable between iterations. Try:

$ ./copy_file_range01 -i 5

^^ this hangs for me.

That's because variables have been changed in each loop. A simple way to solve that is re-run setup() function before the test.

something like:

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c +4 -1
@@ -66,6 +66,9 @@ static void setup(void)
 
 static void copy_file_range_verify(unsigned int i)
 {
+       if (i > 0)
+               setup();
+
        int fd_in, fd_out;
        off_t off_in_ori = 0;
        off_t off_out_ori = 0;
@@ -134,7 +137,7 @@ static void copy_file_range_verify(unsigned int i)
                        else
                                tst_res(TFAIL, "file offset are not same");
                } else {
-                       if (*(tc->off_in) == (off_in_ori + len_ori))
+                       if (*(tc->off_in) == (off_in_ori + len_ori) &&

*(tc->off_in) == *(tc->off_out) )
tst_res(TPASS, "file off_in changed correctly");
else
tst_res(TFAIL, "file off_in changed
incorrectly");

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+             } else {
+                     if (*(tc->off_in) == (off_in_ori + len_ori))
+                             tst_res(TPASS, "file off_in changed correctly");

What about off_out?

off_out should be detected too. After change in above, test pass from my side:

# ./copy_file_range01 -i 5
tst_test.c:847: INFO: Timeout per run is 0h 05m 00s
copy_file_range01.c:128: PASS: file contents match 1 bytes
copy_file_range01.c:136: PASS: file offset are same
copy_file_range01.c:128: PASS: file contents match 524288 bytes
copy_file_range01.c:136: PASS: file offset are same
...
copy_file_range01.c:141: PASS: file off_in changed correctly
copy_file_range01.c:128: PASS: file contents match 4096 bytes
copy_file_range01.c:141: PASS: file off_in changed correctly
copy_file_range01.c:128: PASS: file contents match 4097 bytes
copy_file_range01.c:141: PASS: file off_in changed correctly

Summary:

passed   60
failed   0
skipped  0

warnings 0

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]
author
#3 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

Quoted 41 lines · Li Wang
Quoted 40 lines · Jan Stancek

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

Quoted 28 lines
(quoted diff) +28 -0
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "linux_syscall_numbers.h"
+
+#define TEST_FILE_1 "copy_file_range_ltp01.txt"
+#define TEST_FILE_2 "copy_file_range_ltp02.txt"
+#define STR "abcdefghijklmnopqrstuvwxyz12345\n"
+
+static off_t len1 = 1;   /* 1 */
+static off_t len2;       /* stat.st_size */
+static off_t len3;       /* stat.st_size - 1 */
+static off_t page_size1; /* pagesize - 1 */
+static off_t page_size2; /* pagesize     */
+static off_t page_size3; /* pagesize + 1 */
+
+static struct tcase {
+     off_t *off_in;
+     off_t *off_out;
+     off_t *len;
+} tcases[] = {
+     {NULL,  NULL,  &len1}, /* NULL, NULL, 1 */
+     {NULL,  NULL,  &len2}, /* NULL, NULL, stat.st_size */
+     {&len3, &len3, &len1}, /* stat.st_size - 1, stat.st_size - 1, 1 */
+     {&page_size1, &page_size1, &page_size1}, /* pagesize - 1, pagesize - 1,
Quoted 6 lines

pagesize - 1 */
+ {&page_size2, &page_size2, &page_size2}, /* pagesize, pagesize,
pagesize */
+ {&page_size3, &page_size3, &page_size3}, /* pagesize + 1, pagesize + 1,
pagesize + 1 */
+};

Hi,

Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

Quoted 14 lines
Quoted 5 lines

that the values are not stable between iterations. Try:

$ ./copy_file_range01 -i 5

^^ this hangs for me.

That's because variables have been changed in each loop. A simple way to solve that is re-run setup() function before the test.

something like:

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c static void setup(void) · line 71

Quoted 6 lines
testcases/kernel/syscalls/copy_file_range/copy_file_range01.c +3 -0
@@ -66,6 +66,9 @@ static void setup(void)
 
 static void copy_file_range_verify(unsigned int i)
 {
+       if (i > 0)
+               setup();
+

Repeat setup() when i > 0 is not wise, after thinking over, a better fix come to mind:

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c +1 -1
@@ -134,7 +134,7 @@ static void copy_file_range_verify(unsigned int i)
                        else
                                tst_res(TFAIL, "file offset are not same");
                } else {
-                       if (*(tc->off_in) == (off_in_ori + len_ori))
+                       if (*(tc->off_in) == *(tc->off_out) &&

*(tc->off_in) == (off_in_ori + len_ori))
tst_res(TPASS, "file off_in changed correctly");
else
tst_res(TFAIL, "file off_in changed
incorrectly");
@@ -147,6 +147,10 @@ static void copy_file_range_verify(unsigned int i)

        SAFE_FCLOSE(fp2);
        SAFE_CLOSE(fd_in);
        SAFE_CLOSE(fd_out);

+
+ /* Reset the test values between iterations */
+ if (i == test.tcnt - 1)
+ setup();
}

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]
#4 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

Quoted 4 lines · Li Wang
Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

I'm attaching copy_file_range01.c, that I made from your v3 version. It doesn't use static list of parameters, but instead iterates over possible values for len/off_in/off_out in all possible combinations.

Let me know what you think about this approach.

Regards,
Jan

-------------- next part --------------
/*
* Copyright (c) Linux Test Project, 2017
*
* 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.
*/

#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include "tst_test.h"
#include "tst_safe_stdio.h"
#include "linux_syscall_numbers.h"

#define TEST_FILE_1 "copy_file_range_ltp01.txt"
#define TEST_FILE_2 "copy_file_range_ltp02.txt"
#define STR "abcdefghijklmnopqrstuvwxyz12345\n"

#define verbose 0

static size_t *len_arr;
static loff_t **off_arr;
static int len_sz, off_sz;

static void setup(void)

{
	int i, fd, page_size;

	page_size = getpagesize();

	fd = SAFE_OPEN(TEST_FILE_1, 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, STR, strlen(STR));
	SAFE_CLOSE(fd);

	len_sz = 4;
	len_arr = malloc(sizeof(size_t) * len_sz);
	len_arr[0] = 11;
	len_arr[1] = page_size - 1;
	len_arr[2] = page_size;
	len_arr[3] = page_size + 1;

	off_sz = 6;
	off_arr = malloc(sizeof(loff_t *) * off_sz);
	for (i = 1; i < off_sz; i++)
		off_arr[i] = malloc(sizeof(loff_t));

	off_arr[0] = NULL;
	*off_arr[1] = 0;
	*off_arr[2] = 17;
	*off_arr[3] = page_size - 1;
	*off_arr[4] = page_size;
	*off_arr[5] = page_size + 1;
}

static int check_file_content(const char *fname1, const char *fname2,

	loff_t *off1, loff_t *off2, size_t len)
{
	FILE *fp1, *fp2;
	int ch1, ch2;
	size_t count = 0;

	fp1 = SAFE_FOPEN(fname1, "r");
	if (off1 && fseek(fp1, *off1, SEEK_SET))
		tst_brk(TBROK | TERRNO, "fseek() failed");

	fp2 = SAFE_FOPEN(fname2, "r");
	if (off2 && fseek(fp2, *off2, SEEK_SET))
		tst_brk(TBROK | TERRNO, "fseek() failed");

	do {
		ch1 = getc(fp1);
		ch2 = getc(fp2);
		count++;
	} while ((count < len) && (ch1 == ch2));

	SAFE_FCLOSE(fp1);
	SAFE_FCLOSE(fp2);

	return !(ch1 == ch2);
}

static int check_file_offset(const char *m, int fd, loff_t len,
loff_t *off_ori, loff_t *off_after)

{
	int ret = 0;

	if (off_ori) {
		/* FD should stay untouched, and off_in/out is updated */
		loff_t fd_off = SAFE_LSEEK(fd, 0, SEEK_CUR);

		if (fd_off == 0) {
			if (verbose)
				tst_res(TPASS, "%s FD offset unchanged", m);
		} else {
			tst_res(TFAIL, "%s FD offset changed: %ld",
				m, (long)fd_off);
			ret = 1;
		}

		if (!off_after) {
			tst_res(TFAIL, "%s offset is NULL", m);
			ret = 1;
		}

		if ((off_after) && (*off_ori + len == *off_after)) {
			if (verbose) {
				tst_res(TPASS, "%s offset advanced as"
					" expected: %ld", m, (long)*off_after);
			}
		} else {
			tst_res(TFAIL, "%s offset unexpected value: %ld",
				m, (long)*off_after);
			ret = 1;
		}
	} else {
		/* FD offset is advanced by len */
		loff_t fd_off = SAFE_LSEEK(fd, 0, SEEK_CUR);

		if (fd_off == len) {
			if (verbose) {
				tst_res(TPASS, "%s FD offset changed as"
					" expected: %ld", m, (long)fd_off);
			}
		} else {
			tst_res(TFAIL, "%s FD offset unexpected value: %ld",
				m, (long)fd_off);
			ret = 1;
		}
	}

	return ret;
}

static void test_one(size_t len, loff_t *off_in, loff_t *off_out)

{
	size_t to_copy = len;
	int fd_in, fd_out, ret;
	loff_t *off_in_ori = off_in;
	loff_t *off_out_ori = off_out;
	loff_t off_in_copy;
	loff_t off_out_copy;
	char str_off_in[32], str_off_out[32];

	if (off_in) {
		off_in_copy = *off_in;
		off_in = &off_in_copy;
		sprintf(str_off_in, "%ld", (long)*off_in);
	} else {
		strcpy(str_off_in, "NULL");
	}

	if (off_out) {
		off_out_copy = *off_out;
		off_out = &off_out_copy;
		sprintf(str_off_out, "%ld", (long)*off_out);
	} else {
		strcpy(str_off_out, "NULL");
	}

	fd_in = SAFE_OPEN(TEST_FILE_1, O_RDONLY);
	fd_out = SAFE_OPEN(TEST_FILE_2, O_CREAT | O_WRONLY | O_TRUNC, 0644);

	/*
	 * copy_file_range() will return the number of bytes copied between
	 * files. This could be less than the length originally requested.
	 */
	do {
		TEST(tst_syscall(__NR_copy_file_range, fd_in, off_in, fd_out,
			off_out, to_copy, 0));
		if (TEST_RETURN == -1) {
			tst_res(TFAIL | TTERRNO, "copy_file_range() failed");
			SAFE_CLOSE(fd_in);
			SAFE_CLOSE(fd_out);
			return;
		}

		to_copy -= TEST_RETURN;
	} while (to_copy > 0);

	ret = check_file_content(TEST_FILE_1, TEST_FILE_2,
		off_in_ori, off_out_ori, len);
	if (ret)
		tst_res(TFAIL, "file contents do not match");

	ret |= check_file_offset("(in)", fd_in, len, off_in_ori, off_in);
	ret |= check_file_offset("(out)", fd_out, len, off_out_ori, off_out);

	tst_res(ret == 0 ? TPASS : TFAIL, "off_in: %s, off_out: %s, len: %ld",
			str_off_in, str_off_out, (long)len);

	SAFE_CLOSE(fd_in);
	SAFE_CLOSE(fd_out);
}

static void copy_file_range_verify(void)

{
	int i, j, k;

	for (i = 0; i < len_sz; i++)
		for (j = 0; j < off_sz; j++)
			for (k = 0; k < off_sz; k++)
				test_one(len_arr[i], off_arr[j], off_arr[k]);
}
static struct tst_test test = {
	.tid = "copy_file_range01",
	.setup = setup,
	.needs_tmpdir = 1,
	.test_all = copy_file_range_verify,
};
author
#5 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

Quoted 11 lines · Jan Stancek
Quoted 4 lines · Li Wang
Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

I'm attaching copy_file_range01.c, that I made from your v3 version. It doesn't use static list of parameters, but instead iterates over possible values for len/off_in/off_out in all possible combinations.

Let me know what you think about this approach.

To split data structure into arrays is more clear than before, and involve the different function make things simple too. I agree to use this approach.

Quoted 17 lines

static void setup(void)

{
      int i, fd, page_size;

      page_size = getpagesize();

      fd = SAFE_OPEN(TEST_FILE_1, 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, STR, strlen(STR));
      SAFE_CLOSE(fd);

      len_sz = 4;
      len_arr = malloc(sizeof(size_t) * len_sz);
      len_arr[0] = 11;
...
      *off_arr[2] = 17;

These two values(11, 17) are just randomized or have special means here?

Regards,
Li Wang

#6 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

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

Quoted 7 lines · Jan Stancek
Quoted 6 lines · Li Wang
Quoted 4 lines
Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

Quoted 8 lines
Quoted 5 lines

I'm attaching copy_file_range01.c, that I made from your v3 version. It doesn't use static list of parameters, but instead iterates over possible values for len/off_in/off_out in all possible combinations.

Let me know what you think about this approach.

To split data structure into arrays is more clear than before, and involve the different function make things simple too. I agree to use this approach.

OK, can this wait after release?

Quoted 13 lines
Quoted 13 lines

static void setup(void)

{
      int i, fd, page_size;

      page_size = getpagesize();

      fd = SAFE_OPEN(TEST_FILE_1, 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, STR, strlen(STR));
      SAFE_CLOSE(fd);
Quoted 7 lines
Quoted 5 lines
      len_sz = 4;
      len_arr = malloc(sizeof(size_t) * len_sz);
      len_arr[0] = 11;
...
      *off_arr[2] = 17;

These two values(11, 17) are just randomized or have special means here?

Just some random small numbers.

Regards,
Jan

author
#7 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

Quoted 14 lines · Jan Stancek

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

Quoted 11 lines · Jan Stancek
Quoted 10 lines · Li Wang
Quoted 4 lines
Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

I'm attaching copy_file_range01.c, that I made from your v3 version. It doesn't use static list of parameters, but instead iterates over possible values for len/off_in/off_out in all possible combinations.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Let me know what you think about this approach.

To split data structure into arrays is more clear than before, and involve the different function make things simple too. I agree to use this approach.

OK, can this wait after release?

Yes, It's OK to me.

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]
#8 lore raw

PATCH v3 1/1 syscalls: add new test for copy_file_range(2)

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

Quoted 18 lines · Jan Stancek
Quoted 17 lines

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

Quoted 14 lines · Jan Stancek
Quoted 12 lines · Li Wang
Quoted 4 lines
Quoted 1 line
Quoted 1 line

These variables names are a bit confusing. But larger problem is

Currently have no idea to improve the confusing issue.

I'm attaching copy_file_range01.c, that I made from your v3 version. It doesn't use static list of parameters, but instead iterates over possible values for len/off_in/off_out in all possible combinations.

Let me know what you think about this approach.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

To split data structure into arrays is more clear than before, and involve the different function make things simple too. I agree to use this approach.

OK, can this wait after release?

Yes, It's OK to me.

Pushed.

Regards,
Jan