-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_test.cpp
101 lines (84 loc) · 2.51 KB
/
memory_test.cpp
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
#include <gtest/gtest.h>
#include <sps/memory>
#include <sps/functional.hpp>
#include <sps/multi_malloc.hpp>
class A {
public:
A() {
m_data = sps::unique_aligned_array_create<float>(20);
}
private:
sps::unique_aligned_array<float> m_data;
};
struct B {
B() : pData(nullptr) {
pData = new int[10];
}
~B() {
delete pData;
}
int* pData;
};
TEST(memory_test, aligned_unique_array) {
auto a = sps::unique_aligned_array_create<float>(0);
auto b = sps::unique_aligned_array_create<float>(35);
auto c = sps::unique_aligned_multi_array_create<double, 2>(1, 1);
auto d = sps::unique_aligned_multi_array_create<double, 2>(0, 0);
auto f = sps::unique_aligned_multi_array_create<double, 2>(1, 0);
auto g = sps::unique_aligned_multi_array_create<double, 2>(0, 1);
#ifdef __GNUG__
// sps::unique_multi_array<double, 2> h =
// sps::nix::unique_aligned_multi_array_create<double, 2>(7, 8);
// size_t m = 7;
// size_t n = 8;
// const size_t nDims = 2;
// sps::unique_multi_array<double, nDims> i =
// sps::unique_multi_array_create<double, nDims>(m, n);
#endif
// Must fail
// auto j = sps::unique_aligned_multi_array<B,2>(1,1);
// auto k = sps::unique_aligned_multi_array_create<B, 2>(1,1);
#ifdef __GNUG__
auto l = sps::unique_aligned_multi_array_create<double, 1>(1);
#endif
ASSERT_TRUE(true);
}
TEST(memory_test, unique_member) {
A a;
}
TEST(memory_test, multi_malloc) {
float* pFloat0 = static_cast<float*>(_mm_multi_malloc<float>(3, 2, 2, 4));
_mm_multi_free<float>(pFloat0, 3);
#ifndef _MSC_VER
float* pFloat1 = static_cast<float*>(_mm_multi_malloc_nc<float>(2, 10, 10));
_mm_multi_free_nc<float>(pFloat1, 2);
#endif
}
TEST(memory_test, reset_array) {
auto b = sps::unique_aligned_array_create<float>(35);
b.reset(static_cast<float*>(_mm_malloc(45*sizeof(float), 16)));
b.get_deleter() = sps::make::function([](float* f)->void { _mm_free(f);});
}
template <class T>
struct AlignedData : sps::aligned<4*sizeof(T)> {
T a;
};
TEST(memory_test, inherit_alignment) {
float f;
SPS_UNREFERENCED_PARAMETER(f);
AlignedData<double> c[2];
ASSERT_EQ(((uintptr_t)&c[1] & 0x1F), 0UL);
}
int main(int argc, char* argv[]) {
#ifdef __GNUG__
static_assert(sps::ptr_depth<sps::depth_ptr<float, 2>::value_type>::level == 2,
"The level of depth_ptr<T,2>::value_type must equal 2");
#endif
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
/* Local variables: */
/* indent-tabs-mode: nil */
/* tab-width: 2 */
/* c-basic-offset: 2 */
/* End: */