[PATCH 4/4] Add a test case for "-e write=all" option for sendmmsg system call

Masatake YAMATO yamato at redhat.com
Thu Nov 6 16:23:27 UTC 2014


* tests/Makefile.am: Add mmsg to CHECK_PROGRAMS. Add mmsg.test to TESTS.

* tests/mmsg.test: New file.

* tests/mmsg.c: New target program to be traced by testes strace.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 tests/Makefile.am |  2 ++
 tests/mmsg.c      | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/mmsg.test   | 44 +++++++++++++++++++++++++++
 3 files changed, 137 insertions(+)
 create mode 100644 tests/mmsg.c
 create mode 100755 tests/mmsg.test

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 541a0c4..0d92776 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
 
 check_PROGRAMS = \
 	inet-accept-connect-send-recv \
+	mmsg \
 	net-accept-connect \
 	netlink_inet_diag \
 	scm_rights \
@@ -27,6 +28,7 @@ TESTS = \
 	sigaction.test \
 	stat.test \
 	statfs.test \
+	mmsg.test \
 	net.test \
 	net-fd.test \
 	net-yy.test \
diff --git a/tests/mmsg.c b/tests/mmsg.c
new file mode 100644
index 0000000..732fa67
--- /dev/null
+++ b/tests/mmsg.c
@@ -0,0 +1,91 @@
+/* Derived from man page of sendmmsg(2) and recvmmsg(2) */
+#define _GNU_SOURCE
+#include <sys/socket.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static char xbuf[4096];
+
+int
+main(void)
+{
+  int sv[2];
+  pid_t pid;
+
+
+  if (socketpair (AF_UNIX, SOCK_DGRAM, 0, sv) < 0)
+    {
+      perror("socketpair");
+      exit (1);
+    }
+
+
+  pid = fork ();
+  if (pid < 0)
+    {
+      perror("fork");
+      exit (1);
+    }
+  else if (pid == 0)
+    {
+      struct mmsghdr msg[2];
+      struct iovec msg1[2], msg2;
+      char one[4] = "one", two[4] = "two", three[6] = "three";
+      memset(msg1, 0, sizeof(msg1));
+      msg1[0].iov_base = one;
+      msg1[0].iov_len = 3;
+      msg1[1].iov_base = xbuf;
+      msg1[1].iov_len = 4096;
+      msg1[1].iov_base = two;
+      msg1[1].iov_len = 3;
+
+      memset(&msg2, 0, sizeof(msg2));
+      msg2.iov_base = three;
+      msg2.iov_len = 5;
+
+      memset(msg, 0, sizeof(msg));
+      msg[0].msg_hdr.msg_iov = msg1;
+      msg[0].msg_hdr.msg_iovlen = 2;
+      msg[1].msg_hdr.msg_iov = &msg2;
+      msg[1].msg_hdr.msg_iovlen = 1;
+
+      if (sendmmsg (sv[0], msg, 2, 0) < 0)
+        {
+          perror("sendmsg");
+          exit (1);
+        }
+    }
+  else
+    {
+      struct mmsghdr msg[2];
+      struct iovec msg1[2], msg2;
+      char one[4], two[4], three[6];
+
+      memset(msg1, 0, sizeof(msg1));
+      msg1[0].iov_base = one;
+      msg1[0].iov_len = 3;
+      msg1[1].iov_base = two;
+      msg1[1].iov_len = 3;
+
+      memset(&msg2, 0, sizeof(msg2));
+      msg2.iov_base = three;
+      msg2.iov_len = 5;
+
+      memset(msg, 0, sizeof(msg));
+      msg[0].msg_hdr.msg_iov = msg1;
+      msg[0].msg_hdr.msg_iovlen = 2;
+      msg[1].msg_hdr.msg_iov = &msg2;
+      msg[1].msg_hdr.msg_iovlen = 1;
+
+      if (recvmmsg(sv[1], msg, 2, 0, NULL) < 0)
+        {
+          perror ("recvmmsg");
+          exit (1);
+        }
+    }
+  return 0;
+}
diff --git a/tests/mmsg.test b/tests/mmsg.test
new file mode 100755
index 0000000..20252f9
--- /dev/null
+++ b/tests/mmsg.test
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# Ensure that strace -k works.
+
+. "${srcdir=.}/init.sh"
+
+args="-e write=all -f ./mmsg"
+$STRACE $args > $LOG 2>&1 || {
+	cat $LOG
+	fail_ "$STRACE $args failed"
+}
+
+expected1=' | 00000  6f 6e 65                                          one              |'
+result1=$(grep '^ |' $LOG | grep one)
+
+expected2=' | 00000  74 77 6f                                          two              |'
+result2=$(grep '^ |' $LOG | grep two)
+
+expected3=' | 00000  74 68 72 65 65                                    three            |'
+result3=$(grep '^ |' $LOG | grep three)
+
+
+test "$result1" = "$expected1" || {
+	cat $LOG
+	echo "expected: \"$expected1\""
+	echo "result: \"$result1\""
+	fail_ "unexpected output from $STRACE $args"
+}
+
+test "$result2" = "$expected2" || {
+	cat $LOG
+	echo "expected: \"$expected2\""
+	echo "result: \"$result2\""
+	fail_ "unexpected output from $STRACE $args"
+}
+
+test "$result3" = "$expected3" || {
+	cat $LOG
+	echo "expected: \"$expected3\""
+	echo "result: \"$result3\""
+	fail_ "unexpected output from $STRACE $args"
+}
+
+exit 0
-- 
1.9.3





More information about the Strace-devel mailing list