Skip to contentSkip to conversation

Add vmsplice03 test

PATCH New Jorik Cronenberg 2 participants 2 messages Nov 26, 2019 – Dec 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add vmsplice03 test

From: jcronenberg <[email protected]>

Add a test for splicing from a pipe to user memory.

---
 testcases/kernel/syscalls/vmsplice/.gitignore |  1 +
 .../kernel/syscalls/vmsplice/vmsplice03.c     | 70 +++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 testcases/kernel/syscalls/vmsplice/vmsplice03.c
testcases/kernel/syscalls/vmsplice/.gitignore +1 -0
index 2cc74a956..03922073c 100644
@@ -1,2 +1,3 @@
 /vmsplice01
 /vmsplice02
+/vmsplice03
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/1 Add vmsplice03 test

Hi!

Quoted 27 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +21 -0
new file mode 100644
index 000000000..54dace1b6
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 SUSE LLC
+ * Author: Jorik Cronenberg <[email protected]>
+ *
+ * Test vmsplice() from a pipe into user memory
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+#include "lapi/vmsplice.h"
+
+
+#define TEST_BLOCK_SIZE (64*1024)	/* 64K */
+
+static char buffer[TEST_BLOCK_SIZE];
+static off64_t offset;
+
+static void vmsplice_test(void)

testcases/kernel/syscalls/vmsplice/vmsplice03.c line 31

Quoted 10 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +10 -0
+{
+	int written, i;
+	int pipes[2];
+	struct iovec iov;
+	char arr_write[TEST_BLOCK_SIZE];
+	char *arr_read;
+
+	iov.iov_base = arr_write;
+	iov.iov_len = TEST_BLOCK_SIZE;
+	offset = sizeof(struct iovec);

It may be a good idea to memset the arr_write[] array with well defined data, e.g. 0 just to be sure that kernel really filled it.

testcases/kernel/syscalls/vmsplice/vmsplice03.c line 36

Quoted 4 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +4 -0
+	SAFE_PIPE(pipes);
+	SAFE_WRITE(1, pipes[1], buffer, TEST_BLOCK_SIZE);
+	written = vmsplice(pipes[0], &iov, 1, 0);
+	arr_read = (char *)&iov;

This only works by accident because the arr_write is put on the stack after the iovec structure and there is no padding in between them.

What you really should do is to use the arr_write pointer in the comparsion instead. The struc iovec is just a description of an buffer that starts in memory at arr_write address and is iov_len long because the kernel has to know its lenght.

testcases/kernel/syscalls/vmsplice/vmsplice03.c line 40

Quoted 3 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +3 -0
+	if (written < 0)
+		tst_brk(TBROK | TERRNO, "vmsplice() failed");
+	else if (written == 0)

There is no need for an else branch after tst_brk() because tst_brk() will exit the test immediately.

Quoted 20 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +20 -0
+		tst_res(TFAIL, "vmsplice() didn't write anything");
+	else {
+		for (i = 0; i < written; i++) {
+			if (arr_read[i+offset] != buffer[i]) {
+				tst_res(TFAIL,
+					"Wrong data in user memory at %i", i);
+				break;
+			}
+		}
+		if (i == written)
+			tst_res(TPASS, "Spliced correctly into user memory");
+	}
+
+	SAFE_CLOSE(pipes[1]);
+	SAFE_CLOSE(pipes[0]);
+}
+
+static void setup(void)
+{
+	int i;

testcases/kernel/syscalls/vmsplice/vmsplice03.c line 70

Quoted 10 lines
testcases/kernel/syscalls/vmsplice/vmsplice03.c new file +10 -0
+
+	for (i = 0; i < TEST_BLOCK_SIZE; i++)
+		buffer[i] = i & 0xff;
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = vmsplice_test,
+	.min_kver = "2.6.23",
+};

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]