Skip to contentSkip to conversation

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

PATCH New [email protected] 2 participants 2 messages Apr 7, 2017 – Apr 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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/splice/splice05.c | 113 ++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
 create mode 100644 testcases/kernel/syscalls/splice/splice05.c
runtest/syscalls +1 -0
index 15ae66e..48b32d6 100644
@@ -1222,6 +1222,7 @@ sockioctl01 sockioctl01
 splice01 splice01
 splice02 seq 1 20000 | splice02 splice02-temp
 splice03 splice03
+splice05 splice05
 
 tee01 tee01
 tee02 tee02
testcases/kernel/syscalls/splice/splice05.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

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

Hi!

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

Quoted 5 lines
testcases/kernel/syscalls/splice/splice05.c new file +5 -0
+#define MAX_DATA_LEN (64*1024)
+
+static void setup(void);
+static void cleanup(void);
+static void pipe_socket(void);

These function prototypes are useless.

Quoted 7 lines
testcases/kernel/syscalls/splice/splice05.c new file +7 -0
+static char *arr_in, *arr_out;
+static char *str_len_data;
+static int num_len_data = MAX_DATA_LEN;
+static int pp0[2], pp1[2], sv[2];
+
+static struct tst_option options[] = {
+	{"l:", &str_len_data, "-l <num> Length of test data (in bytes)"},

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice05.c new file +10 -0
+	{NULL, NULL, NULL},
+};
+
+static void setup(void)
+{
+	int i;
+
+	if (tst_parse_int(str_len_data, &num_len_data, 1, MAX_DATA_LEN))
+		tst_brk(TBROK, "Invalid length of data: '%s'", str_len_data);
+	tst_res(TINFO, "splice size = %d\n", num_len_data);

^
Second newline here as well.

Quoted 7 lines
testcases/kernel/syscalls/splice/splice05.c new file +7 -0
+	arr_in = SAFE_MALLOC(num_len_data);
+	for (i = 0; i < num_len_data; i++)
+		arr_in[i] = i & 0xff;
+}
+
+static void cleanup(void)
+{

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice05.c new file +10 -0
+	int i;
+
+	free(arr_in);
+	free(arr_out);
+
+	for (i = 0; i < 2; i++) {
+		SAFE_CLOSE(pp0[i]);
+		SAFE_CLOSE(pp1[i]);
+		SAFE_CLOSE(sv[i]);
+	}

If you open the pipes/sockets in the test function you have to close it there in case that the test function is executed in a loop. Otherwise the test may fail when file descriptors are used up.

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice05.c new file +10 -0
+}
+
+static void pipe_socket(void)
+{
+	int i;
+
+	SAFE_PIPE(pp0);
+	SAFE_PIPE(pp1);
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
+		tst_brk(TBROK, "fail to create socket pair.");

^
We should print errno with TERRNO here.

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

Quoted 5 lines
testcases/kernel/syscalls/splice/splice05.c new file +5 -0
+	SAFE_WRITE(1, pp0[1], arr_in, num_len_data);
+	if (splice(pp0[0], NULL, sv[0], 0, num_len_data, SPLICE_F_MOVE) != num_len_data)
+		tst_res(TFAIL, "incomplete splice operation.");
+	if (splice(sv[1], 0, pp1[1], NULL, num_len_data, SPLICE_F_MOVE) != num_len_data)
+		tst_res(TFAIL, "incomplete splice operation.");

Here as well we should print the splice return value and errno.

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

Quoted 1 line
testcases/kernel/syscalls/splice/splice05.c new file +1 -0
+	arr_out = SAFE_MALLOC(num_len_data);

Why do we allocate the arr_out here insetad of setup?

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

Quoted 5 lines
testcases/kernel/syscalls/splice/splice05.c new file +5 -0
+	SAFE_READ(1, pp1[0], arr_out, num_len_data);
+
+	for (i = 0; i < num_len_data; i++) {
+		if (arr_in[i] != arr_out[i]) {
+			tst_res(TFAIL, "splice(2): pipe <-> socket fails.");

Here as well you may print more info about the buffer.

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

Quoted 5 lines
testcases/kernel/syscalls/splice/splice05.c new file +5 -0
+			return;
+		}
+	}
+	tst_res(TPASS, "splice(2): pipe <-> socket run pass.");
+	return;

Useless return here as well.

Quoted 16 lines
testcases/kernel/syscalls/splice/splice05.c new file +10 -0
+}
+
+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]