-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_malloc.c
66 lines (59 loc) · 1.2 KB
/
test_malloc.c
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
#include "malloc.h"
#define MAXP 400
#define SUBP 10
#define NPASS 25
#define NLOOP 1
double metrics[NLOOP];
int lrand()
{
static unsigned long long next = 0;
next = next * 0x5deece66dLL + 11;
return (int)((next >> 16) & 0x7fffffff);
}
char *pointers[MAXP];
int size[MAXP];
int rsize()
{
int rv = 8 << (lrand() % 15);
rv = lrand() & (rv-1);
return rv;
}
void test_malloc(void)
{
int i, r, loop, pass, subpass;
int absmax=0, curmax=0;
int realloc_mask = -1;
for (loop=0; loop<NLOOP; loop++) {
for (pass=0; pass<NPASS; pass++) {
for (subpass=0; subpass<SUBP; subpass++) {
for (i=0; i<MAXP; i++) {
int rno = lrand();
if (rno & 8) {
if (pointers[i]) {
if (!(rno & realloc_mask)) {
r = rsize();
curmax -= size[i];
curmax += r;
pointers[i] = realloc(pointers[i], rsize());
size[i] = r;
if (absmax < curmax)
absmax = curmax;
} else {
curmax -= size[i];
free(pointers[i]);
pointers[i] = 0;
}
} else {
r = rsize();
curmax += r;
pointers[i] = malloc(r);
size[i] = r;
if (absmax < curmax)
absmax = curmax;
}
}
}
}
}
}
}