-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (74 loc) · 1.91 KB
/
main.cpp
File metadata and controls
91 lines (74 loc) · 1.91 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
#include <iostream>
#include <vector>
#include <cassert>
#include "ConcurrentAlloc.h"
using namespace std;
int main()
{
cout << "test begin..." << endl;
void* p1 = ConcurrentAlloc(60);
void* p2 = ConcurrentAlloc(70);
void* p3 = ConcurrentAlloc(128);
void* p4 = ConcurrentAlloc(256);
cout << "p1 = " << p1 << endl;
cout << "p2 = " << p2 << endl;
cout << "p3 = " << p3 << endl;
cout << "p4 = " << p4 << endl;
assert(p1 != nullptr);
assert(p2 != nullptr);
assert(p3 != nullptr);
assert(p4 != nullptr);
ConcurrentFree(p1, 60);
ConcurrentFree(p2, 70);
ConcurrentFree(p3, 128);
ConcurrentFree(p4, 256);
cout << "basic alloc/free passed." << endl;
vector<void*> v;
for (int i = 0; i < 1000; ++i)
{
void* p = ConcurrentAlloc(64);
assert(p != nullptr);
v.push_back(p);
}
cout << "1000 alloc(64) passed." << endl;
for (auto p : v)
{
ConcurrentFree(p, 64);
}
v.clear();
cout << "1000 free(64) passed." << endl;
size_t sizes[] = {8, 16, 24, 32, 48, 64, 96, 128, 256, 512, 1024, 2048};
for (int round = 0; round < 10; ++round)
{
for (size_t sz : sizes)
{
void* p = ConcurrentAlloc(sz);
assert(p != nullptr);
v.push_back(p);
}
int idx = 0;
for (size_t sz : sizes)
{
ConcurrentFree(v[idx++], sz);
}
v.clear();
}
cout << "mixed size test passed." << endl;
for (int round = 0; round < 100; ++round)
{
for (int i = 0; i < 200; ++i)
{
void* p = ConcurrentAlloc(60);
assert(p != nullptr);
v.push_back(p);
}
for (auto p : v)
{
ConcurrentFree(p, 60);
}
v.clear();
}
cout << "stress test passed." << endl;
cout << "all test passed." << endl;
return 0;
}