]> granicus.if.org Git - strace/commitdiff
tests: add recv_mmsg and send_mmsg functions to libtests
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 19 Jul 2016 15:09:05 +0000 (15:09 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 19 Jul 2016 17:45:02 +0000 (17:45 +0000)
* tests/tests.h (recv_mmsg, send_mmsg): New prototype.
* tests/libmmsg.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/mmsg.c Do not check for __NR_sendmmsg, __NR_recvmmsg,
HAVE_SENDMMSG, and HAVE_RECVMMSG.  Do not include unused headers.
(recv_mmsg, send_mmsg): Remove.

tests/Makefile.am
tests/libmmsg.c [new file with mode: 0644]
tests/mmsg.c
tests/tests.h

index c537a9eaf4c5ad0be345d11143cd47f80245d32e..3c873625aee0c773fe8014e10d5469489c77178e 100644 (file)
@@ -47,6 +47,7 @@ libtests_a_SOURCES = \
        hexdump_strdup.c \
        hexquote_strndup.c \
        inode_of_sockfd.c \
+       libmmsg.c \
        libsocketcall.c \
        overflowuid.c \
        print_quoted_string.c \
diff --git a/tests/libmmsg.c b/tests/libmmsg.c
new file mode 100644 (file)
index 0000000..07feb7c
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Wrappers for recvmmsg and sendmmsg syscalls.
+ *
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <errno.h>
+#include <sys/syscall.h>
+
+#ifndef __NR_recvmmsg
+# define __NR_recvmmsg -1
+#endif
+#define SC_recvmmsg 19
+
+#ifndef __NR_sendmmsg
+# define __NR_sendmmsg -1
+#endif
+#define SC_sendmmsg 20
+
+int
+recv_mmsg(const int fd, struct mmsghdr *const vec,
+         const unsigned int vlen, const unsigned int flags,
+         struct timespec *const timeout)
+{
+       int rc = socketcall(__NR_recvmmsg, SC_recvmmsg,
+                           fd, (long) vec, vlen, flags, (long) timeout);
+
+       if (rc < 0 && ENOSYS == errno)
+               perror_msg_and_skip("recvmmsg");
+
+       return rc;
+}
+
+int
+send_mmsg(const int fd, struct mmsghdr *const vec,
+         const unsigned int vlen, const unsigned int flags)
+{
+       int rc = socketcall(__NR_sendmmsg, SC_sendmmsg,
+                           fd, (long) vec, vlen, flags, 0);
+
+       if (rc < 0 && ENOSYS == errno)
+               perror_msg_and_skip("sendmmsg");
+
+       return rc;
+}
index 0c7fed537b119da9e7bd7862148bf56358f0fb18..44b62144bc72e31c2060b87a4b36f382c0115f36 100644 (file)
  */
 
 #include "tests.h"
-# include <sys/syscall.h>
+#include <assert.h>
+#include <unistd.h>
 
-#if (defined __NR_sendmmsg || defined HAVE_SENDMMSG) \
- && (defined __NR_recvmmsg || defined HAVE_RECVMMSG)
-
-# include <assert.h>
-# include <errno.h>
-# include <stdio.h>
-# include <unistd.h>
-
-# include "msghdr.h"
-
-static int
-send_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
-{
-       int rc;
-#ifdef __NR_sendmmsg
-       rc = syscall(__NR_sendmmsg, (long) fd, vec, (unsigned long) vlen,
-                    (unsigned long) flags);
-       if (rc >= 0 || ENOSYS != errno)
-               return rc;
-       tprintf("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);
-#endif
-       return rc;
-}
-
-static int
-recv_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags,
-         struct timespec *timeout)
-{
-       int rc;
-#ifdef __NR_recvmmsg
-       rc = syscall(__NR_recvmmsg, (long) fd, vec, (unsigned long) vlen,
-                    (unsigned long) flags, timeout);
-       if (rc >= 0 || ENOSYS != errno)
-               return rc;
-       tprintf("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);
-#endif
-       return rc;
-}
+#include "msghdr.h"
 
 int
 main(void)
@@ -135,7 +91,7 @@ main(void)
        const unsigned int n_w_mmh = ARRAY_SIZE(w_mmh_);
 
        int r = send_mmsg(1, w_mmh, n_w_mmh, MSG_DONTROUTE | MSG_NOSIGNAL);
-       if (r < 0 && errno == ENOSYS)
+       if (r < 0)
                perror_msg_and_skip("sendmmsg");
        assert(r == (int) n_w_mmh);
        assert(close(1) == 0);
@@ -237,9 +193,3 @@ main(void)
        tprintf("+++ exited with 0 +++\n");
        return 0;
 }
-
-#else
-
-SKIP_MAIN_UNDEFINED("(__NR_sendmmsg || HAVE_SENDMMSG) && (__NR_recvmmsg || HAVE_RECVMMSG)")
-
-#endif
index c61d0051229551a1d16733a97ad1b798e20437ec..e0bf2288ff7ad3b1816d9f94f65409ecd142251d 100644 (file)
@@ -111,6 +111,12 @@ int printxval(const struct xlat *, const unsigned long long, const char *);
 int socketcall(const int nr, const int call,
               long a1, long a2, long a3, long a4, long a5);
 
+/* Wrappers for recvmmsg and sendmmsg syscalls. */
+struct mmsghdr;
+struct timespec;
+int recv_mmsg(int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
+int send_mmsg(int, struct mmsghdr *, unsigned int, unsigned int);
+
 # define ARRAY_SIZE(arg) ((unsigned int) (sizeof(arg) / sizeof((arg)[0])))
 # define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)