Skip to contentSkip to conversation

syscalls/splice04: add test for splice() from pipe to pipe

PATCH Superseded [email protected] 2 participants 5 messages May 12, 2017 – May 19, 2017

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 | 106 ++++++++++++++++++++++++++++
 3 files changed, 108 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 +106 -0

106 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

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

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 | 122 ++++++++++++++++++++++++++++
 3 files changed, 124 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 +122 -0

122 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

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

Hi!

testcases/kernel/syscalls/splice/splice05.c line 58

Quoted 12 lines
testcases/kernel/syscalls/splice/splice05.c new file +12 -0
+static void setup(void)
+{
+	int i, pipe_max_unpriv, pipe_limit;
+
+	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
+	pipe_limit = pipe_max_unpriv < num_len_data ? pipe_max_unpriv :
+		num_len_data;
+	num_len_data = pipe_limit;
+
+	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);

Here as well.

Quoted 29 lines
testcases/kernel/syscalls/splice/splice05.c new file +29 -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;
+
+}
+
+static void cleanup(void)
+{
+	free(arr_in);
+	free(arr_out);
+}
+
+static void pipe_socket(void)
+{
+	int pp1[2], pp2[2], sv[2], i, ret;
+
+	SAFE_PIPE(pp1);
+	SAFE_PIPE(pp2);
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
+		tst_brk(TBROK | TERRNO, "fail to create socket pair.");
+
+	SAFE_WRITE(1, pp1[1], arr_in, num_len_data);
+	for (i = 0; i < num_len_data; i++) {
+		ret = splice(pp1[0], NULL, sv[0], 0, 1, SPLICE_F_MOVE);
+		if (ret == -1) {
+			tst_res(TFAIL | TERRNO, "splice error");
+			goto exit;

testcases/kernel/syscalls/splice/splice05.c line 97

Quoted 10 lines
testcases/kernel/syscalls/splice/splice05.c new file +10 -0
+		}
+	}
+	for (i = 0; i < num_len_data; i++) {
+		ret = splice(sv[1], 0, pp2[1], NULL, 1, SPLICE_F_MOVE);
+		if (ret == -1) {
+			tst_res(TFAIL | TERRNO, "splice error");
+			goto exit;
+		}
+		SAFE_READ(1, pp2[0], arr_out + i, 1);
+	}

And here as well.

Quoted 30 lines
testcases/kernel/syscalls/splice/splice05.c new file +24 -0
+	for (i = 0; i < num_len_data; i++) {
+		if (arr_in[i] != arr_out[i]) {
+			tst_res(TFAIL, "wrong data at %d: expected: %d, "
+				"actual %d", i, arr_in[i], arr_out[i]);
+			goto exit;
+		}
+	}
+	tst_res(TPASS, "splice(2): pipe <-> socket run pass.");
+exit:
+	for (i = 0; i < 2; i++) {
+		SAFE_CLOSE(pp1[i]);
+		SAFE_CLOSE(pp2[i]);
+		SAFE_CLOSE(sv[i]);
+	}
+}
+
+static struct tst_test test = {
+	.tid = "splice05",
+	.test_all = pipe_socket,
+	.setup = setup,
+	.cleanup = cleanup,
+	.options = options,
+	.min_kver = "2.6.17"
+};
Signature · 5 lines
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

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

In reply to [email protected]

Hi!

Quoted 13 lines
testcases/kernel/syscalls/splice/splice04.c new file +13 -0
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define PIPE_MAX (64*1024)
+
+static char *str_len_data;
+static int num_len_data = PIPE_MAX;
+static char *arr_in, *arr_out;
+
+static struct tst_option options[] = {
+	{"l:", &str_len_data, "-l <num> Length of test data (in bytes)"},

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10 -0
+	{NULL, NULL, NULL},
+};
+
+static void setup(void)
+{
+	int i, pipe_max_unpriv, pipe_limit;
+
+	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
+	pipe_limit = pipe_max_unpriv < num_len_data ? pipe_max_unpriv :
+		num_len_data;

Hmm, this is case for a MIN() macro. I guess that I should add MIN() and MAX*() to the tst_test.h header since we have several uses in the testcases already.

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

Quoted 5 lines
testcases/kernel/syscalls/splice/splice04.c new file +5 -0
+	num_len_data = pipe_limit;
+
+	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);

There should be curly braces around the multiline statement.

Quoted 18 lines
testcases/kernel/syscalls/splice/splice04.c new file +18 -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;
+}
+
+static void cleanup(void)
+{
+	free(arr_in);
+	free(arr_out);
+}
+
+static void pipe_pipe(void)
+{
+	int pp1[2], pp2[2], i, ret;
+
+	SAFE_PIPE(pp1);

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10 -0
+	SAFE_PIPE(pp2);
+	SAFE_WRITE(1, pp1[1], arr_in, num_len_data);
+	for (i = 0; i < num_len_data; i++) {
+		ret = splice(pp1[0], NULL, pp2[1], NULL, 1, SPLICE_F_MOVE);
+		if (ret == -1) {
+			tst_res(TFAIL | TERRNO, "splice error");
+			goto exit;
+		}
+		SAFE_READ(1, pp2[0], arr_out + i, 1);
+	}

I do not understand why we are moving the data byte by byte here?

And also the SPLICE_F_MOVE flag, even if that was correctly implemented, would be useless here.

Quoted 30 lines
testcases/kernel/syscalls/splice/splice04.c new file +24 -0
+	for (i = 0; i < num_len_data; i++) {
+		if (arr_in[i] != arr_out[i]) {
+			tst_res(TFAIL, "wrong data at %d: expected: %d, "
+				"actual: %d", i, arr_in[i], arr_out[i]);
+			goto exit;
+		}
+	}
+	tst_res(TPASS, "splice(2) from pipe to pipe run pass.");
+
+exit:
+	SAFE_CLOSE(pp1[1]);
+	SAFE_CLOSE(pp1[0]);
+	SAFE_CLOSE(pp2[1]);
+	SAFE_CLOSE(pp2[0]);
+}
+
+static struct tst_test test = {
+	.tid = "splice04",
+	.test_all = pipe_pipe,
+	.setup = setup,
+	.cleanup = cleanup,
+	.options = options,
+	.min_kver = "2.6.31"
+};
Signature · 5 lines
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

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

Hi!

Quoted 14 lines

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

Quoted 11 lines
testcases/kernel/syscalls/splice/splice04.c new file +11 -0
+	SAFE_PIPE(pp1);
+	SAFE_PIPE(pp2);
+	SAFE_WRITE(1, pp1[1], arr_in, num_len_data);
+	for (i = 0; i < num_len_data; i++) {
+		ret = splice(pp1[0], NULL, pp2[1], NULL, 1, SPLICE_F_MOVE);
+		if (ret == -1) {
+			tst_res(TFAIL | TERRNO, "splice error");
+			goto exit;
+		}
+		SAFE_READ(1, pp2[0], arr_out + i, 1);
+	}

I do not understand why we are moving the data byte by byte here?

Quoted 2 lines

And also the SPLICE_F_MOVE flag, even if that was correctly implemented, would be useless here.

Looked at the previous version of the patch and the comment from Jan.

What he meant there was that we should decrease the number of requested bytes by the number of bytes we spliced already.

Signature · 2 lines
Cyril Hrubis
[email protected]