Rev 7520 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7520 | Rev 7537 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | extern void wtfree(void *pointer); |
8 | extern void wtfree(void *pointer); |
9 | extern void* wtrealloc(void* pointer, size_t size); |
9 | extern void* wtrealloc(void* pointer, size_t size); |
10 | extern void* wtcalloc (size_t num, size_t size); |
10 | extern void* wtcalloc (size_t num, size_t size); |
11 | extern int wtmalloc_freelist_check(); |
11 | extern int wtmalloc_freelist_check(); |
12 | extern int wtmalloc_poiner_check(void *ptr); |
12 | extern int wtmalloc_poiner_check(void *ptr); |
- | 13 | extern void wtdump_alloc_stats(); |
|
Line 13... | Line 14... | ||
13 | 14 | ||
14 | #ifdef __GNUC__ |
15 | #ifdef __GNUC__ |
15 | void* sysmalloc(size_t sz) |
16 | void* sysmalloc(size_t sz) |
16 | { |
17 | { |
17 | return malloc(sz); |
18 | return malloc(sz); |
18 | } |
19 | } |
Line 19... | Line 20... | ||
19 | #endif |
20 | #endif |
Line 20... | Line 21... | ||
20 | 21 | ||
21 | 22 | ||
22 | 23 | ||
Line 57... | Line 58... | ||
57 | 58 | ||
58 | puts("test allocation started"); |
59 | puts("test allocation started"); |
59 | // test allocation |
60 | // test allocation |
60 | for (i = 0; i < NUMPTR; i++) |
61 | for (i = 0; i < NUMPTR; i++) |
61 | { |
62 | { |
62 | sz = rand() % 1024; |
63 | sz = rand() % 4200; |
63 | pointers[i] = wtmalloc(sz); |
64 | pointers[i] = wtmalloc(sz); |
64 | sizes[i] = sz; |
65 | sizes[i] = sz; |
65 | values[i] = sz % 256; |
66 | values[i] = sz % 256; |
Line 87... | Line 88... | ||
87 | // test allocation in free list gaps |
88 | // test allocation in free list gaps |
88 | for (i = 0; i < NUMPTR; i++) |
89 | for (i = 0; i < NUMPTR; i++) |
89 | { |
90 | { |
90 | if (pointers[i]) continue; |
91 | if (pointers[i]) continue; |
Line 91... | Line 92... | ||
91 | 92 | ||
92 | sz = rand() % 1024; |
93 | sz = rand() % 4200; |
93 | pointers[i] = wtmalloc(sz); |
94 | pointers[i] = wtmalloc(sz); |
94 | sizes[i] = sz; |
95 | sizes[i] = sz; |
95 | values[i] = sz % 256; |
96 | values[i] = sz % 256; |
96 | memset(pointers[i], values[i], sz); |
97 | memset(pointers[i], values[i], sz); |
Line 100... | Line 101... | ||
100 | 101 | ||
101 | puts("test realloc started"); |
102 | puts("test realloc started"); |
102 | // test realloc |
103 | // test realloc |
103 | for (i = 0; i < NUMPTR; i++) |
104 | for (i = 0; i < NUMPTR; i++) |
104 | { |
105 | { |
105 | sz = rand() % 1024; |
106 | sz = rand() % 4200; |
- | 107 | pointers[i] = wtrealloc(pointers[i], sz); |
|
106 | pointers[i] = wtrealloc(pointers[i], sz); |
108 | |
107 | sizes[i] = sz; |
109 | sizes[i] = sz; |
108 | memset(pointers[i], values[i], sz); |
110 | memset(pointers[i], values[i], sz); |
109 | } |
111 | } |
110 | assert(wtmalloc_freelist_check()); |
112 | assert(wtmalloc_freelist_check()); |
Line 118... | Line 120... | ||
118 | wtfree(pointers[i]); |
120 | wtfree(pointers[i]); |
119 | pointers[i] = NULL; |
121 | pointers[i] = NULL; |
120 | } |
122 | } |
121 | assert(wtmalloc_freelist_check()); |
123 | assert(wtmalloc_freelist_check()); |
Line -... | Line 124... | ||
- | 124 | ||
- | 125 | wtdump_alloc_stats(); |
|
122 | 126 | ||
Line 123... | Line 127... | ||
123 | printf("tests all OK\n"); |
127 | printf("\ntests all OK\n"); |
Line 124... | Line 128... | ||
124 | 128 |