16f365c21d796310a9ea70d8420e6879eb5abb6aedavem// Copyright (c) 2007, Google Inc. 26f365c21d796310a9ea70d8420e6879eb5abb6aedavem// All rights reserved. 36f365c21d796310a9ea70d8420e6879eb5abb6aedavem// 4462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane// Redistribution and use in source and binary forms, with or without 5462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane// modification, are permitted provided that the following conditions are 6462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane// met: 76f365c21d796310a9ea70d8420e6879eb5abb6aedavem// 86f365c21d796310a9ea70d8420e6879eb5abb6aedavem// * Redistributions of source code must retain the above copyright 99f23a3a1bff6c8af93e651273c9887bbf119f555Ian Romanick// notice, this list of conditions and the following disclaimer. 106f365c21d796310a9ea70d8420e6879eb5abb6aedavem// * Redistributions in binary form must reproduce the above 116f365c21d796310a9ea70d8420e6879eb5abb6aedavem// copyright notice, this list of conditions and the following disclaimer 126f365c21d796310a9ea70d8420e6879eb5abb6aedavem// in the documentation and/or other materials provided with the 136f365c21d796310a9ea70d8420e6879eb5abb6aedavem// distribution. 146f365c21d796310a9ea70d8420e6879eb5abb6aedavem// * Neither the name of Google Inc. nor the names of its 156f365c21d796310a9ea70d8420e6879eb5abb6aedavem// contributors may be used to endorse or promote products derived from 166f365c21d796310a9ea70d8420e6879eb5abb6aedavem// this software without specific prior written permission. 176f365c21d796310a9ea70d8420e6879eb5abb6aedavem// 186f365c21d796310a9ea70d8420e6879eb5abb6aedavem// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 196f365c21d796310a9ea70d8420e6879eb5abb6aedavem// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 206f365c21d796310a9ea70d8420e6879eb5abb6aedavem// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 216f365c21d796310a9ea70d8420e6879eb5abb6aedavem// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 226f365c21d796310a9ea70d8420e6879eb5abb6aedavem// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 236f365c21d796310a9ea70d8420e6879eb5abb6aedavem// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 246f365c21d796310a9ea70d8420e6879eb5abb6aedavem// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 256f365c21d796310a9ea70d8420e6879eb5abb6aedavem// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 266f365c21d796310a9ea70d8420e6879eb5abb6aedavem// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 276f365c21d796310a9ea70d8420e6879eb5abb6aedavem// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 286f365c21d796310a9ea70d8420e6879eb5abb6aedavem// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 296f365c21d796310a9ea70d8420e6879eb5abb6aedavem 306f365c21d796310a9ea70d8420e6879eb5abb6aedavem// --- 316f365c21d796310a9ea70d8420e6879eb5abb6aedavem// Author: Craig Silverstein 326f365c21d796310a9ea70d8420e6879eb5abb6aedavem 336f365c21d796310a9ea70d8420e6879eb5abb6aedavem#ifndef TCMALLOC_TOOLS_TESTUTIL_H_ 346f365c21d796310a9ea70d8420e6879eb5abb6aedavem#define TCMALLOC_TOOLS_TESTUTIL_H_ 356f365c21d796310a9ea70d8420e6879eb5abb6aedavem 366f365c21d796310a9ea70d8420e6879eb5abb6aedavem// Run a function in a thread of its own and wait for it to finish. 376f365c21d796310a9ea70d8420e6879eb5abb6aedavem// The function you pass in must have the signature 386f365c21d796310a9ea70d8420e6879eb5abb6aedavem// void MyFunction(); 396f365c21d796310a9ea70d8420e6879eb5abb6aedavemextern "C" void RunThread(void (*fn)()); 406f365c21d796310a9ea70d8420e6879eb5abb6aedavem 416f365c21d796310a9ea70d8420e6879eb5abb6aedavem// Run a function X times, in X threads, and wait for them all to finish. 426f365c21d796310a9ea70d8420e6879eb5abb6aedavem// The function you pass in must have the signature 436f365c21d796310a9ea70d8420e6879eb5abb6aedavem// void MyFunction(); 446f365c21d796310a9ea70d8420e6879eb5abb6aedavemextern "C" void RunManyThreads(void (*fn)(), int count); 456f365c21d796310a9ea70d8420e6879eb5abb6aedavem 466f365c21d796310a9ea70d8420e6879eb5abb6aedavem// The 'advanced' version: run a function X times, in X threads, and 476f365c21d796310a9ea70d8420e6879eb5abb6aedavem// wait for them all to finish. Give them all the specified stack-size. 486f365c21d796310a9ea70d8420e6879eb5abb6aedavem// (If you're curious why this takes a stacksize and the others don't, 496f365c21d796310a9ea70d8420e6879eb5abb6aedavem// it's because the one client of this fn wanted to specify stacksize. :-) ) 506f365c21d796310a9ea70d8420e6879eb5abb6aedavem// The function you pass in must have the signature 516f365c21d796310a9ea70d8420e6879eb5abb6aedavem// void MyFunction(int idx); 526f365c21d796310a9ea70d8420e6879eb5abb6aedavem// where idx is the index of the thread (which of the X threads this is). 536f365c21d796310a9ea70d8420e6879eb5abb6aedavemextern "C" void RunManyThreadsWithId(void (*fn)(int), int count, int stacksize); 546f365c21d796310a9ea70d8420e6879eb5abb6aedavem 556f365c21d796310a9ea70d8420e6879eb5abb6aedavem// When compiled 64-bit and run on systems with swap several unittests will end 566f365c21d796310a9ea70d8420e6879eb5abb6aedavem// up trying to consume all of RAM+swap, and that can take quite some time. By 576f365c21d796310a9ea70d8420e6879eb5abb6aedavem// limiting the address-space size we get sufficient coverage without blowing 586f365c21d796310a9ea70d8420e6879eb5abb6aedavem// out job limits. 596f365c21d796310a9ea70d8420e6879eb5abb6aedavemvoid SetTestResourceLimit(); 606f365c21d796310a9ea70d8420e6879eb5abb6aedavem 616f365c21d796310a9ea70d8420e6879eb5abb6aedavem#endif // TCMALLOC_TOOLS_TESTUTIL_H_ 626f365c21d796310a9ea70d8420e6879eb5abb6aedavem