/* impl.c.mpmss: MPM STRESS TEST * * $Id$ * Copyright (c) 2001 Ravenbrook Limited. */ #include "mpscmv.h" #include "mpslib.h" #include "mpsavm.h" #include "testlib.h" #include "mps.h" #include #include /* @@@@ Hack due to missing mpscmfs.h */ extern mps_class_t PoolClassMFS(void); #define testArenaSIZE ((((size_t)64)<<20) - 4) #define smallArenaSIZE ((((size_t)1)<<20) - 4) #define testSetSIZE 200 #define testLOOPS 10 static mps_res_t stress(mps_class_t class, mps_arena_t arena, size_t (*size)(int i), ...) { mps_res_t res; mps_pool_t pool; va_list arg; int i, k; int *ps[testSetSIZE]; size_t ss[testSetSIZE]; va_start(arg, size); res = mps_pool_create_v(&pool, arena, class, arg); va_end(arg); if (res != MPS_RES_OK) return res; /* allocate a load of objects */ for (i=0; i= sizeof(ps[i])) *ps[i] = 1; /* Write something, so it gets swap. */ } mps_pool_check_fenceposts(pool); for (k=0; k (b)) ? (a) : (b)) static size_t randomSize(int i) { /* Make the range large enough to span three pages in the segment table: */ /* 160 segments/page, page size max 0x2000. */ size_t maxSize = 2 * 160 * 0x2000; /* Reduce by a factor of 2 every 10 cycles. Total allocation about 40 MB. */ return rnd() % max((maxSize >> (i / 10)), 2) + 1; } static size_t fixedSizeSize = 0; static size_t fixedSize(int i) { testlib_unused(i); return fixedSizeSize; } static mps_pool_debug_option_s debugOptions = { (void *)"postpost", 8 }; static int testInArena(mps_arena_t arena) { printf("MV debug\n"); die(stress(mps_class_mv_debug(), arena, randomSize, &debugOptions, (size_t)65536, (size_t)32, (size_t)65536), "stress MV debug"); printf("MFS\n"); fixedSizeSize = 13; die(stress(PoolClassMFS(), arena, fixedSize, (size_t)100000, fixedSizeSize), "stress MFS"); printf("MV\n"); die(stress(mps_class_mv(), arena, randomSize, (size_t)65536, (size_t)32, (size_t)65536), "stress MV"); return 0; } int main(int argc, char **argv) { mps_arena_t arena; randomize(argc, argv); die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE), "mps_arena_create"); testInArena(arena); mps_arena_destroy(arena); die(mps_arena_create(&arena, mps_arena_class_vm(), smallArenaSIZE), "mps_arena_create"); testInArena(arena); mps_arena_destroy(arena); fflush(stdout); /* synchronize */ fprintf(stderr, "\nConclusion: Failed to find any defects.\n"); return 0; }