#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_realloc");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
int *test = vmem_realloc(vmp, NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = test_value;
UT_ASSERTeq(test[0], test_value);
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
test = vmem_realloc(vmp, test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], test_value);
test[1] = test_value;
test[9] = test_value;
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}