]> granicus.if.org Git - strace/commitdiff
tests: add a test for the latest dumpio fix
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 1 Feb 2015 00:20:32 +0000 (00:20 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 1 Feb 2015 01:33:20 +0000 (01:33 +0000)
* tests/dumpio.expected: New file.
* tests/unix-pair-send-recv.c: New file.
* tests/dumpio.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add unix-pair-send-recv.
(TESTS): Add dumpio.test.
(EXTRA_DIST): Add dumpio.expected.
* tests/.gitignore: Add unix-pair-send-recv.

tests/.gitignore
tests/Makefile.am
tests/dumpio.expected [new file with mode: 0644]
tests/dumpio.test [new file with mode: 0755]
tests/unix-pair-send-recv.c [new file with mode: 0644]

index 1510bc99fbbb28686a46c46fdec9926aa98a57b2..c96ee1fee774a6db27526998d464ae3fb0bcfc73 100644 (file)
@@ -20,6 +20,7 @@ uid
 uid16
 uid32
 uio
+unix-pair-send-recv
 *.log
 *.log.*
 *.o
index b2b5945711713951a8b56ccd64b3ec5408d7341b..901df50140766976b41b7cd723bbec1c9418fdf0 100644 (file)
@@ -24,7 +24,8 @@ check_PROGRAMS = \
        uid \
        uid16 \
        uid32 \
-       uio
+       uio \
+       unix-pair-send-recv
 
 stat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 statfs_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
@@ -37,6 +38,7 @@ TESTS = \
        strace-f.test \
        qual_syscall.test \
        caps.test \
+       dumpio.test \
        fanotify_mark.test \
        getdents.test \
        ioctl.test \
@@ -71,6 +73,7 @@ TEST_LOG_COMPILER = $(srcdir)/run.sh
 
 EXTRA_DIST = init.sh run.sh \
             caps.awk \
+            dumpio.expected \
             getdents.awk \
             mmsg.expected \
             net-yy-accept.awk \
diff --git a/tests/dumpio.expected b/tests/dumpio.expected
new file mode 100644 (file)
index 0000000..f8fd244
--- /dev/null
@@ -0,0 +1,7 @@
+sendto(0, "zyxwvutsrqponmlkjihgfedcba", 26, MSG_DONTROUTE, NULL, 0) = 26
+ | 00000  7a 79 78 77 76 75 74 73  72 71 70 6f 6e 6d 6c 6b  zyxwvutsrqponmlk |
+ | 00010  6a 69 68 67 66 65 64 63  62 61                    jihgfedcba       |
+recvfrom(0, "abcdefghijklmnopqrstuvwxyz", 26, MSG_WAITALL, NULL, NULL) = 26
+ | 00000  61 62 63 64 65 66 67 68  69 6a 6b 6c 6d 6e 6f 70  abcdefghijklmnop |
+ | 00010  71 72 73 74 75 76 77 78  79 7a                    qrstuvwxyz       |
++++ exited with 0 +++
diff --git a/tests/dumpio.test b/tests/dumpio.test
new file mode 100755 (executable)
index 0000000..ef3792d
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Check how dumpio works.
+
+. "${srcdir=.}/init.sh"
+
+dumpio_expected="${srcdir=.}/dumpio.expected"
+cat "$dumpio_expected" > /dev/null ||
+       fail_ "$dumpio_expected is not available"
+
+check_prog diff
+
+args='./unix-pair-send-recv abcdefghijklmnopqrstuvwxyz'
+$args ||
+       fail_ "$args failed"
+
+args="-esignal=none -esendto,recvfrom -eread=0 -ewrite=0 $args"
+$STRACE -o "$LOG" $args || {
+       cat "$LOG"
+       fail_ "$STRACE $args failed"
+}
+
+diff "$dumpio_expected" "$LOG" ||
+       fail_ "$STRACE $args failed to dump i/o properly"
+
+exit 0
diff --git a/tests/unix-pair-send-recv.c b/tests/unix-pair-send-recv.c
new file mode 100644 (file)
index 0000000..535f8e7
--- /dev/null
@@ -0,0 +1,57 @@
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+static void
+transpose(char *str, int len)
+{
+       int i;
+
+       for (i = 0; i < len / 2; ++i) {
+               char c = str[i];
+               str[i] = str[len - 1 - i];
+               str[len - 1 - i] = c;
+       }
+}
+
+int
+main(int ac, char **av)
+{
+       assert(ac == 2);
+       const int len = strlen(av[1]);
+       assert(len);
+
+       (void) close(0);
+       (void) close(1);
+
+       int sv[2];
+       assert(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
+       assert(sv[0] == 0);
+       assert(sv[1] == 1);
+
+       pid_t pid = fork();
+       assert(pid >= 0);
+
+       if (pid) {
+               assert(close(1) == 0);
+               transpose(av[1], len);
+               assert(sendto(0, av[1], len, MSG_DONTROUTE, NULL, 0) == len);
+               assert(recvfrom(0, av[1], len, MSG_WAITALL, NULL, NULL) == len);
+               assert(close(0) == 0);
+
+                int status;
+               assert(waitpid(pid, &status, 0) == pid);
+               assert(status == 0);
+       } else {
+               assert(close(0) == 0);
+               assert(recvfrom(1, av[1], len, MSG_WAITALL, NULL, NULL) == len);
+               transpose(av[1], len);
+               assert(sendto(1, av[1], len, MSG_DONTROUTE, NULL, 0) == len);
+               assert(recvfrom(1, av[1], len, MSG_WAITALL, NULL, NULL) == 0);
+               assert(close(1) == 0);
+       }
+
+       return 0;
+}