Repository navigation
Expand file tree
/
Copy pathmemory_pool_test.cc
More file actions
146 lines (111 loc) · 3.78 KB
/
Copy pathmemory_pool_test.cc
File metadata and controls
146 lines (111 loc) · 3.78 KB
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include <cstdint>
#include <gtest/gtest.h>
#include "arrow/memory_pool.h"
#include "arrow/memory_pool_test.h"
#include "arrow/status.h"
#include "arrow/testing/gtest_util.h"
namespace arrow {
struct DefaultMemoryPoolFactory {
static MemoryPool* memory_pool() { return default_memory_pool(); }
};
struct SystemMemoryPoolFactory {
static MemoryPool* memory_pool() { return system_memory_pool(); }
};
#ifdef ARROW_JEMALLOC
struct JemallocMemoryPoolFactory {
static MemoryPool* memory_pool() {
MemoryPool* pool;
ABORT_NOT_OK(jemalloc_memory_pool(&pool));
return pool;
}
};
#endif
#ifdef ARROW_MIMALLOC
struct MimallocMemoryPoolFactory {
static MemoryPool* memory_pool() {
MemoryPool* pool;
ABORT_NOT_OK(mimalloc_memory_pool(&pool));
return pool;
}
};
#endif
template <typename Factory>
class TestMemoryPool : public ::arrow::TestMemoryPoolBase {
public:
MemoryPool* memory_pool() override { return Factory::memory_pool(); }
};
TYPED_TEST_CASE_P(TestMemoryPool);
TYPED_TEST_P(TestMemoryPool, MemoryTracking) { this->TestMemoryTracking(); }
TYPED_TEST_P(TestMemoryPool, OOM) {
#ifndef ADDRESS_SANITIZER
this->TestOOM();
#endif
}
TYPED_TEST_P(TestMemoryPool, Reallocate) { this->TestReallocate(); }
REGISTER_TYPED_TEST_CASE_P(TestMemoryPool, MemoryTracking, OOM, Reallocate);
INSTANTIATE_TYPED_TEST_CASE_P(Default, TestMemoryPool, DefaultMemoryPoolFactory);
INSTANTIATE_TYPED_TEST_CASE_P(System, TestMemoryPool, SystemMemoryPoolFactory);
#ifdef ARROW_JEMALLOC
INSTANTIATE_TYPED_TEST_CASE_P(Jemalloc, TestMemoryPool, JemallocMemoryPoolFactory);
#endif
#ifdef ARROW_MIMALLOC
INSTANTIATE_TYPED_TEST_CASE_P(Mimalloc, TestMemoryPool, MimallocMemoryPoolFactory);
#endif
// Death tests and valgrind are known to not play well 100% of the time. See
// googletest documentation
#if !(defined(ARROW_VALGRIND) || defined(ADDRESS_SANITIZER))
TEST(DefaultMemoryPoolDeathTest, MaxMemory) {
MemoryPool* pool = default_memory_pool();
uint8_t* data1;
uint8_t* data2;
ASSERT_OK(pool->Allocate(100, &data1));
ASSERT_OK(pool->Allocate(50, &data2));
pool->Free(data2, 50);
ASSERT_OK(pool->Allocate(100, &data2));
pool->Free(data1, 100);
pool->Free(data2, 100);
ASSERT_EQ(200, pool->max_memory());
}
#endif // ARROW_VALGRIND
TEST(LoggingMemoryPool, Logging) {
MemoryPool* pool = default_memory_pool();
LoggingMemoryPool lp(pool);
uint8_t* data;
ASSERT_OK(pool->Allocate(100, &data));
uint8_t* data2;
ASSERT_OK(pool->Allocate(100, &data2));
pool->Free(data, 100);
pool->Free(data2, 100);
ASSERT_EQ(200, pool->max_memory());
}
TEST(ProxyMemoryPool, Logging) {
MemoryPool* pool = default_memory_pool();
ProxyMemoryPool pp(pool);
uint8_t* data;
ASSERT_OK(pool->Allocate(100, &data));
uint8_t* data2;
ASSERT_OK(pp.Allocate(300, &data2));
ASSERT_EQ(400, pool->bytes_allocated());
ASSERT_EQ(300, pp.bytes_allocated());
pool->Free(data, 100);
pp.Free(data2, 300);
ASSERT_EQ(0, pool->bytes_allocated());
ASSERT_EQ(0, pp.bytes_allocated());
}
} // namespace arrow