Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 2 participants 2 messages Mar 31, 2017 – Apr 3, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

119 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

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

Hi!

Quoted 9 lines
testcases/kernel/syscalls/splice/splice04.c new file +9 -0
+/*
+ * Functional test for splice(2): pipe to pipe
+ *
+ * This test case tests splice(2) from a pipe to another
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <fcntl.h>

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

Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10 -0
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define MAX_DATA_LEN (64*1024)
+
+static void setup(void);
+static void cleanup(void);
+static void maintest(void);
+static int cmp_data(void);
+static int pipe_pipe(void);

Nearly all of these are not needed, the only one is the pipe_pipe() called from maintest() and this wouldn't be needed if there is no maintest function anyway.

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

Quoted 2 lines
testcases/kernel/syscalls/splice/splice04.c new file +2 -0
+static char *str_len_data;
+static int num_len_data;

You can initialize the num_len_data to MAX_DATA_LEN here and drop the if (!num_len_data) condition from the setup()

Quoted 8 lines
testcases/kernel/syscalls/splice/splice04.c new file +8 -0
+static char *arr_in;
+static char *arr_out;
+
+static struct tst_option options[] = {
+	{"l:", &str_len_data, "-l <num> Length of test data (in bytes)"},
+	{NULL, NULL, NULL},
+};
+

testcases/kernel/syscalls/splice/splice04.c

Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10 -0
+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);
+	if (!num_len_data)
+		num_len_data = MAX_DATA_LEN;
+
+	fprintf(stdout, "splice size = %d\n", num_len_data);

Use tst_res(TINFO, ) here.

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

Quoted 4 lines
testcases/kernel/syscalls/splice/splice04.c new file +4 -0
+	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;
                 ^
		 This is just more complicated way how to write
		 arr_in[i] = ...

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

Quoted 8 lines
testcases/kernel/syscalls/splice/splice04.c new file +8 -0
+}
+
+static void cleanup(void)
+{
+	if (arr_in != NULL)
+		free(arr_in);
+	if (arr_out != NULL)
+		free(arr_out);

Do just free(arr_in) and free(arr_out) here, free(NULL) is no-op.

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

Quoted 8 lines
testcases/kernel/syscalls/splice/splice04.c new file +8 -0
+}
+
+static void maintest(void)
+{
+	if (pipe_pipe())
+		tst_res(TFAIL, "splice(2) from pipe to pipe fails.");
+	else
+		tst_res(TPASS, "splice(2) from pipe to pipe run pass.");

Why do we need a separate function just to print the PASS/FAIL ?

Why can't we just print PASS/FAIL in the cmp_data() function?

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

Quoted 8 lines
testcases/kernel/syscalls/splice/splice04.c new file +8 -0
+}
+
+static int cmp_data(void)
+{
+	int i;
+
+	for (i = 0; i < num_len_data; i++) {
+		if (*(arr_in + i) != *(arr_out + i)) {

^
Again this is the same as arr_in[i] and arr_out[i]

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

Quoted 1 line
testcases/kernel/syscalls/splice/splice04.c new file +1 -0
+			tst_res(TBROK, "Data mismatch after splice operation.");

^
This message here does not make sense, it's clear TFAIL.

Quoted 4 lines
testcases/kernel/syscalls/splice/splice04.c new file +4 -0
+			return -1;
+		}
+	}
+	return 0;

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

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

You should really check the return value from the syscall you are supposed to test...

Quoted 24 lines
testcases/kernel/syscalls/splice/splice04.c new file +18 -0
+	SAFE_READ(1, pp2[0], arr_out, num_len_data);
+
+	SAFE_CLOSE(pp1[1]);
+	SAFE_CLOSE(pp1[0]);
+	SAFE_CLOSE(pp2[1]);
+	SAFE_CLOSE(pp2[0]);
+
+	return cmp_data();
+}
+
+static struct tst_test test = {
+	.tid = "splice04",
+	.test_all = maintest,
+	.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]