mmsg.test: fix regression introduced by commit v4.11-138-g6e815ce
This fixes the test on platforms where both __NR_sendmmsg and
HAVE_SENDMMSG are defined but the former is not implemented by the
kernel and the second is implemented as an indirect syscall.
* tests/mmsg.c (LENGTH_OF): New macro.
(send_mmsg, recv_mmsg): Print expected output in case of ENOSYS.
(main): Redirect stdout to a new descriptor. Use LENGTH_OF.
Print expected output.
* tests/mmsg.test: Update.
* tests/mmsg.expected: Remove.
* tests/Makefile.am (EXTRA_DIST): Remove mmsg.expected.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ab46af1..ff3175d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -326,7 +326,6 @@
ksysent.sed \
lstatx.c \
memfd_create.expected \
- mmsg.expected \
mq.expected \
net.expected \
net-fd.expected \
diff --git a/tests/mmsg.c b/tests/mmsg.c
index ba7fc3e..fa1ee8b 100644
--- a/tests/mmsg.c
+++ b/tests/mmsg.c
@@ -34,15 +34,20 @@
# include <assert.h>
# include <errno.h>
+# include <stdio.h>
# include <unistd.h>
# include <sys/socket.h>
-#ifndef HAVE_STRUCT_MMSGHDR
+# ifndef HAVE_STRUCT_MMSGHDR
struct mmsghdr {
struct msghdr msg_hdr;
unsigned msg_len;
};
-#endif
+# endif
+
+# define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
+
+static FILE *logfp;
static int
send_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
@@ -53,6 +58,9 @@
(unsigned long) flags);
if (rc >= 0 || ENOSYS != errno)
return rc;
+ fprintf(logfp,
+ "sendmmsg(%d, %p, %u, MSG_DONTROUTE|MSG_NOSIGNAL)"
+ " = -1 ENOSYS (%m)\n", fd, vec, vlen);
#endif
#ifdef HAVE_SENDMMSG
rc = sendmmsg(fd, vec, vlen, flags);
@@ -70,6 +78,9 @@
(unsigned long) flags, timeout);
if (rc >= 0 || ENOSYS != errno)
return rc;
+ fprintf(logfp,
+ "recvmmsg(%d, %p, %u, MSG_DONTWAIT, NULL)"
+ " = -1 ENOSYS (%m)\n", fd, vec, vlen);
#endif
#ifdef HAVE_RECVMMSG
rc = recvmmsg(fd, vec, vlen, flags, timeout);
@@ -83,6 +94,10 @@
const int R = 0, W = 1;
int sv[2];
+ int logfd = dup(1);
+ assert(logfd > 2);
+ assert((logfp = fdopen(logfd, "w")));
+
(void) close(0);
(void) close(1);
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv))
@@ -93,20 +108,24 @@
static const char one[] = "one";
static const char two[] = "two";
static const char three[] = "three";
- void *copy_one = tail_memdup(one, sizeof(one) - 1);
- void *copy_two = tail_memdup(two, sizeof(two) - 1);
- void *copy_three = tail_memdup(three, sizeof(three) - 1);
+ static const char ascii_one[] = "6f 6e 65";
+ static const char ascii_two[] = "74 77 6f";
+ static const char ascii_three[] = "74 68 72 65 65";
+
+ void *copy_one = tail_memdup(one, LENGTH_OF(one));
+ void *copy_two = tail_memdup(two, LENGTH_OF(two));
+ void *copy_three = tail_memdup(three, LENGTH_OF(three));
struct iovec iov[] = {
{
.iov_base = copy_one,
- .iov_len = sizeof(one) - 1
+ .iov_len = LENGTH_OF(one)
}, {
.iov_base = copy_two,
- .iov_len = sizeof(two) - 1
+ .iov_len = LENGTH_OF(two)
}, {
.iov_base = copy_three,
- .iov_len = sizeof(three) - 1
+ .iov_len = LENGTH_OF(three)
}
};
struct iovec *copy_iov = tail_memdup(iov, sizeof(iov));
@@ -125,17 +144,60 @@
}
};
void *copy_mmh = tail_memdup(mmh, sizeof(mmh));
-# define n_mmh (sizeof(mmh)/sizeof(mmh[0]))
+# define n_mmh ((unsigned int) (sizeof(mmh)/sizeof(mmh[0])))
int r = send_mmsg(W, copy_mmh, n_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
if (r < 0 && errno == ENOSYS)
perror_msg_and_skip("sendmmsg");
- assert((size_t)r == n_mmh);
+ assert(r == (int) n_mmh);
assert(close(W) == 0);
+ fprintf(logfp,
+ "sendmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
+ ", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
+ ", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
+ ", msg_controllen=0, msg_flags=0}, %u}}, %u"
+ ", MSG_DONTROUTE|MSG_NOSIGNAL) = %d\n"
+ " = %u buffers in vector 0\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n"
+ " * %u bytes in buffer 1\n"
+ " | 00000 %-48s %-16s |\n"
+ " = %u buffers in vector 1\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n",
+ W, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
+ LENGTH_OF(one) + LENGTH_OF(two),
+ 1, three, LENGTH_OF(three), LENGTH_OF(three),
+ n_mmh, r,
+ 2, LENGTH_OF(one), ascii_one, one,
+ LENGTH_OF(two), ascii_two, two,
+ 1, LENGTH_OF(three), ascii_three, three);
- assert(recv_mmsg(R, copy_mmh, n_mmh, MSG_DONTWAIT, NULL) == n_mmh);
+ assert(recv_mmsg(R, copy_mmh, n_mmh, MSG_DONTWAIT, NULL) == (int) n_mmh);
assert(close(R) == 0);
+ fprintf(logfp,
+ "recvmmsg(%d, {{{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}"
+ ", {\"%s\", %u}], msg_controllen=0, msg_flags=0}, %u}"
+ ", {{msg_name(0)=NULL, msg_iov(%u)=[{\"%s\", %u}]"
+ ", msg_controllen=0, msg_flags=0}, %u}}, %u"
+ ", MSG_DONTWAIT, NULL) = %d (left NULL)\n"
+ " = %u buffers in vector 0\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n"
+ " * %u bytes in buffer 1\n"
+ " | 00000 %-48s %-16s |\n"
+ " = %u buffers in vector 1\n"
+ " * %u bytes in buffer 0\n"
+ " | 00000 %-48s %-16s |\n",
+ R, 2, one, LENGTH_OF(one), two, LENGTH_OF(two),
+ LENGTH_OF(one) + LENGTH_OF(two),
+ 1, three, LENGTH_OF(three), LENGTH_OF(three),
+ n_mmh, r,
+ 2, LENGTH_OF(one), ascii_one, one,
+ LENGTH_OF(two), ascii_two, two,
+ 1, LENGTH_OF(three), ascii_three, three);
+ fprintf(logfp, "+++ exited with 0 +++\n");
return 0;
}
diff --git a/tests/mmsg.expected b/tests/mmsg.expected
deleted file mode 100644
index 708e029..0000000
--- a/tests/mmsg.expected
+++ /dev/null
@@ -1,19 +0,0 @@
-sendmmsg(1, {{{msg_name(0)=NULL, msg_iov(2)=[{"one", 3}, {"two", 3}], msg_controllen=0, msg_flags=0}, 6}, {{msg_name(0)=NULL, msg_iov(1)=[{"three", 5}], msg_controllen=0, msg_flags=0}, 5}}, 2, MSG_DONTROUTE|MSG_NOSIGNAL) = 2
- = 2 buffers in vector 0
- * 3 bytes in buffer 0
- | 00000 6f 6e 65 one |
- * 3 bytes in buffer 1
- | 00000 74 77 6f two |
- = 1 buffers in vector 1
- * 5 bytes in buffer 0
- | 00000 74 68 72 65 65 three |
-recvmmsg(0, {{{msg_name(0)=NULL, msg_iov(2)=[{"one", 3}, {"two", 3}], msg_controllen=0, msg_flags=0}, 6}, {{msg_name(0)=NULL, msg_iov(1)=[{"three", 5}], msg_controllen=0, msg_flags=0}, 5}}, 2, MSG_DONTWAIT, NULL) = 2 (left NULL)
- = 2 buffers in vector 0
- * 3 bytes in buffer 0
- | 00000 6f 6e 65 one |
- * 3 bytes in buffer 1
- | 00000 74 77 6f two |
- = 1 buffers in vector 1
- * 5 bytes in buffer 0
- | 00000 74 68 72 65 65 three |
-+++ exited with 0 +++
diff --git a/tests/mmsg.test b/tests/mmsg.test
index 0237df8..073340f 100755
--- a/tests/mmsg.test
+++ b/tests/mmsg.test
@@ -4,8 +4,10 @@
. "${srcdir=.}/init.sh"
-run_prog
-run_strace -e trace=recvmmsg,sendmmsg -e read=0 -e write=1 $args
-match_diff
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -e trace=recvmmsg,sendmmsg -e read=0 -e write=1 $args > "$OUT"
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
exit 0