Commit 3667e9b4 authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Jakub Kicinski
Browse files

selftests: tls: add test for short splice due to full skmsg



We don't have a test triggering a partial splice caused by a full
skmsg. Add one, based on a program by Jann Horn.

Use MAX_FRAGS=48 to make sure the skmsg will be full for any allowed
value of CONFIG_MAX_SKB_FRAGS (17..45).

Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Link: https://patch.msgid.link/1d129a15f526ea3602f3a2b368aa0b6f7e0d35d5.1760432043.git.sd@queasysnail.net


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f95fce1e
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -946,6 +946,37 @@ TEST_F(tls, peek_and_splice)
	EXPECT_EQ(memcmp(mem_send, mem_recv, send_len), 0);
}

#define MAX_FRAGS 48
TEST_F(tls, splice_short)
{
	struct iovec sendchar_iov;
	char read_buf[0x10000];
	char sendbuf[0x100];
	char sendchar = 'S';
	int pipefds[2];
	int i;

	sendchar_iov.iov_base = &sendchar;
	sendchar_iov.iov_len = 1;

	memset(sendbuf, 's', sizeof(sendbuf));

	ASSERT_GE(pipe2(pipefds, O_NONBLOCK), 0);
	ASSERT_GE(fcntl(pipefds[0], F_SETPIPE_SZ, (MAX_FRAGS + 1) * 0x1000), 0);

	for (i = 0; i < MAX_FRAGS; i++)
		ASSERT_GE(vmsplice(pipefds[1], &sendchar_iov, 1, 0), 0);

	ASSERT_EQ(write(pipefds[1], sendbuf, sizeof(sendbuf)), sizeof(sendbuf));

	EXPECT_EQ(splice(pipefds[0], NULL, self->fd, NULL, MAX_FRAGS + 0x1000, 0),
		  MAX_FRAGS + sizeof(sendbuf));
	EXPECT_EQ(recv(self->cfd, read_buf, sizeof(read_buf), 0), MAX_FRAGS + sizeof(sendbuf));
	EXPECT_EQ(recv(self->cfd, read_buf, sizeof(read_buf), MSG_DONTWAIT), -1);
	EXPECT_EQ(errno, EAGAIN);
}
#undef MAX_FRAGS

TEST_F(tls, recvmsg_single)
{
	char const *test_str = "test_recvmsg_single";