1 /**
2  * Copyright (C) Mellanox Technologies Ltd. 2001-2018.  ALL RIGHTS RESERVED.
3  *
4  * See file LICENSE for terms.
5  */
6 
7 #include <common/test.h>
8 extern "C" {
9 #include <ucp/dt/dt.h>
10 }
11 
12 class test_ucp_dt_iov : public ucs::test{
13 protected:
calc_iov_offset(const ucp_dt_iov_t * iov,size_t iov_indx,size_t iov_offs)14     size_t calc_iov_offset(const ucp_dt_iov_t *iov, size_t iov_indx, size_t iov_offs) {
15         size_t offset = iov_offs;;
16         for (size_t i = 0; i < iov_indx; ++i) {
17             offset += iov[i].length;
18         }
19         return offset;
20    }
21 };
22 
UCS_TEST_F(test_ucp_dt_iov,seek)23 UCS_TEST_F(test_ucp_dt_iov, seek)
24 {
25     for (int count = 0; count < 100; ++count) {
26         size_t iovcnt = (ucs::rand() % 20) + 1;
27         std::vector<ucp_dt_iov_t> iov(iovcnt);
28 
29         size_t total_size = 0;
30         for (size_t i = 0; i < iovcnt; ++i) {
31             iov[i].length = (ucs::rand() % 1000) + 1;
32             total_size   += iov[i].length;
33         }
34 
35         ASSERT_EQ(total_size, calc_iov_offset(&iov[0], iovcnt, 0));
36 
37         size_t offset = 0;
38         size_t iov_offs = 0, iov_indx = 0;
39         for (int j = 0; j < 100; ++j) {
40             size_t new_offset = ucs::rand() % total_size;
41             ucp_dt_iov_seek(&iov[0], iovcnt,
42                             (ptrdiff_t)new_offset - (ptrdiff_t)offset,
43                             &iov_offs, &iov_indx);
44             EXPECT_EQ(new_offset, calc_iov_offset(&iov[0], iov_indx, iov_offs));
45             offset = new_offset;
46         }
47     }
48 }
49