diff --git a/.cvsignore b/.cvsignore index 3a5c1e6..544bfaf 100644 --- a/.cvsignore +++ b/.cvsignore @@ -17,6 +17,7 @@ stamp-h stamp-h.in stamp-h1 umem_test +umem_test2 Doxyfile umem.spec *.tar.gz diff --git a/Makefile.am b/Makefile.am index 4ab8f1e..9086017 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,11 +1,14 @@ EXTRA_DIST = COPYRIGHT OPENSOLARIS.LICENSE umem.spec Doxyfile lib_LTLIBRARIES = libumem.la -noinst_PROGRAMS = umem_test +noinst_PROGRAMS = umem_test umem_test2 umem_test_SOURCES = umem_test.c umem_test_LDADD = -lumem -lpthread -ldl +umem_test2_SOURCES = umem_test2.c +umem_test2_LDADD = -lumem -lpthread -ldl + libumem_la_SOURCES = init_lib.c \ umem_agent_support.c \ umem_fail.c \ @@ -31,7 +34,7 @@ libumem_la_SOURCES = init_lib.c \ nobase_include_HEADERS = umem.h sys/vmem.h -TESTS = umem_test +TESTS = umem_test umem_test2 html-local: mkdir -p docs diff --git a/umem_test2.c b/umem_test2.c new file mode 100644 index 0000000..8994b42 --- /dev/null +++ b/umem_test2.c @@ -0,0 +1,62 @@ +#include +#include + +#include "umem.h" + +static const char *TESTSTRINGS[] = { + "fred", + "fredfredfred", + "thisisabitlongerthantheotherstrings", + "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890", +}; + +#define N_TESTSTRINGS (sizeof(TESTSTRINGS) / sizeof(TESTSTRINGS[0])) +#define N_TESTS 1000 + +int +main (int argc, char *argv[]) +{ + char *testcases[N_TESTSTRINGS][N_TESTS + 1]; + size_t len[N_TESTSTRINGS]; + int i, j; + + memset(testcases, 0, sizeof(testcases)); + + umem_startup(NULL, 0, 0, NULL, NULL); + + for (i = 0; i < N_TESTSTRINGS; ++i) + { + len[i] = strlen(TESTSTRINGS[i]) + 1; + } + + puts("Allocating..."); + + for (j = 0; j < N_TESTS; ++j) + { + for (i = 0; i < N_TESTSTRINGS; ++i) + { + testcases[i][j] = umem_alloc(len[i], UMEM_DEFAULT); + strcpy(testcases[i][j], TESTSTRINGS[i]); + } + } + + puts("Deallocating..."); + + for (j = 0; j < N_TESTS; ++j) + { + for (i = N_TESTSTRINGS - 1; i >= 0; --i) + { + umem_free(testcases[i][j], len[i]); + } + + if ((j % 25) == 0) + { + puts("Reaping..."); + umem_reap(); + } + } + + puts("Done"); + + return 0; +}