#include <getopt.h>
#include "unittest.h"
#include "jemalloc/internal/jemalloc_internal.h"
#include "jemalloc/internal/size_classes.h"
#define DEFAULT_COUNT (SMALL_MAXCLASS / 4)
#define DEFAULT_N 100
static void
usage(char *appname)
{
UT_FATAL("usage: %s <z - use calloc | \
n - do not use calloc> directory ", appname);
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
int count = DEFAULT_COUNT;
int n = DEFAULT_N;
VMEM *vmp;
int i, j;
int use_calloc = 0;
START(argc, argv, "vmem_pages_purging");
switch (argv[1][0]) {
case 'z':
use_calloc = 1;
break;
case 'n':
break;
default:
usage(argv[0]);
}
if (argv[2]) {
dir = argv[2];
} else {
usage(argv[0]);
}
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
for (i = 0; i < n; i++) {
int *test = NULL;
if (use_calloc)
test = vmem_calloc(vmp, 1, count * sizeof(int));
else
test = vmem_malloc(vmp, count * sizeof(int));
UT_ASSERTne(test, NULL);
if (use_calloc) {
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], 0);
}
for (j = 0; j < count; j++)
test[j] = test_value;
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], test_value);
vmem_free(vmp, test);
}
vmem_delete(vmp);
DONE(NULL);
}