]> granicus.if.org Git - strace/commitdiff
tests: check the latest MSG_TRUNC decoding fix
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 2 Aug 2019 16:53:02 +0000 (16:53 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 2 Aug 2019 16:53:02 +0000 (16:53 +0000)
* 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.

tests/.gitignore
tests/gen_tests.in
tests/pure_executables.list
tests/recv-MSG_TRUNC.c [new file with mode: 0644]
tests/recvfrom-MSG_TRUNC.c [new file with mode: 0644]

index 7774ceecbf88709ca6aaf9e016f3dd1bc2dacf40..2b0993506320aefc5068978f30ee5c01e51ae968 100644 (file)
@@ -463,7 +463,9 @@ readlink
 readlinkat
 readv
 reboot
+recv-MSG_TRUNC
 recvfrom
+recvfrom-MSG_TRUNC
 recvmmsg-timeout
 recvmsg
 redirect-fds
index f90910f1815c675173e2ecdd248d0c9936d50bd9..4a506b94c2a9d680417a40395c3718a503b77a7f 100644 (file)
@@ -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'
index 3224999ee379ce843cd3b64d2518689e33b7952f..f55ae8a83f048554812c15154581926ef4ba3e81 100755 (executable)
@@ -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 (file)
index 0000000..ee9ea63
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Check decoding of recv MSG_TRUNC.
+ *
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <errno.h>
+#include <stdio.h>
+#include <sys/socket.h>
+#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 (file)
index 0000000..b8ef378
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Check decoding of recvfrom MSG_TRUNC.
+ *
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <stdio.h>
+#include <sys/socket.h>
+
+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;
+}