From: Dmitry V. Levin Date: Fri, 2 Aug 2019 16:53:02 +0000 (+0000) Subject: tests: check the latest MSG_TRUNC decoding fix X-Git-Tag: v5.3~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f39f00a3780a84be6aa2d170e1129e7e31ffd8b;p=strace tests: check the latest MSG_TRUNC decoding fix * tests/recv-MSG_TRUNC.c: New file. * tests/recvfrom-MSG_TRUNC.c: Likewise. * tests/gen_tests.in (recv-MSG_TRUNC, recvfrom-MSG_TRUNC): New entries. * tests/pure_executables.list: Add recv-MSG_TRUNC and recvfrom-MSG_TRUNC. * tests/.gitignore: Likewise. --- diff --git a/tests/.gitignore b/tests/.gitignore index 7774ceec..2b099350 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -463,7 +463,9 @@ readlink readlinkat readv reboot +recv-MSG_TRUNC recvfrom +recvfrom-MSG_TRUNC recvmmsg-timeout recvmsg redirect-fds diff --git a/tests/gen_tests.in b/tests/gen_tests.in index f90910f1..4a506b94 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -380,7 +380,9 @@ readdir -a16 readlink -xx readlinkat -xx reboot -s 256 +recv-MSG_TRUNC -a26 -e trace=recv recvfrom -a35 +recvfrom-MSG_TRUNC -e trace=recvfrom recvmmsg-timeout -a25 -e trace=recvmmsg recvmsg -eread=0 -ewrite=1 -e trace=recvmsg,sendmsg regex test_trace_expr '' -etrace='/^(.*_)?statv?fs' diff --git a/tests/pure_executables.list b/tests/pure_executables.list index 3224999e..f55ae8a8 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -390,7 +390,9 @@ readlink readlinkat readv reboot +recv-MSG_TRUNC recvfrom +recvfrom-MSG_TRUNC recvmmsg-timeout recvmsg remap_file_pages diff --git a/tests/recv-MSG_TRUNC.c b/tests/recv-MSG_TRUNC.c new file mode 100644 index 00000000..ee9ea632 --- /dev/null +++ b/tests/recv-MSG_TRUNC.c @@ -0,0 +1,59 @@ +/* + * Check decoding of recv MSG_TRUNC. + * + * Copyright (c) 2019 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include +#include +#include +#include "scno.h" + +#ifndef __NR_recv +# define __NR_recv -1 +#endif +#define SC_recv 10 + +static int +sys_recv(int sockfd, const void *buf, unsigned int len, int flags) +{ + int rc = socketcall(__NR_recv, SC_recv, + sockfd, (long) buf, len, flags, 0); + if (rc < 0 && ENOSYS == errno) + perror_msg_and_skip("recv"); + return rc; +} + +int +main(void) +{ + static const char sbuf[2] = "AB"; + int sv[2]; + TAIL_ALLOC_OBJECT_CONST_PTR(char, rbuf); + + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv)) + perror_msg_and_skip("socketpair"); + + if (send(sv[1], sbuf + 1, 1, 0) != 1) + perror_msg_and_skip("send"); + if (sys_recv(sv[0], rbuf - 1, 2, MSG_PEEK) != 1) + perror_msg_and_fail("recv"); + printf("recv(%d, \"B\", 2, MSG_PEEK) = 1\n", sv[0]); + + if (sys_recv(sv[0], rbuf, 1, MSG_TRUNC) != 1) + perror_msg_and_skip("recv"); + printf("recv(%d, \"B\", 1, MSG_TRUNC) = 1\n", sv[0]); + + if (send(sv[1], sbuf, 2, 0) != 2) + perror_msg_and_skip("send"); + if (sys_recv(sv[0], rbuf, 1, MSG_TRUNC) != 2) + perror_msg_and_skip("recv"); + printf("recv(%d, \"A\", 1, MSG_TRUNC) = 2\n", sv[0]); + + puts("+++ exited with 0 +++"); + return 0; +} diff --git a/tests/recvfrom-MSG_TRUNC.c b/tests/recvfrom-MSG_TRUNC.c new file mode 100644 index 00000000..b8ef3786 --- /dev/null +++ b/tests/recvfrom-MSG_TRUNC.c @@ -0,0 +1,42 @@ +/* + * Check decoding of recvfrom MSG_TRUNC. + * + * Copyright (c) 2019 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include +#include + +int +main(void) +{ + static const char sbuf[2] = "AB"; + int sv[2]; + TAIL_ALLOC_OBJECT_CONST_PTR(char, rbuf); + + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv)) + perror_msg_and_skip("socketpair"); + + if (send(sv[1], sbuf + 1, 1, 0) != 1) + perror_msg_and_skip("send"); + if (recvfrom(sv[0], rbuf - 1, 2, MSG_PEEK, NULL, NULL) != 1) + perror_msg_and_fail("recvfrom"); + printf("recvfrom(%d, \"B\", 2, MSG_PEEK, NULL, NULL) = 1\n", sv[0]); + + if (recvfrom(sv[0], rbuf, 1, MSG_TRUNC, NULL, NULL) != 1) + perror_msg_and_skip("recvfrom"); + printf("recvfrom(%d, \"B\", 1, MSG_TRUNC, NULL, NULL) = 1\n", sv[0]); + + if (send(sv[1], sbuf, 2, 0) != 2) + perror_msg_and_skip("send"); + if (recvfrom(sv[0], rbuf, 1, MSG_TRUNC, NULL, NULL) != 2) + perror_msg_and_skip("recvfrom"); + printf("recvfrom(%d, \"A\", 1, MSG_TRUNC, NULL, NULL) = 2\n", sv[0]); + + puts("+++ exited with 0 +++"); + return 0; +}