21 #include <unordered_map> 25 namespace base_internal {
30 #define TEST_ASSERT(x) \ 32 printf("TEST_ASSERT(%s) FAILED ON LINE %d\n", #x, __LINE__); \ 45 static void CheckBlockDesc(
const BlockDesc &d) {
46 for (
int i = 0;
i != d.len;
i++) {
53 static void RandomizeBlockDesc(BlockDesc *d) {
54 d->fill = rand() & 0xff;
55 for (
int i = 0;
i != d->len;
i++) {
56 d->ptr[
i] = (d->fill +
i) & 0xff;
62 static bool using_low_level_alloc =
false;
76 static void Test(
bool use_new_arena,
bool call_malloc_hook,
int n) {
77 typedef std::unordered_map<int, BlockDesc> AllocMap;
79 AllocMap::iterator it;
82 LowLevelAlloc::Arena *
arena = 0;
87 for (
int i = 0;
i !=
n;
i++) {
88 if (
i != 0 &&
i % 10000 == 0) {
95 using_low_level_alloc =
true;
96 block_desc.len = rand() & 0x3fff;
98 reinterpret_cast<char *
>(
102 using_low_level_alloc =
false;
103 RandomizeBlockDesc(&block_desc);
105 it = allocated.find(rnd);
106 if (it != allocated.end()) {
107 CheckBlockDesc(it->second);
108 using_low_level_alloc =
true;
110 using_low_level_alloc =
false;
111 it->second = block_desc;
113 allocated[rnd] = block_desc;
117 it = allocated.begin();
118 if (it != allocated.end()) {
119 CheckBlockDesc(it->second);
120 using_low_level_alloc =
true;
122 using_low_level_alloc =
false;
129 while ((it = allocated.begin()) != allocated.end()) {
130 CheckBlockDesc(it->second);
131 using_low_level_alloc =
true;
133 using_low_level_alloc =
false;
142 static struct BeforeMain {
144 Test(
false,
false, 50000);
145 Test(
true,
false, 50000);
146 Test(
true,
true, 50000);
154 int main(
int argc,
char *argv[]) {
int main(int argc, char *argv[])
static void * Alloc(size_t request) ABSL_ATTRIBUTE_SECTION(malloc_hook)
LowLevelAlloc::Arena * arena
static void Free(void *s) ABSL_ATTRIBUTE_SECTION(malloc_hook)
static void * AllocWithArena(size_t request, Arena *arena) ABSL_ATTRIBUTE_SECTION(malloc_hook)
static Arena * NewArena(int32_t flags)
static bool DeleteArena(Arena *arena)