2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:18:54 +00:00
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
2007-10-16 14:18:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-04-16 23:58:56 -04:00
|
|
|
|
2007-10-16 14:18:02 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "mempool.h"
|
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
static void
|
|
|
|
test_mempool_limits (size_t size) {
|
2013-04-16 23:57:33 -04:00
|
|
|
void *base = toku_malloc(size);
|
2007-10-16 14:18:02 +00:00
|
|
|
struct mempool mempool;
|
2008-05-08 21:01:17 +00:00
|
|
|
toku_mempool_init(&mempool, base, size);
|
2007-10-16 14:18:02 +00:00
|
|
|
|
2013-04-16 23:57:18 -04:00
|
|
|
size_t i;
|
2007-10-16 14:18:02 +00:00
|
|
|
for (i=0;; i++) {
|
2008-05-08 21:01:17 +00:00
|
|
|
void *vp = toku_mempool_malloc(&mempool, 1, 1);
|
2007-10-16 14:18:02 +00:00
|
|
|
if (vp == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(i == size);
|
|
|
|
|
2008-05-08 21:01:17 +00:00
|
|
|
toku_mempool_fini(&mempool);
|
2013-04-16 23:57:33 -04:00
|
|
|
toku_free(base);
|
2007-10-16 14:18:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
static void
|
|
|
|
test_mempool_malloc_mfree (size_t size) {
|
2013-04-16 23:57:33 -04:00
|
|
|
void *base = toku_malloc(size);
|
2007-10-16 14:18:02 +00:00
|
|
|
struct mempool mempool;
|
2008-05-08 21:01:17 +00:00
|
|
|
toku_mempool_init(&mempool, base, size);
|
2007-10-16 14:18:02 +00:00
|
|
|
|
|
|
|
void *vp[size];
|
2013-04-16 23:57:18 -04:00
|
|
|
size_t i;
|
2007-10-16 14:18:02 +00:00
|
|
|
for (i=0;; i++) {
|
2013-04-16 23:57:28 -04:00
|
|
|
void *tp = toku_mempool_malloc(&mempool, 1, 1);
|
|
|
|
if (tp == 0)
|
2007-10-16 14:18:02 +00:00
|
|
|
break;
|
2013-04-16 23:57:28 -04:00
|
|
|
assert(i < size);
|
|
|
|
vp[i] = tp;
|
2007-10-16 14:18:02 +00:00
|
|
|
}
|
|
|
|
assert(i == size);
|
|
|
|
|
|
|
|
for (i=0; i<size; i++)
|
2008-05-08 21:01:17 +00:00
|
|
|
toku_mempool_mfree(&mempool, vp[i], 1);
|
|
|
|
assert(toku_mempool_get_frag_size(&mempool) == size);
|
2007-10-16 14:18:02 +00:00
|
|
|
|
2008-05-08 21:01:17 +00:00
|
|
|
toku_mempool_fini(&mempool);
|
2013-04-16 23:57:33 -04:00
|
|
|
toku_free(base);
|
2007-10-16 14:18:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
int
|
|
|
|
test_main(int argc, const char *argv[]) {
|
|
|
|
default_parse_args(argc, argv);
|
2007-10-16 14:18:02 +00:00
|
|
|
test_mempool_limits(0);
|
|
|
|
test_mempool_limits(256);
|
|
|
|
test_mempool_malloc_mfree(0);
|
|
|
|
test_mempool_malloc_mfree(256);
|
|
|
|
return 0;
|
|
|
|
}
|