File: test_strided_alloc.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 (63 lines) | stat: -rw-r--r-- 1,454 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
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2018. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/

#include <common/test.h>
extern "C" {
#include <ucs/datastruct/strided_alloc.h>
}

#include <limits.h>
#include <vector>
#include <queue>

class test_strided_alloc : public ucs::test {
protected:
    static const size_t area_size   = 64;
    static const unsigned num_areas = 3;
};


UCS_TEST_F(test_strided_alloc, basic) {

    ucs_strided_alloc_t sa;

    ucs_strided_alloc_init(&sa, area_size, num_areas);

    std::vector<void*> objs;
    for (size_t i = 0; i < 2; ++i) {
        /* allocate */
        void *base = ucs_strided_alloc_get(&sa, "test");

        for (unsigned j = 0; j < num_areas; ++j) {
            void *area = ucs_strided_elem_get(base, 0, j);
            memset(area, i*j, area_size);
        }

        /* save in a vector */
        objs.push_back(base);
    }

    /* check data integrity */
    char buf[area_size];
    for (size_t i = 0; i < objs.size(); ++i) {
        void *base = objs[i];

        for (unsigned j = 0; j < num_areas; ++j) {
            void *area = ucs_strided_elem_get(base, 0, j);
            memset(buf, i*j, area_size);
            EXPECT_EQ(0, memcmp(area, buf, area_size));
        }
    }

    /* release */
    while (!objs.empty()) {
        void *base = objs.back();
        objs.pop_back();
        ucs_strided_alloc_put(&sa, base);
    }

    ucs_strided_alloc_cleanup(&sa);
}