File: test_iov.cc

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (167 lines) | stat: -rw-r--r-- 5,154 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2020. ALL RIGHTS RESERVED.
 *
 * See file LICENSE for terms.
 */

#include <common/test.h>

extern "C" {
#include <ucs/sys/iovec.h>
#include <ucs/sys/iovec.inl>
}


class test_ucs_iov : public ucs::test {
protected:
    struct iov1_t {
        char      length_padding[128];
        size_t    length;
        char      buffer_padding[64];
        void      *buffer;
    };

    struct iov2_t {
        char      length_padding[64];
        size_t    length;
        char      buffer_padding[256];
        void      *buffer;
    };

    template <typename T>
    void iov_set_length(T *iov, size_t length) {
        iov->length = length;
    }

    template <typename T>
    void iov_set_buffer(T *iov, void *buffer) {
        iov->buffer = buffer;
    }

    template <typename T>
    size_t iov_get_length(T *iov) {
        return iov->length;
    }

    template <typename T>
    void *iov_get_buffer(T *iov) {
        return iov->buffer;
    }

    template <typename T1, typename T2>
    size_t iov_converter(T1 *src_iov, size_t *src_iov_cnt_p,
                         T2 *dst_iov, size_t dst_iov_cnt,
                         size_t max_length, ucs_iov_iter_t *iov_iter_p) {
        return ucs_iov_converter(src_iov, src_iov_cnt_p,
                                 iov_set_buffer, iov_set_length,
                                 dst_iov, dst_iov_cnt,
                                 iov_get_buffer, iov_get_length,
                                 max_length, iov_iter_p);
    }

    void expect_zero_changes(size_t res_cnt, size_t res_length,
                             const ucs_iov_iter_t *iov_iter) {
        EXPECT_EQ(0lu, res_cnt);
        EXPECT_EQ(0lu, res_length);
        EXPECT_EQ(0lu, iov_iter->iov_index);
        EXPECT_EQ(0lu, iov_iter->buffer_offset);
    }

    template<typename T1, typename T2>
    void test_iov_type_pair(T1 *iov1, size_t iov1_cnt,
                            T2 *iov2, size_t iov2_cnt,
                            size_t max_length) {
        size_t res_total_length = 0;
        size_t exp_total_length = 0;
        size_t cnt, length;
        ucs_iov_iter_t iov_iter;

        iov1 = new T1[iov1_cnt];
        ASSERT_TRUE(iov1 != NULL);
        iov2  = new T2[iov2_cnt];
        ASSERT_TRUE(iov2 != NULL);

        for (size_t i = 0; i < iov2_cnt; i++) {
            iov_set_buffer(&iov2[i], (void*)0x1);
            iov_set_length(&iov2[i], i);
            exp_total_length += iov_get_length(&iov2[i]);
        }

        ucs_iov_iter_init(&iov_iter);

        while (iov_iter.iov_index < iov2_cnt) {
            cnt    = iov1_cnt;
            length = iov_converter(iov1, &cnt,
                                   iov2, iov2_cnt,
                                   max_length, &iov_iter);
            EXPECT_TRUE((iov_iter.iov_index == iov2_cnt) ||
                        (length == max_length) || (cnt == iov1_cnt));
            res_total_length += length;
        }

        EXPECT_EQ(exp_total_length, res_total_length);

        ucs_iov_iter_init(&iov_iter);
        cnt    = 0;
        length = iov_converter((T1*)NULL, &cnt,
                               iov2, iov2_cnt,
                               max_length, &iov_iter);
        expect_zero_changes(cnt, length, &iov_iter);

        ucs_iov_iter_init(&iov_iter);
        cnt    = iov1_cnt;
        length = iov_converter(iov1, &cnt,
                               (T2*)NULL, 0,
                               max_length, &iov_iter);
        expect_zero_changes(cnt, length, &iov_iter);

        ucs_iov_iter_init(&iov_iter);
        cnt    = iov1_cnt;
        length = iov_converter(iov1, &cnt,
                               iov2, iov2_cnt,
                               0, &iov_iter);
        expect_zero_changes(cnt, length, &iov_iter);

        delete[] iov1;
        delete[] iov2;
    }
};

UCS_TEST_F(test_ucs_iov, total_length) {
    const size_t iov_cnt = 1024;
    size_t total_length  = 0;
    struct iovec *iov;

    iov = new struct iovec[iov_cnt];
    ASSERT_TRUE(iov != NULL);

    for (size_t i = 0; i < iov_cnt; i++) {
        iov[i].iov_len = i;
        total_length  += iov[i].iov_len;
    }

    EXPECT_EQ(total_length, ucs_iovec_total_length(iov, iov_cnt));

    delete[] iov;
}

UCS_TEST_F(test_ucs_iov, iov_to_iov) {
    const size_t iov1_cnt   = 16;
    const size_t iov2_cnt   = 1024;
    const size_t max_length = 1024;
    void *iov_buf1          = NULL;
    void *iov_buf2          = NULL;

    test_iov_type_pair(static_cast<iov1_t*>(iov_buf1), iov1_cnt,
                       static_cast<iov2_t*>(iov_buf2), iov2_cnt,
                       max_length);
    test_iov_type_pair(static_cast<iov2_t*>(iov_buf1), iov1_cnt,
                       static_cast<iov1_t*>(iov_buf2), iov2_cnt,
                       max_length);
    test_iov_type_pair(static_cast<iov1_t*>(iov_buf1), iov1_cnt,
                       static_cast<iov1_t*>(iov_buf2), iov2_cnt,
                       max_length);
    test_iov_type_pair(static_cast<iov2_t*>(iov_buf1), iov1_cnt,
                       static_cast<iov2_t*>(iov_buf2), iov2_cnt,
                       max_length);
}