File: decorator_test.cpp

package info (click to toggle)
memkind 1.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,508 kB
  • sloc: ansic: 72,572; cpp: 39,493; sh: 4,594; perl: 4,250; xml: 2,044; python: 1,753; makefile: 1,393; csh: 7
file content (95 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download
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
// SPDX-License-Identifier: BSD-2-Clause
/* Copyright (C) 2014 - 2021 Intel Corporation. */

#include "memkind.h"

#include "common.h"
#include "config.h"
#include "decorator_test.h"

size_t size = 16;
memkind_t kind = MEMKIND_DEFAULT;

class DecoratorTest: public ::testing::Test
{

protected:
    void SetUp()
    {
        decorators_state = new decorators_flags();
    }

    void TearDown()
    {
        free(decorators_state);
    }
};

TEST_F(DecoratorTest, test_TC_MEMKIND_DT_malloc)
{
#ifdef MEMKIND_DECORATION_ENABLED
    void *buffer = memkind_malloc(kind, size);

    ASSERT_TRUE(buffer != NULL);
    EXPECT_EQ(1, decorators_state->malloc_pre);
    EXPECT_EQ(1, decorators_state->malloc_post);

    memkind_free(NULL, buffer);
#endif
}

TEST_F(DecoratorTest, test_TC_MEMKIND_DT_calloc)
{
#ifdef MEMKIND_DECORATION_ENABLED
    void *buffer = memkind_calloc(kind, 1, size);

    ASSERT_TRUE(buffer != NULL);
    EXPECT_EQ(1, decorators_state->calloc_pre);
    EXPECT_EQ(1, decorators_state->calloc_post);

    memkind_free(NULL, buffer);
#endif
}

TEST_F(DecoratorTest, test_TC_MEMKIND_DT_posix_memalign)
{
#ifdef MEMKIND_DECORATION_ENABLED
    void *buffer;

    int res = memkind_posix_memalign(kind, &buffer, 8, size);

    ASSERT_TRUE(buffer != NULL);
    ASSERT_EQ(0, res);
    EXPECT_EQ(1, decorators_state->posix_memalign_pre);
    EXPECT_EQ(1, decorators_state->posix_memalign_post);

    memkind_free(NULL, buffer);
#endif
}

TEST_F(DecoratorTest, test_TC_MEMKIND_DT_realloc)
{
#ifdef MEMKIND_DECORATION_ENABLED
    void *buffer = memkind_realloc(kind, NULL, size);

    ASSERT_TRUE(buffer != NULL);
    EXPECT_EQ(1, decorators_state->realloc_pre);
    EXPECT_EQ(1, decorators_state->realloc_post);

    memkind_free(NULL, buffer);
#endif
}

TEST_F(DecoratorTest, test_TC_MEMKIND_DT_free)
{
#ifdef MEMKIND_DECORATION_ENABLED
    void *buffer = memkind_malloc(kind, size);

    ASSERT_TRUE(buffer != NULL);

    memkind_free(NULL, buffer);

    EXPECT_EQ(1, decorators_state->free_pre);
    EXPECT_EQ(1, decorators_state->free_post);
#endif
}