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
147
148
149
150
151
152
|
#include "../pkmem.h"
#include <csetjmp>
#include <signal.h>
#include <thread>
static bool expected_exit = false;
static bool caught = false;
static jmp_buf jmp_env;
void
exit(int code)
{
if (expected_exit) {
caught = true;
longjmp(jmp_env, 1);
} else {
_exit(code);
}
}
// assert() calls abort(), handle
void
handle_assert_abort(int sig)
{
if (expected_exit) {
caught = true;
longjmp(jmp_env, 1);
} else {
_exit(1);
}
}
int main(int argc, char *argv[])
{
signal(SIGABRT, handle_assert_abort);
(void)argc;
(void)argv;
int i;
// pk_new<T>
{
char *some_dang_string = pk_new<char>(64);
fprintf(stdout, "some_dang_string: %p\n", some_dang_string);
pk_delete<char>(some_dang_string, 64);
}
pk_memory_teardown_all();
// assert bucket count
do
{
int r;
r = setjmp(jmp_env);
if (r == 1) {
if (expected_exit == true && caught == true) {
expected_exit = false;
caught = false;
PK_LOGV_INF("%s: successfully caught err.\n", __FILE__);
fflush(stdout);
fflush(stderr);
break;
} else {
goto uncaught_err;
}
}
for (i = 0; i < PK_MAX_BUCKET_COUNT + 1; ++i) {
caught = false;
expected_exit = true;
pk_membucket *bkt = pk_bucket_create("lol", 1024, false);
expected_exit = false;
(void)bkt;
}
goto uncaught_err;
}
while(false);
pk_memory_teardown_all();
// assert no buckets available on pk_new with full memory
do
{
int r;
caught = false;
expected_exit = false;
for (i = 0; i < PK_MAX_BUCKET_COUNT; ++i) {
pk_membucket *bkt = pk_bucket_create("lol2", 1024, false);
char *asdf = pk_new<char>(768, bkt);
(void)asdf;
}
r = setjmp(jmp_env);
if (r == 1) {
if (expected_exit == true && caught == true) {
expected_exit = false;
caught = false;
PK_LOGV_INF("%s: successfully caught err.\n", __FILE__);
fflush(stdout);
fflush(stderr);
break;
} else {
goto uncaught_err;
}
}
caught = false;
expected_exit = true;
char *asdf = pk_new<char>(768);
(void)asdf;
expected_exit = false;
goto uncaught_err;
}
while(false);
pk_memory_teardown_all();
// assert no buckets available on pk_new with full memory
do
{
int r;
caught = false;
expected_exit = false;
pk_membucket *bkt = nullptr;
for (i = 0; i < PK_MAX_BUCKET_COUNT; ++i) {
bkt = pk_bucket_create("lol3", 1024, false);
char *asdf = pk_new<char>(768, bkt);
(void)asdf;
}
r = setjmp(jmp_env);
if (r == 1) {
if (expected_exit == true && caught == true) {
expected_exit = false;
caught = false;
PK_LOGV_INF("%s: successfully caught err.\n", __FILE__);
fflush(stdout);
fflush(stderr);
break;
} else {
goto uncaught_err;
}
}
caught = false;
expected_exit = true;
char *asdf = pk_new<char>(768, bkt);
(void)asdf;
expected_exit = false;
goto uncaught_err;
}
while(false);
pk_memory_teardown_all();
return 0;
uncaught_err:
PK_LOGV_ERR("%s: failed to catch err.\n", __FILE__);
fflush(stdout);
fflush(stderr);
return 1;
}
|