-
Notifications
You must be signed in to change notification settings - Fork 1
/
UnitTest.cpp
83 lines (68 loc) · 1.2 KB
/
UnitTest.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
#include "ConcurrentAlloc.h"
void TestThreadCache()
{
std::vector<void*> v;
for (size_t i = 0; i < 10; ++i)
{
v.push_back(ConcurrentAlloc(10));
cout << v.back() << endl;
}
cout << endl << endl;
for (size_t i = 0; i < 10; ++i)
{
ConcurrentFree(v[i], 10);
}
v.clear();
for (size_t i = 0; i < 10; ++i)
{
v.push_back(ConcurrentAlloc(10));
cout << v.back() << endl;
}
for (size_t i = 0; i < 10; ++i)
{
ConcurrentFree(v[i], 10);
}
v.clear();
}
void TestPageCache()
{
void* ptr = malloc((NPAGES - 1) << PAGE_SHIFT);
cout << ptr << endl;
if (ptr == nullptr)
{
throw std::bad_alloc();
}
PageID pageid = (PageID)ptr >> PAGE_SHIFT;
cout << pageid << endl;
void* shiftptr = (void*)(pageid << PAGE_SHIFT);
cout << shiftptr << endl;
}
void TestConcurrentAlloc()
{
size_t n = 100000;
std::vector<void*> v;
for (size_t i = 0; i < n; ++i)
{
v.push_back(ConcurrentAlloc(10));
}
cout << endl << endl;
for (size_t i = 0; i < n; ++i)
{
ConcurrentFree(v[i], 10);
}
v.clear();
for (size_t i = 0; i < n; ++i)
{
v.push_back(ConcurrentAlloc(10));
}
for (size_t i = 0; i < n; ++i)
{
ConcurrentFree(v[i], 10);
}
v.clear();
}
int main()
{
TestConcurrentAlloc();
return 0;
}