]> granicus.if.org Git - strace/commitdiff
tests: adjust readv/writev and preadv/pwritev tests to older kernels
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 19 Apr 2016 21:10:44 +0000 (21:10 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 20 Apr 2016 01:08:13 +0000 (01:08 +0000)
With linux kernels older than v3.16-rc1, iovec based compat syscalls may
return EINVAL in some cases where on later kernels they return EFAULT.
Adjust tests to handle both cases properly.

* tests/preadv-pwritev.c: Include <errno.h>.
(main): Print either "EINVAL" or "EFAULT" depending on errno.
* tests/pwritev.c: Likewise.
* tests/readv.c: Likewise.

tests/preadv-pwritev.c
tests/pwritev.c
tests/readv.c

index f86d07103c50c93f85836a6d1aeded2fa15c960e..8ceae3500ecdb72496c07b2f6111e8200b21a746 100644 (file)
@@ -31,6 +31,7 @@
 
 #if defined HAVE_PREADV && defined HAVE_PWRITEV
 
+# include <errno.h>
 # include <fcntl.h>
 # include <stdio.h>
 # include <sys/uio.h>
@@ -68,12 +69,14 @@ main(void)
        rc = pwritev(1, efault, 42, 0);
        if (rc != -1)
                perror_msg_and_fail("pwritev: expected -1, returned %ld", rc);
-       tprintf("pwritev(1, %p, 42, 0) = -1 EFAULT (%m)\n", efault);
+       tprintf("pwritev(1, %p, 42, 0) = -1 %s (%m)\n",
+               efault, errno == EINVAL ? "EINVAL" : "EFAULT");
 
        rc = preadv(0, efault, 42, 0);
        if (rc != -1)
                perror_msg_and_fail("preadv: expected -1, returned %ld", rc);
-       tprintf("preadv(0, %p, 42, 0) = -1 EFAULT (%m)\n", efault);
+       tprintf("preadv(0, %p, 42, 0) = -1 %s (%m)\n",
+               efault, errno == EINVAL ? "EINVAL" : "EFAULT");
 
        static const char r0_c[] = "01234567";
        const char *r0_d = hexdump_strdup(r0_c);
@@ -103,8 +106,9 @@ main(void)
        if (rc != -1)
                perror_msg_and_fail("pwritev: expected -1 EFAULT, returned %ld",
                                    rc);
-       tprintf("pwritev(1, [{\"%s\", %u}, %p], 2, 0) = -1 EFAULT (%m)\n",
-               w2_c, LENGTH_OF(w2_c), w_iov + ARRAY_SIZE(w_iov_));
+       tprintf("pwritev(1, [{\"%s\", %u}, %p], 2, 0) = -1 %s (%m)\n",
+               w2_c, LENGTH_OF(w2_c), w_iov + ARRAY_SIZE(w_iov_),
+               errno == EINVAL ? "EINVAL" : "EFAULT");
 
        const unsigned int w_len =
                LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
index 99b3018317e8a63e8d6a39819a23108acd5815be..0c8afcbda35b25cf219d39b489980f111521f650 100644 (file)
@@ -29,6 +29,7 @@
 
 #ifdef HAVE_PWRITEV
 
+# include <errno.h>
 # include <fcntl.h>
 # include <stdio.h>
 # include <sys/uio.h>
@@ -115,8 +116,9 @@ main(void)
                        perror_msg_and_fail("pwritev");
                fputs("pwritev(0, ", stdout);
                print_iovec(iov + i, n, LEN - i);
-               printf(", %u, %lld) = -1 EFAULT (%m)\n",
-                      n, (long long) offset + LEN + i);
+               printf(", %u, %lld) = -1 %s (%m)\n",
+                      n, (long long) offset + LEN + i,
+                      errno == EINVAL ? "EINVAL" : "EFAULT");
        }
 
        iov->iov_base = iov + LEN * 2;
index b0603c20063da8040d1bdef5d852e92073d2bab6..a8af872998302949da8ef5fe0e69ac1a9441a1ee 100644 (file)
@@ -30,6 +30,7 @@
 #include "tests.h"
 
 #include <assert.h>
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/uio.h>
@@ -60,10 +61,12 @@ main(void)
        void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c));
 
        assert(writev(1, efault, 42) == -1);
-       tprintf("writev(1, %p, 42) = -1 EFAULT (%m)\n", efault);
+       tprintf("writev(1, %p, 42) = -1 %s (%m)\n",
+               efault, errno == EINVAL ? "EINVAL" : "EFAULT");
 
        assert(readv(0, efault, 42) == -1);
-       tprintf("readv(0, %p, 42) = -1 EFAULT (%m)\n", efault);
+       tprintf("readv(0, %p, 42) = -1 %s (%m)\n",
+               efault, errno == EINVAL ? "EINVAL" : "EFAULT");
 
        static const char r0_c[] = "01234567";
        const char *r0_d = hexdump_strdup(r0_c);
@@ -88,8 +91,9 @@ main(void)
        tprintf("writev(1, [], 0) = 0\n");
 
        assert(writev(1, w_iov + ARRAY_SIZE(w_iov_) - 1, 2) == -1);
-       tprintf("writev(1, [{\"%s\", %u}, %p], 2) = -1 EFAULT (%m)\n",
-               w2_c, LENGTH_OF(w2_c), w_iov + ARRAY_SIZE(w_iov_));
+       tprintf("writev(1, [{\"%s\", %u}, %p], 2) = -1 %s (%m)\n",
+               w2_c, LENGTH_OF(w2_c), w_iov + ARRAY_SIZE(w_iov_),
+               errno == EINVAL ? "EINVAL" : "EFAULT");
 
        const unsigned int w_len =
                LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);