From 495f525d6866926332ef423d88f145b019ef44ab Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 1 Feb 2015 00:20:32 +0000 Subject: [PATCH] tests: add a test for the latest dumpio fix * 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 | 1 + tests/Makefile.am | 5 +++- tests/dumpio.expected | 7 +++++ tests/dumpio.test | 26 +++++++++++++++++ tests/unix-pair-send-recv.c | 57 +++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tests/dumpio.expected create mode 100755 tests/dumpio.test create mode 100644 tests/unix-pair-send-recv.c diff --git a/tests/.gitignore b/tests/.gitignore index 1510bc99..c96ee1fe 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -20,6 +20,7 @@ uid uid16 uid32 uio +unix-pair-send-recv *.log *.log.* *.o diff --git a/tests/Makefile.am b/tests/Makefile.am index b2b59457..901df501 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..f8fd2449 --- /dev/null +++ b/tests/dumpio.expected @@ -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 index 00000000..ef3792d2 --- /dev/null +++ b/tests/dumpio.test @@ -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 index 00000000..535f8e7e --- /dev/null +++ b/tests/unix-pair-send-recv.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + +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; +}