/* mv2test.c: POOLMVT STRESS TEST * * $Id$ * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. */ #include #include #include "mpstd.h" #include #include "mpscmvt.h" #include "mps.h" typedef mps_word_t mps_count_t; /* machine word (target dep.) */ #include "mpslib.h" #include "mpsavm.h" #include "testlib.h" #include /* expdev() -- exponentially distributed random deviates * * From * * Returns an exponentially distributed, positive, random deviate of * unit mean, using rnd_double() as the source of uniform deviates. */ static double expdev(void) { double dum; do dum=rnd_double(); while (dum == 0.0); return (float)-log(dum); } static size_t size_min; static size_t size_mean; static size_t size_max; static int verbose = 0; static mps_pool_t pool; static size_t randomSize(unsigned long i) { /* Distribution centered on mean. Verify that allocations below min and above max are handled correctly */ size_t s = (size_max - size_mean)/4; size_t m = size_mean; double r; double x; testlib_unused(i); /* per SGR */ do { r = expdev(); x = (double)s * sqrt(2 * r); x += (double)m; } while (x <= 1.0); return (size_t)x; } #define testArenaSIZE ((size_t)64<<20) #define TEST_SET_SIZE 1234 #define TEST_LOOPS 27 static mps_res_t make(mps_addr_t *p, mps_ap_t ap, size_t size) { mps_res_t res; size = alignUp(size, MPS_PF_ALIGN); do { MPS_RESERVE_BLOCK(res, *p, ap, size); if(res != MPS_RES_OK) return res; } while(!mps_commit(ap, *p, size)); return MPS_RES_OK; } static mps_res_t stress(mps_class_t class, mps_arena_t arena, size_t (*size)(unsigned long i), mps_arg_s args[]) { mps_res_t res; mps_ap_t ap; unsigned long i, k; int *ps[TEST_SET_SIZE]; size_t ss[TEST_SET_SIZE]; res = mps_pool_create_k(&pool, arena, class, args); if(res != MPS_RES_OK) return res; die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate"); /* allocate a load of objects */ for(i=0; i 0) { mps_free(pool, (mps_addr_t)ps[i], ss[i]); ss[i] = 0; } } /* allocate some new objects */ for(i=x; i. * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Redistributions in any form must be accompanied by information on how * to obtain complete source code for this software and any accompanying * software that uses this software. The source code must either be * included in the distribution or be available for no more than the cost * of distribution plus a nominal fee, and must be freely redistributable * under reasonable conditions. For an executable file, complete source * code means the source code for all modules it contains. It does not * include source code for modules or files that typically accompany the * major components of the operating system on which the executable file * runs. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */