|
Revision 21, 1.1 kB
(checked in by richdawe, 7 years ago)
|
Add another test program
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
#include <stdio.h> |
|---|
| 2 |
#include <string.h> |
|---|
| 3 |
|
|---|
| 4 |
#include "umem.h" |
|---|
| 5 |
|
|---|
| 6 |
static const char *TESTSTRINGS[] = { |
|---|
| 7 |
"fred", |
|---|
| 8 |
"fredfredfred", |
|---|
| 9 |
"thisisabitlongerthantheotherstrings", |
|---|
| 10 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890", |
|---|
| 11 |
}; |
|---|
| 12 |
|
|---|
| 13 |
#define N_TESTSTRINGS (sizeof(TESTSTRINGS) / sizeof(TESTSTRINGS[0])) |
|---|
| 14 |
#define N_TESTS 1000 |
|---|
| 15 |
|
|---|
| 16 |
int |
|---|
| 17 |
main (int argc, char *argv[]) |
|---|
| 18 |
{ |
|---|
| 19 |
char *testcases[N_TESTSTRINGS][N_TESTS + 1]; |
|---|
| 20 |
size_t len[N_TESTSTRINGS]; |
|---|
| 21 |
int i, j; |
|---|
| 22 |
|
|---|
| 23 |
memset(testcases, 0, sizeof(testcases)); |
|---|
| 24 |
|
|---|
| 25 |
umem_startup(NULL, 0, 0, NULL, NULL); |
|---|
| 26 |
|
|---|
| 27 |
for (i = 0; i < N_TESTSTRINGS; ++i) |
|---|
| 28 |
{ |
|---|
| 29 |
len[i] = strlen(TESTSTRINGS[i]) + 1; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
puts("Allocating..."); |
|---|
| 33 |
|
|---|
| 34 |
for (j = 0; j < N_TESTS; ++j) |
|---|
| 35 |
{ |
|---|
| 36 |
for (i = 0; i < N_TESTSTRINGS; ++i) |
|---|
| 37 |
{ |
|---|
| 38 |
testcases[i][j] = umem_alloc(len[i], UMEM_DEFAULT); |
|---|
| 39 |
strcpy(testcases[i][j], TESTSTRINGS[i]); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
puts("Deallocating..."); |
|---|
| 44 |
|
|---|
| 45 |
for (j = 0; j < N_TESTS; ++j) |
|---|
| 46 |
{ |
|---|
| 47 |
for (i = N_TESTSTRINGS - 1; i >= 0; --i) |
|---|
| 48 |
{ |
|---|
| 49 |
umem_free(testcases[i][j], len[i]); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
if ((j % 25) == 0) |
|---|
| 53 |
{ |
|---|
| 54 |
puts("Reaping..."); |
|---|
| 55 |
umem_reap(); |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
puts("Done"); |
|---|
| 60 |
|
|---|
| 61 |
return 0; |
|---|
| 62 |
} |
|---|