summaryrefslogtreecommitdiff
path: root/tests/recvfrom-MSG_TRUNC.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2019-08-02 16:53:02 +0000
committerDmitry V. Levin <ldv@altlinux.org>2019-08-02 16:53:02 +0000
commit7f39f00a3780a84be6aa2d170e1129e7e31ffd8b (patch)
treec5ffb33b7d0605634c55ce5ee7c03cac90c1eb0d /tests/recvfrom-MSG_TRUNC.c
parentf565ae4cc7841e1525987e763defa0204c7398b4 (diff)
downloadstrace-7f39f00a3780a84be6aa2d170e1129e7e31ffd8b.tar.gz
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.
Diffstat (limited to 'tests/recvfrom-MSG_TRUNC.c')
-rw-r--r--tests/recvfrom-MSG_TRUNC.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/recvfrom-MSG_TRUNC.c b/tests/recvfrom-MSG_TRUNC.c
new file mode 100644
index 000000000..b8ef37867
--- /dev/null
+++ b/tests/recvfrom-MSG_TRUNC.c
@@ -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;
+}