Signed-off-by: Pavel Begunkov --- test/helpers.c | 10 ++++++++++ test/helpers.h | 2 ++ test/vec-regbuf.c | 6 ++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/helpers.c b/test/helpers.c index 18af2be8..15ceb17a 100644 --- a/test/helpers.c +++ b/test/helpers.c @@ -526,3 +526,13 @@ int t_submit_and_wait_single(struct io_uring *ring, struct io_uring_cqe **cqe) } return 0; } + +size_t t_iovec_data_length(struct iovec *iov, unsigned iov_len) +{ + size_t sz = 0; + int i; + + for (i = 0; i < iov_len; i++) + sz += iov[i].iov_len; + return sz; +} diff --git a/test/helpers.h b/test/helpers.h index b7465890..a45b8683 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -124,6 +124,8 @@ unsigned long long utime_since_now(struct timeval *tv); int t_submit_and_wait_single(struct io_uring *ring, struct io_uring_cqe **cqe); +size_t t_iovec_data_length(struct iovec *iov, unsigned iov_len); + #ifdef __cplusplus } #endif diff --git a/test/vec-regbuf.c b/test/vec-regbuf.c index 286b78c6..0cbe2c74 100644 --- a/test/vec-regbuf.c +++ b/test/vec-regbuf.c @@ -269,7 +269,7 @@ static int test_vec(struct buf_desc *bd, struct iovec *vecs, int nr_vec, struct sockaddr_storage addr; int sock_server, sock_client; struct verify_data vd; - size_t total_len = 0; + size_t total_len; int i, ret; void *verify_res; pthread_t th; @@ -284,9 +284,7 @@ static int test_vec(struct buf_desc *bd, struct iovec *vecs, int nr_vec, for (i = 0; i < bd->size; i++) bd->buf_wr[i] = i; memset(bd->buf_rd, 0, bd->size); - - for (i = 0; i < nr_vec; i++) - total_len += vecs[i].iov_len; + total_len = t_iovec_data_length(vecs, nr_vec); vd.bd = bd; vd.vecs = vecs; -- 2.49.0