tests: add a test for pread/pwrite and preadv/pwritev offset decoding
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 16 Apr 2014 23:28:29 +0000 (23:28 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 16 Apr 2014 23:49:33 +0000 (23:49 +0000)
* tests/uio.c: New file.
* tests/uio.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add uio.
(uio_CFLAGS): Define.
(TESTS): Add uio.test.

tests/Makefile.am
tests/uio.c [new file with mode: 0644]
tests/uio.test [new file with mode: 0755]

index 82226df32f0186e1ccac30e6e974c1b1d897f6d4..c63c41f6b7dea8563955875a9dac976ee89e1d12 100644 (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
diff --git a/tests/uio.c b/tests/uio.c
new file mode 100644 (file)
index 0000000..ca731e0
--- /dev/null
@@ -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;
+}
diff --git a/tests/uio.test b/tests/uio.test
new file mode 100755 (executable)
index 0000000..25f82cb
--- /dev/null
@@ -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