Add another test program

This commit is contained in:
Richard Dawe 2006-07-25 20:15:33 +00:00
parent 07f343fdd8
commit 817aa395a1
3 changed files with 68 additions and 2 deletions

View file

@ -17,6 +17,7 @@ stamp-h
stamp-h.in stamp-h.in
stamp-h1 stamp-h1
umem_test umem_test
umem_test2
Doxyfile Doxyfile
umem.spec umem.spec
*.tar.gz *.tar.gz

View file

@ -1,11 +1,14 @@
EXTRA_DIST = COPYRIGHT OPENSOLARIS.LICENSE umem.spec Doxyfile EXTRA_DIST = COPYRIGHT OPENSOLARIS.LICENSE umem.spec Doxyfile
lib_LTLIBRARIES = libumem.la lib_LTLIBRARIES = libumem.la
noinst_PROGRAMS = umem_test noinst_PROGRAMS = umem_test umem_test2
umem_test_SOURCES = umem_test.c umem_test_SOURCES = umem_test.c
umem_test_LDADD = -lumem -lpthread -ldl umem_test_LDADD = -lumem -lpthread -ldl
umem_test2_SOURCES = umem_test2.c
umem_test2_LDADD = -lumem -lpthread -ldl
libumem_la_SOURCES = init_lib.c \ libumem_la_SOURCES = init_lib.c \
umem_agent_support.c \ umem_agent_support.c \
umem_fail.c \ umem_fail.c \
@ -31,7 +34,7 @@ libumem_la_SOURCES = init_lib.c \
nobase_include_HEADERS = umem.h sys/vmem.h nobase_include_HEADERS = umem.h sys/vmem.h
TESTS = umem_test TESTS = umem_test umem_test2
html-local: html-local:
mkdir -p docs mkdir -p docs

62
umem_test2.c Normal file
View file

@ -0,0 +1,62 @@
#include <stdio.h>
#include <string.h>
#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;
}