Skip to contentSkip to conversation

add test case splice04 and splice05

PATCH Superseded [email protected] 2 participants 4 messages May 2, 2017 – May 3, 2017

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover add test case splice04 and splice05

From: Boyang Xue <[email protected]>

Hi,

Please help me review the following test cases. Thanks.

Changes from patchset v2:
add built test case binary in right .gitignore file

Changes from patchset v1:
1) add built test case binary in .gitignore
2) restrict test data size so as to honor /proc/sys/fs/pipe-max-size
3) do splice() in a loop in case not all data are splice-ed in a single operation

-Boyang

Boyang Xue (2):
syscalls/splice04: add test for splice() from pipe to pipe syscalls/splice05: add test for splice() between pipe and socket

 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/.gitignore        |   2 +
 testcases/kernel/syscalls/splice/splice04.c | 117 ++++++++++++++++++++++++
 testcases/kernel/syscalls/splice/splice05.c | 134 ++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+)
 create mode 100644 testcases/kernel/syscalls/splice/splice04.c
 create mode 100644 testcases/kernel/syscalls/splice/splice05.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/2 syscalls/splice04: add test for splice() from pipe to pipe

From: Boyang Xue <[email protected]>

This test case covers pipe to pipe splice operation, which was introduced in kernel commit 7c77f0b3f920 ("splice: implement pipe to pipe splicing").

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/.gitignore        |   1 +
 testcases/kernel/syscalls/splice/splice04.c | 117 ++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+)
 create mode 100644 testcases/kernel/syscalls/splice/splice04.c
runtest/syscalls +1 -0
index 5909456..d6c9ab4 100644
@@ -1224,6 +1224,7 @@ sockioctl01 sockioctl01
 splice01 splice01
 splice02 seq 1 20000 | splice02 splice02-temp
 splice03 splice03
+splice04 splice04
 
 tee01 tee01
 tee02 tee02
testcases/kernel/syscalls/.gitignore +1 -0
index d5985cd..92ddbbe 100644
@@ -976,6 +976,7 @@
 /splice/splice01
 /splice/splice02
 /splice/splice03
+/splice/splice04
 /ssetmask/ssetmask01
 /stat/stat01
 /stat/stat01_64
testcases/kernel/syscalls/splice/splice04.c new file +117 -0

117 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v3 1/2 syscalls/splice04: add test for splice() from pipe to pipe

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

Quoted 6 lines

From: Boyang Xue <[email protected]>

This test case covers pipe to pipe splice operation, which was introduced in kernel commit 7c77f0b3f920 ("splice: implement pipe to pipe splicing").

Hi,

Many lines go over 80 characters.

Quoted 14 lines
testcases/kernel/syscalls/splice/splice04.c new file +13 -0
+static void setup(void)
+{
+	int i, fd, pipe_max_unpriv, pipe_limit;
+	FILE *s;
+
+	fd = SAFE_OPEN("/proc/sys/fs/pipe-max-size", O_RDONLY);
+	s = fdopen(fd, "r");
+	if (s == NULL)
+		tst_brk(TBROK, "fdopen() error");
+	if (fscanf(s, "%d", &pipe_max_unpriv) != 1)
+		tst_brk(TBROK, "Fail to get value of /proc/sys/fs/pipe-max-size");
+	else {
+		pipe_limit = pipe_max_unpriv < num_len_data ? pipe_max_unpriv :

num_len_data;

testcases/kernel/syscalls/splice/splice04.c line 60

Quoted 4 lines
testcases/kernel/syscalls/splice/splice04.c new file +4 -0
+		num_len_data = pipe_limit;
+	}
+	if (fclose(s) == EOF)
+		tst_brk(TBROK, "Fail to close file");

You can use helper macro: SAFE_FILE_SCANF

Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +3 -0
+
+	if (tst_parse_int(str_len_data, &num_len_data, 1, pipe_limit))
+		tst_brk(TBROK, "Invalid length of data: '%s', valid value: [1, %d]",

str_len_data, pipe_limit);

testcases/kernel/syscalls/splice/splice04.c new file +6 -0
+	tst_res(TINFO, "splice size = %d", num_len_data);
+	arr_in = SAFE_MALLOC(num_len_data);
+	arr_out = SAFE_MALLOC(num_len_data);
+	for (i = 0; i < num_len_data; i++)
+		arr_in[i] = i & 0xff;
+}

...

testcases/kernel/syscalls/splice/splice04.c line 85

Quoted 9 lines
testcases/kernel/syscalls/splice/splice04.c new file +9 -0
+static void pipe_pipe(void)
+{
+	int pp1[2], pp2[2], i, ret;
+
+	SAFE_PIPE(pp1);
+	SAFE_PIPE(pp2);
+	SAFE_WRITE(1, pp1[1], arr_in, num_len_data);
+	do {
+		ret = splice(pp1[0], NULL, pp2[1], NULL, num_len_data, SPLICE_F_MOVE);

You always try to splice num_len_data bytes, which can lead to hang if this loop runs multiple times, because there aren't enough bytes in pipe after first splice.

For example, on 4.10:
[pid 2987] 11:55:49.090001 splice(3, NULL, 6, NULL, 65536, SPLICE_F_MOVE) = 32768 [pid 2987] 11:55:49.090073 splice(3, NULL, 6, NULL, 65536, SPLICE_F_MOVE<hangs>

We have 65536 bytes in pipe, first splice transfered half of that, second splice is again trying to transfer 65536 bytes.

testcases/kernel/syscalls/splice/splice04.c line 87

Quoted 2 lines
testcases/kernel/syscalls/splice/splice04.c new file +2 -0
+		if (ret == 0)
+			break;

from man2 splice:
"A return value of 0 means end of input. If fd_in refers to a pipe, then this means that there was no data to trans� fer, and it would not make sense to block because there are no writers connected to the write end of the pipe."

Since you still have write end opened it can block rather than return 0. Also, it makes sense only if fd_in is pipe, which is not the case of splice05 testcase.

testcases/kernel/syscalls/splice/splice04.c line 92

Quoted 5 lines
testcases/kernel/syscalls/splice/splice04.c new file +5 -0
+		else if (ret == -1) {
+			tst_res(TFAIL | TERRNO, "splice error");
+			goto exit;
+		}
+	} while (num_len_data - ret);

Unless first splice transfers all, this condition is always true.

Regards,
Jan

#3 lore raw

PATCH v3 2/2 syscalls/splice05: add test for splice() between pipe and socket

In reply to [email protected]

From: Boyang Xue <[email protected]>

This test case covers splice operation between pipe and socket.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/.gitignore        |   1 +
 testcases/kernel/syscalls/splice/splice05.c | 134 ++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
 create mode 100644 testcases/kernel/syscalls/splice/splice05.c
runtest/syscalls +1 -0
index d6c9ab4..0fae11a 100644
@@ -1225,6 +1225,7 @@ splice01 splice01
 splice02 seq 1 20000 | splice02 splice02-temp
 splice03 splice03
 splice04 splice04
+splice05 splice05
 
 tee01 tee01
 tee02 tee02
testcases/kernel/syscalls/.gitignore +1 -0
index 92ddbbe..604730f 100644
@@ -977,6 +977,7 @@
 /splice/splice02
 /splice/splice03
 /splice/splice04
+/splice/splice05
 /ssetmask/ssetmask01
 /stat/stat01
 /stat/stat01_64
testcases/kernel/syscalls/splice/splice05.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
1.8.3.1