tests: add a test for pread/pwrite and preadv/pwritev offset decoding

* tests/uio.c: New file.
* tests/uio.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add uio.
(uio_CFLAGS): Define.
(TESTS): Add uio.test.
This commit is contained in:
2014-04-16 23:28:29 +00:00
parent 99a0544f01
commit cc3d59199d
3 changed files with 63 additions and 1 deletions

View File

@ -2,7 +2,9 @@
AM_CFLAGS = $(WARN_CFLAGS)
check_PROGRAMS = net-accept-connect set_ptracer_any sigaction
check_PROGRAMS = net-accept-connect set_ptracer_any sigaction uio
uio_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
TESTS = \
ptrace_setoptions.test \
@ -12,6 +14,7 @@ TESTS = \
stat.test \
net.test \
net-fd.test \
uio.test \
detach-sleeping.test \
detach-stopped.test \
detach-running.test

25
tests/uio.c Normal file
View File

@ -0,0 +1,25 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#include <assert.h>
int
main(void)
{
const off_t offset = 0xdefaceddeadbeefLL;
int fd;
char buf[4];
struct iovec iov = { buf, sizeof buf };
assert((fd = open("/dev/zero", O_RDONLY)) >= 0);
assert(pread(fd, buf, sizeof buf, offset) == 4);
assert(preadv(fd, &iov, 1, offset) == 4);
assert(!close(fd));
assert((fd = open("/dev/null", O_WRONLY)) >= 0);
assert(pwrite(fd, buf, sizeof buf, offset) == 4);
assert(pwritev(fd, &iov, 1, offset) == 4);
assert(!close(fd));
return 0;
}

34
tests/uio.test Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
# Check how pread/pwrite and preadv/pwritev syscalls are traced.
. "${srcdir=.}/init.sh"
check_prog grep
check_prog rm
./uio ||
fail_ 'uio failed'
args="-edesc ./uio"
$STRACE $args > $LOG 2>&1 || {
cat $LOG
fail_ "$STRACE $args failed"
}
grep_log()
{
local syscall="$1"; shift
LC_ALL=C grep -E -x "$syscall$*" $LOG > /dev/null || {
cat $LOG
fail_ "$STRACE $args failed to trace \"$syscall\" properly"
}
}
grep_log 'pread(64)?' '\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4'
grep_log 'preadv' '\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4'
grep_log 'pwrite(64)?' '\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4'
grep_log 'pwritev' '\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4'
exit 0