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.
This commit is contained in:
Дмитрий Левин 2015-02-01 00:20:32 +00:00
parent dc52121cd0
commit 495f525d68
5 changed files with 95 additions and 1 deletions

1
tests/.gitignore vendored
View File

@ -20,6 +20,7 @@ uid
uid16
uid32
uio
unix-pair-send-recv
*.log
*.log.*
*.o

View 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 \

7
tests/dumpio.expected Normal file
View File

@ -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 +++

26
tests/dumpio.test Executable file
View File

@ -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

View File

@ -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;
}