From f73a3a44dd62a331c88a63d4b0756274ea3084aa Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 19 Apr 2016 21:10:44 +0000 Subject: [PATCH] tests: adjust readv/writev and preadv/pwritev tests to older kernels 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 . (main): Print either "EINVAL" or "EFAULT" depending on errno. * tests/pwritev.c: Likewise. * tests/readv.c: Likewise. --- tests/preadv-pwritev.c | 12 ++++++++---- tests/pwritev.c | 6 ++++-- tests/readv.c | 12 ++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/preadv-pwritev.c b/tests/preadv-pwritev.c index f86d0710..8ceae350 100644 --- a/tests/preadv-pwritev.c +++ b/tests/preadv-pwritev.c @@ -31,6 +31,7 @@ #if defined HAVE_PREADV && defined HAVE_PWRITEV +# include # include # include # include @@ -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); diff --git a/tests/pwritev.c b/tests/pwritev.c index 99b30183..0c8afcbd 100644 --- a/tests/pwritev.c +++ b/tests/pwritev.c @@ -29,6 +29,7 @@ #ifdef HAVE_PWRITEV +# include # include # include # include @@ -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; diff --git a/tests/readv.c b/tests/readv.c index b0603c20..a8af8729 100644 --- a/tests/readv.c +++ b/tests/readv.c @@ -30,6 +30,7 @@ #include "tests.h" #include +#include #include #include #include @@ -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); -- 2.40.0