1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-15 07:41:09 -08:00
new test

Copied from Perforce
 Change: 20314
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Richard Tucker 1998-10-29 13:31:33 +00:00
parent b403affe60
commit b8922c80cd
10 changed files with 1126 additions and 0 deletions

85
mps/qa/function/139.c Normal file
View file

@ -0,0 +1,85 @@
/*
TEST_HEADER
id = $HopeName$
summary = MVFF alloc from emergency list test
language = c
link = testlib.o
END_HEADER
*/
/* MVFF will put free blocks on emergency lists if it cannot allocate
in the CBS. There is a bug in anchovy.1 in which the emergency lists
are not checked when allocating, so some allocs will fail needlessly.
*/
#include "testlib.h"
#include "mpscmvff.h"
#include "mpsavm.h"
#define COMLIMIT1 (10*1024*1024)
#define COMLIMIT2 (12*1024*1024)
#define SMALLSIZE (8)
#define NSMALL (4*1024)
#define BIGSIZE (64)
#define EXTENDBY (8*1024)
#define MAXLARGE (1000*1024)
void *stackpointer;
mps_arena_t arena;
static mps_addr_t
largeObjects[MAXLARGE],
smallObjects[NSMALL];
static void test(void) {
mps_thr_t thread;
mps_pool_t pool;
unsigned int i;
unsigned long nLarge;
cdie(mps_arena_create(&arena, mps_arena_class_vmnz(),
(size_t) (1024*1024*50)), "create arena");
cdie(mps_thread_reg(&thread, arena), "register thread");
mps_arena_commit_limit_set(arena, COMLIMIT1);
die(
mps_pool_create(&pool, arena, mps_class_mvff(),
EXTENDBY, 8, 8, 0, 0, 1),
"create MVFF pool");
for (i = 0; i < NSMALL; i++) {
die(mps_alloc(&smallObjects[i], pool, SMALLSIZE), "small alloc failed");
}
nLarge = 0;
while (mps_alloc(&largeObjects[nLarge], pool, BIGSIZE) == MPS_RES_OK) {
nLarge ++;
}
report("nLarge", "%lu", nLarge);
for (i = 0; i < NSMALL; i += 2) {
mps_free(pool, smallObjects[i], SMALLSIZE);
}
comment("Freed every other small object.");
/* The CBS should be in emergency mode now. */
mps_free(pool, largeObjects[3], BIGSIZE);
die(mps_alloc(&largeObjects[3], pool, BIGSIZE), "free and alloc failed");
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void) {
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

190
mps/qa/function/140.c Normal file
View file

@ -0,0 +1,190 @@
/*
TEST_HEADER
id = $HopeName$
summary = MVFF low-memory test
language = c
link = testlib.o
END_HEADER
*/
#include <time.h>
#include "testlib.h"
#include "mpscmvff.h"
#include "mpsavm.h"
#define MAXNUMBER 1000000
void *stackpointer;
mps_space_t space;
mps_bool_t slotHigh, arenaHigh, firstFit;
int comments = 0;
static struct {mps_addr_t addr; size_t size;} queue[MAXNUMBER];
static mps_pool_debug_option_s debugOpts = {(void *) "fefifofu", 8};
enum {SEQ=0, RAN=1, SEQGAP=2, RANGAP=3, DUMMY=4};
static char *tdesc[] = {"sequential", "random",
"sequential gap", "random gap", "dummy"};
static void setobj(mps_addr_t a, size_t size, unsigned char val)
{
unsigned char *b;
b = a;
commentif(comments, "Set %x, size %x = %i", b, size, (int) val);
while (size>0)
{
*b=val;
b++;
size--;
}
}
static int chkobj(mps_addr_t a, size_t size, unsigned char val)
{
unsigned char *b;
b = a;
while (size>0)
{
/* comment("%p == %i", b, (int) val);
*/
if (*b != val) return 0;
b++;
size--;
}
return 1;
}
static void dt(int kind,
size_t extendBy, size_t avgSize, size_t align,
size_t mins, size_t maxs, int number, int iter)
{
mps_pool_t pool;
int i, hd;
clock_t time0, time1;
size_t size;
int secs;
asserts(number <= MAXNUMBER, "number too big");
time0 = clock();
asserts(time0 != -1, "processor time not available");
die(
mps_pool_create(&pool, space, mps_class_mvff_debug(),
&debugOpts,
extendBy, avgSize, align, slotHigh, arenaHigh, firstFit),
"create MVFF pool");
for(hd=0; hd<number; hd++)
{
queue[hd].addr = NULL;
size = ranrange(mins, maxs);
if ((ranint(2) && (kind & 2)) || (kind==DUMMY))
{
}
else
{
if (MPS_RES_OK == mps_alloc(&queue[hd].addr, pool, size)) {
commentif(comments, "Alloc: %i at %x, size %x", hd, queue[hd].addr, size);
setobj(queue[hd].addr, size, (unsigned char) (hd%256));
queue[hd].size = size;
} else {
commentif(comments, "Alloc failed: %i, size %x", hd, size);
}
}
};
hd=-1;
for(i=0; i<iter; i++)
{
if (ranint(100) == 1) {
mps_pool_check_fenceposts(pool);
}
if (kind & 1) hd = ranint(number);
else {ranint(number); hd=(hd+1)%number;} /* call raninit anyway
to use same time */
if (queue[hd].addr != NULL)
{
asserts(chkobj(queue[hd].addr, queue[hd].size, (unsigned char) (hd%256)),
"corrupt at %x (%s: %x, %x, %x, %x, %x, %i, %i, %i)",
queue[hd].addr,
tdesc[kind], (int) extendBy, (int) avgSize, (int) align,
(int) mins, (int) maxs, number, iter,
slotHigh*100+arenaHigh*10+firstFit);
commentif(comments, "Free %i at %x, size %x", hd,
queue[hd].addr, queue[hd].size);
mps_free(pool, queue[hd].addr, queue[hd].size);
}
size = ranrange(mins, maxs);
queue[hd].addr=NULL;
if ((ranint(2) && (kind & 2)) || (kind==DUMMY))
{
}
else
{
if (MPS_RES_OK == mps_alloc(&queue[hd].addr, pool, size)) {
commentif(comments, "Alloc %i at %x, size %x", hd, queue[hd].addr, size);
setobj(queue[hd].addr, size, (unsigned char) (hd%256));
queue[hd].size = size;
} else {
commentif(comments, "Alloc failed: %i, size %x", hd, size);
}
}
}
mps_pool_destroy(pool);
time1=clock();
secs=(int) 100*(time1-time0)/CLOCKS_PER_SEC;
comment("%s test (%x, %x, %x, %x, %x, %i, %i, %i) in %i centisecs",
tdesc[kind], (int) extendBy, (int) avgSize, (int) align,
(int) mins, (int) maxs, number, iter,
slotHigh*100+arenaHigh*10+firstFit, secs);
}
static void test(void)
{
mps_thr_t thread;
size_t mins;
int symm;
size_t comlimit;
cdie(mps_arena_create(&space, mps_arena_class_vm(), (size_t) (1024*1024*50)), "create space");
cdie(mps_thread_reg(&thread, space), "register thread");
for (comlimit = 512*1024; comlimit > 0; comlimit -= 4*1024) {
mps_arena_commit_limit_set(space, comlimit);
report("limit", "%x", comlimit);
symm = ranint(8);
slotHigh = (symm >> 2) & 1;
arenaHigh = (symm >> 1) & 1;
firstFit = (symm & 1);
mins = ranrange(1, 16);
dt(RANGAP, 64*1024, 32, 8, 4*mins, 4*ranrange(mins, mins*100), 1000, 100000);
}
mps_thread_dereg(thread);
mps_arena_destroy(space);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

62
mps/qa/function/144.c Normal file
View file

@ -0,0 +1,62 @@
/*
TEST_HEADER
id = $HopeName$
summary = MVFF fenceposting check
language = c
link = testlib.o
END_HEADER
*/
#include "testlib.h"
#include "mpscmvff.h"
#include "mpsavm.h"
void *stackpointer;
mps_arena_t arena;
static mps_pool_debug_option_s debugOpts = {(void *)"bibblebo", 8};
static void test(void) {
mps_thr_t thread;
mps_pool_t pool;
mps_addr_t a, b;
char *c;
cdie(mps_arena_create(&arena, mps_arena_class_vmnz(),
(size_t) (1024*1024*50)), "create arena");
cdie(mps_thread_reg(&thread, arena), "register thread");
die(
mps_pool_create(&pool, arena, mps_class_mvff_debug(), &debugOpts,
8192, 8, 8, 0, 0, 1),
"create MVFF pool");
die(mps_alloc(&a, pool, 64), "alloc a");
die(mps_alloc(&b, pool, 64), "alloc b");
c = a;
c -= 1;
*c = 0;
mps_pool_check_fenceposts(pool);
comment("Fencepost check.");
c += 67;
*c = 0;
mps_pool_check_fenceposts(pool);
comment("Fencepost check.");
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void) {
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

106
mps/qa/function/146.c Normal file
View file

@ -0,0 +1,106 @@
/*
TEST_HEADER
id = $HopeName$
summary = EPVM low-memory test
language = c
link = testlib.o epvmfmt.o
END_HEADER
*/
#include "testlib.h"
#include "mpscepvm.h"
#include "mpsavm.h"
#include "epvmfmt.h"
#define MAX_SAVE 10
#define INIT_SAVE 0
#define OBJ_SIZE 8
#define MAXAPS 4096
void *stackpointer;
static mps_ap_t api[MAXAPS];
static void tryout(size_t comlimit, int aps) {
mps_arena_t arena;
mps_thr_t thread;
mps_fmt_t format;
mps_pool_t pool, pool1;
mps_ap_t ap;
psobj *a;
int i, p;
comment("Limit: %lu, aps: %d", (unsigned long) comlimit, aps);
if (mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*128)))
goto no_arena;
mps_arena_commit_limit_set(arena, comlimit);
if (mps_thread_reg(&thread, arena)) goto no_thread;
if (mps_fmt_create_A(&format, arena, &fmtepvm)) goto no_fmt;
if (mps_pool_create(&pool1, arena, mps_class_epvm(), format, 10, 0))
goto no_pool;
for (p = 0; p < aps; p ++) {
if (mps_ap_create(&api[p], pool1, 0)) {
break;
};
}
if (mps_pool_create(&pool, arena, mps_class_epvm(), format, 10, 0))
goto no_pool2;
if (mps_ap_create(&ap, pool, 0)) goto no_ap;
allocrepvm(&a, ap, OBJ_SIZE);
mps_epvm_save(pool);
allocrepvm(&a, ap, OBJ_SIZE);
mps_epvm_save(pool);
for (i=0; i<100; i++) {
allocrepvm(&a, ap, OBJ_SIZE);
}
mps_epvm_restore(pool, 0);
mps_ap_destroy(ap);
no_ap:
mps_pool_destroy(pool);
no_pool2:
for (; p >= 0; p--) {
if (api[p]) {
mps_ap_destroy(api[p]);
}
}
mps_pool_destroy(pool1);
no_pool:
mps_fmt_destroy(format);
no_fmt:
mps_thread_dereg(thread);
no_thread:
mps_arena_destroy(arena);
no_arena:
a = NULL;
}
static void test(void)
{
int i;
for (i = 0; i < MAXAPS; i ++) {
tryout(1024*64, i);
}
}
int main(void) {
void *m;
stackpointer=&m;
easy_tramp(test);
pass();
return 0;
}

77
mps/qa/function/214.c Normal file
View file

@ -0,0 +1,77 @@
/*
TEST_HEADER
id = $HopeName$
summary = MV2 greed test
language = c
link = testlib.o
parameters = OBJECTS=1000 OBJSIZE=8192 DEPTH=2 FRAGLIMIT=50
END_HEADER
*/
#include "testlib.h"
#include "mpscmv2.h"
#include "mpsavm.h"
/* this shouldn't be necessary, but it's not provided anywhere */
typedef MPS_T_WORD mps_count_t;
void *stackpointer;
mps_arena_t arena;
static mps_addr_t objs[OBJECTS];
static mps_res_t mv2_alloc(mps_addr_t *ref, mps_ap_t ap, size_t size) {
mps_res_t res;
size = ((size+7)/8)*8;
do {
MPS_RESERVE_BLOCK(res, *ref, ap, size);
if (res != MPS_RES_OK) return res;
} while (!mps_commit(ap, *ref, size));
return MPS_RES_OK;
}
static void test (void) {
mps_thr_t thread;
mps_pool_t pool;
mps_ap_t ap;
int i;
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)), "create arena");
cdie(mps_thread_reg(&thread, arena), "register thread");
die(
mps_pool_create(&pool, arena, mps_class_mv2(),
OBJSIZE, OBJSIZE, OBJSIZE, DEPTH, FRAGLIMIT),
"create MV2 pool");
die(mps_ap_create(&ap, pool, MPS_RANK_AMBIG), "create ap");
for (i = 0; i < OBJECTS; i++) {
die(mv2_alloc(&objs[i], ap, OBJSIZE), "alloc");
}
report("size1", "%ld", mps_arena_committed(arena));
for (i = 0; i < OBJECTS; i+=2) {
mps_free(pool, objs[i], OBJSIZE);
die(mv2_alloc(&objs[i], ap, OBJSIZE), "alloc");
}
report("size2", "%ld", mps_arena_committed(arena));
mps_ap_destroy(ap);
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

112
mps/qa/function/216.c Normal file
View file

@ -0,0 +1,112 @@
/*
TEST_HEADER
id = $HopeName$
summary = MV2 from af_six measuring fragmentation
language = c
link = testlib.o
stdin = af_six
parameters = MINSIZE=8 AVGSIZE=128 MAXSIZE=65536 DEPTH FRAGLIMIT
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscmv2.h"
#include "mpsavm.h"
#define MAXOBJS (30000)
mps_addr_t objs[MAXOBJS];
size_t sizes[MAXOBJS];
size_t total_size;
size_t committed;
int fragmentation;
double fragacc;
double commacc;
double sizeacc;
double count;
void *stackpointer;
mps_arena_t arena;
static void test(void)
{
mps_thr_t thread;
mps_pool_t pool;
mps_ap_t ap;
log_event event;
int id;
char *c;
size_t size;
unsigned long maxcom;
mps_res_t res;
maxcom = 0;
fragacc = 0;
commacc = 0;
sizeacc = 0;
count = 0;
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)),
"create space");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_pool_create(&pool, arena, mps_class_mv2(),
MINSIZE, AVGSIZE, MAXSIZE, DEPTH, FRAGLIMIT),
"create MV2 pool");
cdie(mps_ap_create(&ap, pool, MPS_RANK_AMBIG), "create ap");
committed = mps_arena_committed(arena);
while (read_event(&event)) {
if (event.type == EVENT_ALLOC) {
id = event.alloc.id;
asserts(id < MAXOBJS, "MAXOBJS too small");
size = event.alloc.size;
sizes[id] = size;
size = ((size+7)/8)*8;
do {
MPS_RESERVE_BLOCK(res, objs[id], ap, size);
asserts(res == MPS_RES_OK, "alloc failed");
} while (!mps_commit(ap, objs[id], size));
total_size+=sizes[id];
c = objs[id];
*c = 43;
} else if (event.type == EVENT_FREE) {
id = event.free.id;
mps_free(pool, objs[id], sizes[id]);
total_size-=sizes[id];
}
committed = mps_arena_committed(arena);
if (committed > maxcom) maxcom=committed;
fragacc += ((double) (committed-total_size))/((double) committed);
commacc += (double) committed;
sizeacc += (double) total_size;
count += 1;
}
report("maxcom", "%ld", maxcom);
report("fragavg", "%f", fragacc/count);
report("fragweighted", "%f", (commacc-sizeacc)/commacc);
report("commavg", "%f", commacc/count);
report("sizeavg", "%f", sizeacc/count);
mps_ap_destroy(ap);
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

95
mps/qa/function/217.c Normal file
View file

@ -0,0 +1,95 @@
/*
TEST_HEADER
id = $HopeName$
summary = MVFF allocate from SW log (af_six)
language = c
link = testlib.o
stdin = af_six
parameters = EXTENDBY=65536 AVGSIZE=128 ALIGN=8 ARENAHIGH=1 SLOTHIGH=1 FIRST=1
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscmvff.h"
#include "mpsavm.h"
#define MAXOBJS (30000)
mps_addr_t objs[MAXOBJS];
size_t sizes[MAXOBJS];
size_t total_size;
size_t committed;
int fragmentation;
int lastfrag=0;
void *stackpointer;
mps_arena_t arena;
static void test(void)
{
mps_thr_t thread;
mps_pool_t pool;
log_event event;
int id;
char *c;
size_t size;
unsigned long maxcom;
maxcom = 0;
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)),
"create space");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_pool_create(&pool, arena, mps_class_mvff(),
EXTENDBY, AVGSIZE, ALIGN, ARENAHIGH, SLOTHIGH, FIRST),
"create MVFF pool");
committed = mps_arena_committed(arena);
while (read_event(&event)) {
if (event.type == EVENT_ALLOC) {
id = event.alloc.id;
asserts(id < MAXOBJS, "MAXOBJS too small");
size = event.alloc.size;
sizes[id] = size;
size = ((size+7)/8)*8;
die(mps_alloc(&objs[id], pool, size), "alloc");
if (mps_arena_committed(arena) > committed) {
fragmentation = (100*(committed-total_size)/committed);
if (fragmentation != lastfrag) {
lastfrag = fragmentation;
report("fragmentation", "%d", fragmentation);
}
}
total_size+=sizes[id];
c = objs[id];
*c = 43;
} else if (event.type == EVENT_FREE) {
id = event.free.id;
mps_free(pool, objs[id], sizes[id]);
total_size-=sizes[id];
}
committed = mps_arena_committed(arena);
if (committed > maxcom) maxcom=committed;
}
report("maxcom", "%ld", maxcom);
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

103
mps/qa/function/220.c Normal file
View file

@ -0,0 +1,103 @@
/*
TEST_HEADER
id = $HopeName$
summary = MVFF from af_six measuring fragmentation
language = c
link = testlib.o
stdin = af_six
parameters = ALIGN=8 AVGSIZE=128 EXTENDBY=65536 ARENAHIGH SLOTHIGH FIRSTFIT
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscmvff.h"
#include "mpsavm.h"
#define MAXOBJS (30000)
mps_addr_t objs[MAXOBJS];
size_t sizes[MAXOBJS];
size_t total_size;
size_t committed;
int fragmentation;
double fragacc;
double commacc;
double sizeacc;
double count;
void *stackpointer;
mps_arena_t arena;
static void test(void)
{
mps_thr_t thread;
mps_pool_t pool;
log_event event;
int id;
char *c;
size_t size;
unsigned long maxcom;
maxcom = 0;
fragacc = 0;
commacc = 0;
sizeacc = 0;
count = 0;
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)),
"create space");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_pool_create(&pool, arena, mps_class_mvff(),
EXTENDBY, AVGSIZE, ALIGN, ARENAHIGH, SLOTHIGH, FIRSTFIT),
"create MVFF pool");
committed = mps_arena_committed(arena);
while (read_event(&event)) {
if (event.type == EVENT_ALLOC) {
id = event.alloc.id;
asserts(id < MAXOBJS, "MAXOBJS too small");
size = event.alloc.size;
sizes[id] = size;
mps_alloc(&objs[id], pool, size);
total_size+=sizes[id];
c = objs[id];
*c = 43;
} else if (event.type == EVENT_FREE) {
id = event.free.id;
mps_free(pool, objs[id], sizes[id]);
total_size-=sizes[id];
}
committed = mps_arena_committed(arena);
if (committed > maxcom) maxcom=committed;
fragacc += ((double) (committed-total_size))/((double) committed);
commacc += (double) committed;
sizeacc += (double) total_size;
count += 1;
}
report("maxcom", "%ld", maxcom);
report("fragavg", "%f", fragacc/count);
report("fragweighted", "%f", (commacc-sizeacc)/commacc);
report("commavg", "%f", commacc/count);
report("sizeavg", "%f", sizeacc/count);
mps_pool_destroy(pool);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

162
mps/qa/function/221.c Normal file
View file

@ -0,0 +1,162 @@
/*
TEST_HEADER
id = $HopeName$
summary = MV2*3 from af_six measuring fragmentation
language = c
link = testlib.o
stdin = af_six
parameters = COMLIMIT=(1024*1024*100) MIN1=8 MIN2=256 MIN3=4096 MAX3=32768 LIMIT FRAGLIMIT
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscmv2.h"
#include "mpsavm.h"
#define MAXOBJS (30000)
mps_addr_t objs[MAXOBJS];
size_t sizes[MAXOBJS];
mps_pool_t pools[MAXOBJS];
size_t total_size;
size_t committed;
int fragmentation;
double fragacc;
double commacc;
double sizeacc;
double count;
void *stackpointer;
mps_arena_t arena;
static void test(void)
{
mps_thr_t thread;
mps_pool_t pool1, pool2, pool3;
mps_ap_t ap1, ap2, ap3, ap;
log_event event;
int id;
char *c;
size_t size;
unsigned long maxcom;
unsigned long depth1, depth2, depth3;
size_t avg1, avg2, avg3;
mps_res_t res;
maxcom = 0;
fragacc = 0;
commacc = 0;
sizeacc = 0;
count = 0;
avg1 = MIN1;
avg2 = MIN2;
avg3 = MIN3;
depth1 = LIMIT*2*(MIN2/avg1)*(100/FRAGLIMIT);
depth2 = LIMIT*2*(MIN3/avg2)*(100/FRAGLIMIT);
depth3 = LIMIT*2*(MAX3/avg3)*(100/FRAGLIMIT);
report("avg1", "%ld", avg1);
report("depth1", "%ld", depth1);
report("avg2", "%ld", avg2);
report("depth2", "%ld", depth2);
report("avg3", "%ld", avg3);
report("depth3", "%ld", depth3);
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)),
"create space");
cdie(mps_arena_commit_limit_set(arena, COMLIMIT), "commit limit");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_pool_create(&pool1, arena, mps_class_mv2(),
MIN1, avg1, MIN2,
depth1,
FRAGLIMIT),
"create MV2 pool (small)");
cdie(mps_ap_create(&ap1, pool1, MPS_RANK_AMBIG), "create ap (small)");
cdie(
mps_pool_create(&pool2, arena, mps_class_mv2(),
MIN2, avg2, MIN3,
depth2,
FRAGLIMIT),
"create MV2 pool (medium)");
cdie(mps_ap_create(&ap2, pool2, MPS_RANK_AMBIG), "create ap (medium)");
cdie(
mps_pool_create(&pool3, arena, mps_class_mv2(),
MIN3, avg3, MAX3,
depth3,
FRAGLIMIT),
"create MV2 pool (big)");
cdie(mps_ap_create(&ap3, pool3, MPS_RANK_AMBIG), "create ap (big)");
committed = mps_arena_committed(arena);
while (read_event(&event)) {
if (event.type == EVENT_ALLOC) {
id = event.alloc.id;
asserts(id < MAXOBJS, "MAXOBJS too small");
size = event.alloc.size;
sizes[id] = size;
size = ((size+7)/8)*8;
if (size < MIN2) {
ap = ap1;
pools[id] = pool1;
} else if (size < MIN3) {
ap = ap2;
pools[id] = pool2;
} else {
ap = ap3;
pools[id] = pool3;
}
do {
MPS_RESERVE_BLOCK(res, objs[id], ap, size);
asserts(res == MPS_RES_OK, "alloc failed");
} while (!mps_commit(ap, objs[id], size));
total_size+=sizes[id];
c = objs[id];
*c = 43;
} else if (event.type == EVENT_FREE) {
id = event.free.id;
mps_free(pools[id], objs[id], sizes[id]);
total_size-=sizes[id];
}
committed = mps_arena_committed(arena);
if (committed > maxcom) maxcom=committed;
fragacc += ((double) (committed-total_size))/((double) committed);
commacc += (double) committed;
sizeacc += (double) total_size;
count += 1;
}
report("maxcom", "%ld", maxcom);
report("fragavg", "%f", fragacc/count);
report("fragweighted", "%f", (commacc-sizeacc)/commacc);
report("commavg", "%f", commacc/count);
report("sizeavg", "%f", sizeacc/count);
mps_ap_destroy(ap1);
mps_ap_destroy(ap2);
mps_ap_destroy(ap3);
mps_pool_destroy(pool1);
mps_pool_destroy(pool2);
mps_pool_destroy(pool3);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}

134
mps/qa/function/222.c Normal file
View file

@ -0,0 +1,134 @@
/*
TEST_HEADER
id = $HopeName$
summary = EPDR*3 from af_six measuring fragmentation
language = c
link = testlib.o
stdin = af_six
parameters = COMLIMIT=(1024*1024*100) MIN1=8 MIN2=256 MIN3=4096 EXTENDBY=65536
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscepdl.h"
#include "mpsavm.h"
#define MAXOBJS (30000)
#define ALIGN 8
mps_addr_t objs[MAXOBJS];
size_t sizes[MAXOBJS];
mps_pool_t pools[MAXOBJS];
size_t total_size;
size_t committed;
int fragmentation;
double fragacc;
double commacc;
double sizeacc;
double count;
void *stackpointer;
mps_arena_t arena;
static void test(void)
{
mps_thr_t thread;
mps_pool_t pool1, pool2, pool3;
log_event event;
int id;
char *c;
size_t size;
unsigned long maxcom;
size_t avg1, avg2, avg3;
maxcom = 0;
fragacc = 0;
commacc = 0;
sizeacc = 0;
count = 0;
avg1 = 4*MIN1;
avg2 = 4*MIN2;
avg3 = 4*MIN3;
report("avg1", "%ld", avg1);
report("avg2", "%ld", avg2);
report("avg3", "%ld", avg3);
cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*100)),
"create space");
cdie(mps_arena_commit_limit_set(arena, COMLIMIT), "commit limit");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_pool_create(&pool1, arena, mps_class_epdr(),
EXTENDBY, avg1, ALIGN),
"create EPDR pool (small)");
cdie(
mps_pool_create(&pool2, arena, mps_class_epdr(),
EXTENDBY, avg2, ALIGN),
"create EPDR pool (medium)");
cdie(
mps_pool_create(&pool3, arena, mps_class_epdr(),
EXTENDBY, avg3, ALIGN),
"create EPDR pool (big)");
committed = mps_arena_committed(arena);
while (read_event(&event)) {
if (event.type == EVENT_ALLOC) {
id = event.alloc.id;
asserts(id < MAXOBJS, "MAXOBJS too small");
size = event.alloc.size;
sizes[id] = size;
if (size < MIN2) {
pools[id] = pool1;
} else if (size < MIN3) {
pools[id] = pool2;
} else {
pools[id] = pool3;
}
die(mps_alloc(&objs[id], pools[id], size), "alloc");
total_size+=sizes[id];
c = objs[id];
*c = 43;
} else if (event.type == EVENT_FREE) {
id = event.free.id;
mps_free(pools[id], objs[id], sizes[id]);
total_size-=sizes[id];
}
committed = mps_arena_committed(arena);
if (committed > maxcom) maxcom=committed;
fragacc += ((double) (committed-total_size))/((double) committed);
commacc += (double) committed;
sizeacc += (double) total_size;
count += 1;
}
report("maxcom", "%ld", maxcom);
report("fragavg", "%f", fragacc/count);
report("fragweighted", "%f", (commacc-sizeacc)/commacc);
report("commavg", "%f", commacc/count);
report("sizeavg", "%f", sizeacc/count);
mps_pool_destroy(pool1);
mps_pool_destroy(pool2);
mps_pool_destroy(pool3);
mps_thread_dereg(thread);
mps_arena_destroy(arena);
}
int main(void)
{
void *m;
stackpointer=&m; /* hack to get stack pointer */
easy_tramp(test);
pass();
return 0;
}