Exemplo n.º 1
0
Arquivo: qalib.c Projeto: juddy/edcde
int
MODULE_ERR(Char *S)
{
   perror(S);
   if(fprintf(__Message_File, "*** Fatal Error ***  %s\n", S) < 0) {
     perror("MODULE_ERR: fprintf: ");
     DONE();
   }
   DONE();
   return 1;

}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_pool_lock");

	if (argc < 2)
		UT_FATAL("usage: %s path", argv[0]);

	if (argc == 2) {
		test_reopen(argv[1]);

		test_open_in_different_process(argc, argv, 0);
		for (int i = 1; i < 100000; i *= 2)
			test_open_in_different_process(argc, argv, i);
	} else if (argc == 3) {
		PMEMobjpool *pop;
		/* 2nd arg used by windows for 2 process test */
		pop = pmemobj_open(argv[1], LAYOUT);
		if (pop)
			UT_FATAL("pmemobj_open after create process should "
				"not succeed");

		if (errno != EWOULDBLOCK)
			UT_FATAL("!pmemobj_open after create process failed "
				"but for unexpected reason");
	}

	DONE(NULL);
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_poolset_parse");

	out_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
			MAJOR_VERSION, MINOR_VERSION);

	if (argc < 2)
		FATAL("usage: %s set-file-name ...", argv[0]);

	struct pool_set *set;
	int fd;

	for (int i = 1; i < argc; i++) {
		const char *path = argv[i];

		fd = OPEN(path, O_RDWR);

		int ret = util_poolset_parse(path, fd, &set);
		if (ret == 0)
			util_poolset_free(set);

		CLOSE(fd);
	}

	out_fini();

	DONE(NULL);
}
Exemplo n.º 4
0
void tagTab::updateCheckboxes()
{
	log(tr("Mise à jour des cases à cocher."));
	qDeleteAll(m_checkboxes);
	m_checkboxes.clear();
	QStringList urls = m_sites->keys();
	QSettings settings(savePath("settings.ini"), QSettings::IniFormat, this);
	int n = settings.value("Sources/Letters", 3).toInt(), m = n;
	for (int i = 0; i < urls.size(); i++)
	{
		if (urls[i].startsWith("www."))
		{ urls[i] = urls[i].right(urls[i].length() - 4); }
		else if (urls[i].startsWith("chan."))
		{ urls[i] = urls[i].right(urls[i].length() - 5); }
		if (n < 0)
		{
			m = urls.at(i).indexOf('.');
			if (n < -1 && urls.at(i).indexOf('.', m+1) != -1)
			{ m = urls.at(i).indexOf('.', m+1); }
		}

		bool isChecked = m_selectedSources.size() > i ? m_selectedSources.at(i) : false;
		QCheckBox *c = new QCheckBox(urls.at(i).left(m), this);
			c->setChecked(isChecked);
			ui->layoutSourcesList->addWidget(c);

		m_checkboxes.append(c);
	}
	DONE();
}
Exemplo n.º 5
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_map_proc");

	util_init();

	if (argc < 3)
		UT_FATAL("usage: %s maps_file len [len]...", argv[0]);

	Sfile = argv[1];

	for (int arg = 2; arg < argc; arg++) {
		size_t len = (size_t)strtoull(argv[arg], NULL, 0);

		size_t align = Ut_pagesize;
		if (len >= 2 * GIGABYTE)
			align = GIGABYTE;
		else if (len >= 4 * MEGABYTE)
			align = 2 * MEGABYTE;

		void *h1 =
			util_map_hint_unused((void *)TERABYTE, len, GIGABYTE);
		void *h2 = util_map_hint(len, 0);
		if (h1 != MAP_FAILED && h1 != NULL)
			UT_ASSERTeq((uintptr_t)h1 & (GIGABYTE - 1), 0);
		if (h2 != MAP_FAILED && h2 != NULL)
			UT_ASSERTeq((uintptr_t)h2 & (align - 1), 0);
		UT_OUT("len %zu: %p %p", len, h1, h2);
	}

	DONE(NULL);
}
Exemplo n.º 6
0
int
main(int argc, char *argv[])
{
	const int test_value = 123456;
	int count = DEFAULT_COUNT;
	int n = DEFAULT_N;
	int *ptr;
	int i, j;

	START(argc, argv, "vmmalloc_calloc");

	for (i = 0; i < n; i++) {
		ptr = calloc(1, count * sizeof(int));
		UT_ASSERTne(ptr, NULL);

		/* calloc should return zeroed memory */
		for (j = 0; j < count; j++)
			UT_ASSERTeq(ptr[j], 0);
		for (j = 0; j < count; j++)
			ptr[j] = test_value;
		for (j = 0; j < count; j++)
			UT_ASSERTeq(ptr[j], test_value);

		cfree(ptr);
	}

	DONE(NULL);
}
Exemplo n.º 7
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_out_of_memory");

	if (argc < 3)
		FATAL("usage: %s size filename ...", argv[0]);

	size_t size = atoll(argv[1]);

	for (int i = 2; i < argc; i++) {
		const char *path = argv[i];

		PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, 0,
					S_IWUSR | S_IRUSR);
		if (pop == NULL)
			FATAL("!pmemobj_create: %s", path);

		test_alloc(pop, size);

		pmemobj_close(pop);

		ASSERTeq(pmemobj_check(path, LAYOUT_NAME), 1);

		ASSERTne(pop = pmemobj_open(path, LAYOUT_NAME), NULL);

		test_free(pop);

		pmemobj_close(pop);
	}

	DONE(NULL);
}
Exemplo n.º 8
0
int
main(int argc, char *argv[])
{
	char *dir = NULL;
	void *mem_pool = NULL;
	VMEM *vmp;

	START(argc, argv, "vmem_check");

	if (argc == 2) {
		dir = argv[1];
	} else if (argc > 2) {
		FATAL("usage: %s [directory]", argv[0]);
	}

	if (dir == NULL) {
		/* allocate memory for function vmem_create_in_region() */
		mem_pool = MMAP(NULL, VMEM_MIN_POOL*2, PROT_READ|PROT_WRITE,
					MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);

		vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
		if (vmp == NULL)
			FATAL("!vmem_create_in_region");
	} else {
		vmp = vmem_create(dir, VMEM_MIN_POOL);
		if (vmp == NULL)
			FATAL("!vmem_create");
	}

	ASSERTeq(1, vmem_check(vmp));

	/* create pool in this same memory region */
	if (dir == NULL) {
		unsigned long Pagesize = (unsigned long) sysconf(_SC_PAGESIZE);
		void *mem_pool2 = (void *)(((uintptr_t)mem_pool +
			VMEM_MIN_POOL/2) & ~(Pagesize-1));

		VMEM *vmp2 = vmem_create_in_region(mem_pool2,
			VMEM_MIN_POOL);

		if (vmp2 == NULL)
			FATAL("!vmem_create_in_region");

		/* detect memory range collision */
		ASSERTne(1, vmem_check(vmp));
		ASSERTne(1, vmem_check(vmp2));

		vmem_delete(vmp2);

		ASSERTne(1, vmem_check(vmp2));
	}

	vmem_delete(vmp);

	/* for vmem_create() memory unmapped after delete pool */
	if (!dir)
		ASSERTne(1, vmem_check(vmp));

	DONE(NULL);
}
Exemplo n.º 9
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_file_create");

	if (argc < 3)
		UT_FATAL("usage: %s minlen len:path...", argv[0]);

	char *fname;
	size_t minsize = strtoul(argv[1], &fname, 0);

	for (int arg = 2; arg < argc; arg++) {
		size_t size = strtoul(argv[arg], &fname, 0);
		if (*fname != ':')
			UT_FATAL("usage: %s minlen len:path...", argv[0]);
		fname++;

		int fd;
		if ((fd = util_file_create(fname, size, minsize)) == -1)
			UT_OUT("!%s: util_file_create", fname);
		else {
			UT_OUT("%s: created", fname);
			close(fd);
		}
	}

	DONE(NULL);
}
Exemplo n.º 10
0
/*
 * pool_test -- test pool
 *
 * This function creates a memory pool in a file (if dir is not NULL),
 * or in RAM (if dir is NULL) and allocates memory for the test.
 */
void
pool_test(const char *dir)
{
	VMEM *vmp = NULL;

	if (dir != NULL) {
		vmp = vmem_pool_create(dir, VMEM_MIN_POOL);
	} else {
		vmp = vmem_pool_create_in_region(mem_pool, VMEM_MIN_POOL);
	}

	if (expect_create_pool == 0) {
		ASSERTeq(vmp, NULL);
		DONE(NULL);
	} else {
		if (vmp == NULL) {
			if (dir == NULL) {
				FATAL("!vmem_pool_create_in_region");
			} else {
				FATAL("!vmem_pool_create");
			}
		}
	}

	char *test = vmem_malloc(vmp, strlen(TEST_STRING_VALUE) + 1);
	ASSERTne(test, NULL);

	strcpy(test, TEST_STRING_VALUE);
	ASSERTeq(strcmp(test, TEST_STRING_VALUE), 0);

	vmem_free(vmp, test);

	vmem_pool_delete(vmp);
}
Exemplo n.º 11
0
int
main(int argc, char *argv[])
{
	VMEM *vmp;

	START(argc, argv, "vmem_create_error");

	if (argc > 1)
		UT_FATAL("usage: %s", argv[0]);

	errno = 0;
	vmp = vmem_create_in_region(mem_pool, 0);
	UT_ASSERTeq(vmp, NULL);
	UT_ASSERTeq(errno, EINVAL);

	errno = 0;
	vmp = vmem_create("./", 0);
	UT_ASSERTeq(vmp, NULL);
	UT_ASSERTeq(errno, EINVAL);

	errno = 0;
	vmp = vmem_create("invalid dir !@#$%^&*()=", VMEM_MIN_POOL);
	UT_ASSERTeq(vmp, NULL);
	UT_ASSERTne(errno, 0);

	DONE(NULL);
}
Exemplo n.º 12
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_pool");

	if (argc < 4)
		UT_FATAL("usage: %s op path layout [poolsize mode]", argv[0]);

	char *layout = NULL;
	size_t poolsize;
	unsigned mode;

	if (strcmp(argv[3], "EMPTY") == 0)
		layout = "";
	else if (strcmp(argv[3], "NULL") != 0)
		layout = argv[3];

	switch (argv[1][0]) {
	case 'c':
		poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
		mode = strtoul(argv[5], NULL, 8);

		pool_create(argv[2], layout, poolsize, mode);
		break;

	case 'o':
		pool_open(argv[2], layout);
		break;

	default:
		UT_FATAL("unknown operation");
	}

	DONE(NULL);
}
Exemplo n.º 13
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "win_mmap");

	if (argc !=  2)
		UT_FATAL("usage: %s file", argv[0]);

	int fd = OPEN(argv[1], O_RDWR);
	int fd_ro = OPEN(argv[1], O_RDONLY);

	POSIX_FALLOCATE(fd, 0, FILE_SIZE);

	test_mmap_flags(fd);
	test_mmap_len(fd);
	test_mmap_hint(fd);
	test_mmap_fixed(fd);
	test_mmap_anon(fd);
	test_mmap_shared(fd);
	test_mmap_prot(fd, fd_ro);
	test_mmap_prot_anon();
	test_munmap(fd);
	test_msync(fd);
	test_mprotect(fd, fd_ro);
	test_mprotect_anon();

	CLOSE(fd_ro);
	CLOSE(fd);

	DONE(NULL);
}
Exemplo n.º 14
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_cpp_cond_var");

	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	nvobj::pool<struct root> pop;

	try {
		pop = nvobj::pool<struct root>::create(
			path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);
	} catch (pmem::pool_error &pe) {
		UT_FATAL("!pool::create: %s %s", pe.what(), path);
	}

	cond_zero_test(pop);

	std::vector<reader_type> notify_functions(
		{reader_mutex, reader_mutex_pred, reader_lock, reader_lock_pred,
		 reader_mutex_until, reader_mutex_until_pred, reader_lock_until,
		 reader_lock_until_pred, reader_mutex_for,
		 reader_mutex_for_pred, reader_lock_for, reader_lock_for_pred});

	for (auto func : notify_functions) {
		int reset_value = 42;

		mutex_test(pop, true, false, write_notify, func);
		pop.get_root()->counter = reset_value;

		mutex_test(pop, true, true, write_notify, func);
		pop.get_root()->counter = reset_value;
	}

	std::vector<reader_type> not_notify_functions(
		{reader_mutex_until, reader_mutex_until_pred, reader_lock_until,
		 reader_lock_until_pred, reader_mutex_for,
		 reader_mutex_for_pred, reader_lock_for, reader_lock_for_pred});

	for (auto func : not_notify_functions) {
		int reset_value = 42;

		mutex_test(pop, false, false, write_notify, func);
		pop.get_root()->counter = reset_value;

		mutex_test(pop, false, true, write_notify, func);
		pop.get_root()->counter = reset_value;
	}

	/* pmemcheck related persist */
	pmemobj_persist(pop.get_handle(), &(pop.get_root()->counter),
			sizeof(pop.get_root()->counter));

	pop.close();

	DONE(nullptr);
}
Exemplo n.º 15
0
int
main(int argc, char *argv[])
{
    START(argc, argv, "obj_check");
    if (argc < 2) {
        UT_FATAL("usage: obj_check file");
    }

    const char *path = argv[1];

    int ret = pmemobj_check(path, NULL);

    switch (ret) {
    case 1:
        UT_OUT("consistent");
        break;
    case 0:
        UT_OUT("not consistent: %s", pmemobj_errormsg());
        break;
    default:
        UT_OUT("error: %s", pmemobj_errormsg());
        break;
    }

    DONE(NULL);
}
Exemplo n.º 16
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_pmalloc_oom_mt");

	if (argc != 2)
		FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	if ((pop = pmemobj_create(path, LAYOUT_NAME,
			PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
		FATAL("!pmemobj_create: %s", path);

	pthread_t t;
	pthread_create(&t, NULL, oom_worker, NULL);
	pthread_join(t, NULL);

	int first_thread_allocated = allocated;

	pthread_create(&t, NULL, oom_worker, NULL);
	pthread_join(t, NULL);

	ASSERTeq(first_thread_allocated, allocated);

	pmemobj_close(pop);

	DONE(NULL);
}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
	int fd;
	char *dest;
	char *src;
	struct stat stbuf;

	START(argc, argv, "pmem_memcpy");

	if (argc != 5)
		FATAL("usage: %s file srcoff destoff length", argv[0]);

	fd = OPEN(argv[1], O_RDWR);
	int dest_off = atoi(argv[2]);
	int src_off = atoi(argv[3]);
	size_t bytes = strtoul(argv[4], NULL, 0);

	FSTAT(fd, &stbuf);

	/* src > dst */
	dest = pmem_map(fd);
	if (dest == NULL)
		FATAL("!could not map file: %s", argv[1]);

	src = MMAP(dest + stbuf.st_size, stbuf.st_size, PROT_READ|PROT_WRITE,
		MAP_SHARED|MAP_ANONYMOUS, -1, 0);
	/*
	 * Its very unlikely that src would not be > dest. pmem_map
	 * chooses the first unused address >= 1TB, large
	 * enough to hold the give range, and 1GB aligned. If the
	 * addresses did not get swapped to allow src > dst, log error
	 * and allow test to continue.
	 */
	if (src <= dest) {
		swap_mappings(&dest, &src, stbuf.st_size, fd);
		if (src <= dest)
			ERR("cannot map files in memory order");
	}

	memset(dest, 0, (2 * bytes));
	memset(src, 0, (2 * bytes));

	do_memcpy(fd, dest, dest_off, src, src_off, bytes, argv[1]);

	/* dest > src */
	swap_mappings(&dest, &src, stbuf.st_size, fd);

	if (dest <= src) {
		ERR("cannot map files in memory order");
	}

	do_memcpy(fd, dest, dest_off, src, src_off, bytes, argv[1]);
	MUNMAP(dest, stbuf.st_size);
	MUNMAP(src, stbuf.st_size);

	CLOSE(fd);

	DONE(NULL);
}
Exemplo n.º 18
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_cpp_ptr_arith");

	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	nvobj::pool_base pop;

	try {
		pop = nvobj::pool_base::create(path, LAYOUT, PMEMOBJ_MIN_POOL,
					       S_IWUSR | S_IRUSR);
	} catch (nvml::pool_error &pe) {
		UT_FATAL("!pool::create: %s %s", pe.what(), path);
	}

	test_arith(pop);
	test_relational(pop);

	pop.close();

	DONE(NULL);
}
Exemplo n.º 19
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_tx_mt");

	if (argc != 2)
		UT_FATAL("usage: %s [file]", argv[0]);

	if ((pop = pmemobj_create(argv[1], "mt", PMEMOBJ_MIN_POOL,
			S_IWUSR | S_IRUSR)) == NULL)
		UT_FATAL("!pmemobj_create");

	int i = 0;
	long ncpus = sysconf(_SC_NPROCESSORS_ONLN);
	pthread_t *threads = MALLOC(2 * ncpus * sizeof(threads[0]));

	for (int j = 0; j < ncpus; ++j) {
		PTHREAD_CREATE(&threads[i++], NULL, tx_alloc_free, NULL);
		PTHREAD_CREATE(&threads[i++], NULL, tx_snap, NULL);
	}

	while (i > 0)
		PTHREAD_JOIN(threads[--i], NULL);

	pmemobj_close(pop);

	FREE(threads);

	DONE(NULL);
}
Exemplo n.º 20
0
int main(
    int argc,
    char **argv)
{
    struct Certificate cert;
    Certificate(&cert, (ushort) 0);
    if (argc < 3)
        FATAL(MSG_USAGE);
    if (get_casn_file(&cert.self, argv[1], 0) <= 0)
        FATAL(MSG_OPEN, argv[1]);
    struct RelativeDistinguishedName *rdnp =
        (struct RelativeDistinguishedName *)member_casn(&cert.toBeSigned.
                                                        subject.rDNSequence.
                                                        self, 0);
    struct AttributeValueAssertion *avap =
        (struct AttributeValueAssertion *)member_casn(&rdnp->self, 0);
    if (write_casn
        (&avap->value.commonName.printableString, (uchar *) argv[2],
         strlen(argv[2])) < 0)
        FATAL(MSG_WRITING, "name");
    if (put_casn_file(&cert.self, argv[1], 0) < 0)
        FATAL(MSG_WRITING, argv[1]);
    DONE(MSG_OK, argv[1]);
    return 0;
}
Exemplo n.º 21
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_cpp_make_persistent_atomic");

	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	nvobj::pool<struct root> pop;

	try {
		pop = nvobj::pool<struct root>::create(
			path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);
	} catch (nvml::pool_error &pe) {
		UT_FATAL("!pool::create: %s %s", pe.what(), path);
	}

	test_make_no_args(pop);
	test_make_args(pop);
	test_delete_null(pop);

	pop.close();

	DONE(NULL);
}
Exemplo n.º 22
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_heap_state");

	if (argc != 2)
		FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	PMEMobjpool *pop = NULL;

	if ((pop = pmemobj_create(path, LAYOUT_NAME,
			PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
		FATAL("!pmemobj_create: %s", path);

	pmemobj_root(pop, ROOT_SIZE); /* just to trigger allocation */

	pmemobj_close(pop);

	pop = pmemobj_open(path, LAYOUT_NAME);
	ASSERTne(pop, NULL);

	for (int i = 0; i < ALLOCS; ++i) {
		PMEMoid oid;
		pmemobj_alloc(pop, &oid, ALLOC_SIZE, 0, NULL, NULL);
		OUT("%d %lu", i, oid.off);
	}

	pmemobj_close(pop);

	DONE(NULL);
}
Exemplo n.º 23
0
int
main(int argc, char *argv[])
{
    START(argc, argv, "vmmalloc_out_of_memory");

    /* allocate all memory */
    void *prev = NULL;
    for (;;) {
        void **next = malloc(sizeof (void *));
        if (next == NULL) {
            /* out of memory */
            break;
        }

        *next = prev;
        prev = next;
    }

    ASSERTne(prev, NULL);

    /* free all allocations */
    while (prev != NULL) {
        void **act = prev;
        prev = *act;
        free(act);
    }

    DONE(NULL);
}
Exemplo n.º 24
0
int
main(int argc, char *argv[])
{
	char *pool_desc, *log_file;
	char root_dir[PATH_MAX];

	START(argc, argv, "rpmemd_db");

	if (argc != 4)
		UT_FATAL("usage: %s <root_dir> <pool_desc> <log-file>",
				argv[0]);

	if (realpath(argv[1], root_dir) == NULL)
		UT_FATAL("!realpath(%s)", argv[1]);

	pool_desc = argv[2];
	log_file = argv[3];

	if (rpmemd_log_init("rpmemd error: ", log_file, 0))
		FAILED_FUNC("rpmemd_log_init");

	test_init(root_dir);
	test_check_dir(root_dir);
	test_create(root_dir, pool_desc);
	test_open(root_dir, pool_desc);

	rpmemd_log_close();

	DONE(NULL);
}
Exemplo n.º 25
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_pool");

	if (argc < 4)
		UT_FATAL("usage: %s op path bsize [poolsize mode]", argv[0]);

	size_t bsize = strtoul(argv[3], NULL, 0);
	size_t poolsize;
	unsigned mode;

	switch (argv[1][0]) {
	case 'c':
		poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
		mode = strtoul(argv[5], NULL, 8);

		pool_create(argv[2], bsize, poolsize, mode);
		break;

	case 'o':
		pool_open(argv[2], bsize);
		break;

	default:
		UT_FATAL("unknown operation");
	}

	DONE(NULL);
}
Exemplo n.º 26
0
void receive_output () {
	int i;
	Head = init_node ();

	/* Allocating space in buffer structure to hold names of incoming connections */
	gRxUInfo.userid = (char *) malloc (20);

	while (!all_done()) {
		for (i = 1; i < 10; i++) {
			if (IS_DONE(i)) continue;

			MPI_Recv (output, 50, MPI_UNSIGNED_CHAR, i, 0, MPI_COMM_WORLD, &status);

			if (!output[0]) {
				DONE(i);
				continue;
			}

			Count++;

			sscanf (output, "%s %d %d", gRxUInfo.userid, &gRxUInfo.followers, &gRxUInfo.following);

			Head = insert (Head, name = gRxUInfo.userid, GATHER);
		}
	}

}
int
main(int argc, char *argv[])
{
	VMEM *vmp;
	size_t i;

	START(argc, argv, "vmem_pool_create_in_region");

	if (argc > 1)
		FATAL("usage: %s", argv[0]);

	vmp = vmem_pool_create_in_region(mem_pool, VMEM_MIN_POOL);

	if (vmp == NULL)
		FATAL("!vmem_pool_create_in_region");

	for (i = 0; i < TEST_ALLOCATIONS; ++i) {
		allocs[i] = vmem_malloc(vmp, sizeof (int));

		ASSERTne(allocs[i], NULL);

		/* check that pointer came from mem_pool */
		ASSERTrange(allocs[i], mem_pool, VMEM_MIN_POOL);
	}

	for (i = 0; i < TEST_ALLOCATIONS; ++i) {
		vmem_free(vmp, allocs[i]);
	}

	vmem_pool_delete(vmp);

	DONE(NULL);
}
Exemplo n.º 28
0
int
main(int argc, char *argv[])
{
	int expect_custom_alloc = 0;

	START(argc, argv, "vmem_custom_alloc");

	if (argc < 2 || argc > 3 || strlen(argv[1]) != 1)
		FATAL("usage: %s (0-2) [directory]", argv[0]);

	switch (argv[1][0]) {
		case '0': {
			/* use default allocator */
			expect_custom_alloc = 0;
			expect_create_pool = 1;
			break;
		}
		case '1': {
			/* error in custom malloc function */
			expect_custom_alloc = 1;
			expect_create_pool = 0;
			vmem_set_funcs(malloc_null, free_custom,
				realloc_custom, strdup_custom, NULL);
			break;
		}
		case '2': {
			/* use custom alloc functions */
			expect_custom_alloc = 1;
			expect_create_pool = 1;
			vmem_set_funcs(malloc_custom, free_custom,
				realloc_custom, strdup_custom, NULL);
			break;
		}
		default: {
			FATAL("usage: %s (0-2) [directory]", argv[0]);
			break;
		}
	}

	if (argc == 3) {
		pool_test(argv[2]);
	} else {
		int i;
		/* repeat create pool */
		for (i = 0; i < TEST_REPEAT_CREATE_POOLS; ++i)
			pool_test(NULL);
	}

	/* check memory leak in custom allocator */
	ASSERTeq(custom_allocs, 0);

	if (expect_custom_alloc == 0) {
		ASSERTeq(custom_alloc_calls, 0);
	} else {
		ASSERTne(custom_alloc_calls, 0);
	}

	DONE(NULL);
}
Exemplo n.º 29
0
static void
test_detect()
{
	struct memory_block mhuge_used = { .chunk_id = 0, 0, 0, 0 };
	struct memory_block mhuge_free = { .chunk_id = 1, 0, 0, 0 };
	struct memory_block mrun = { .chunk_id = 2, 0, 0, 0 };

	pop->hlayout->zone0.chunk_headers[0].size_idx = 1;
	pop->hlayout->zone0.chunk_headers[0].type = CHUNK_TYPE_USED;

	pop->hlayout->zone0.chunk_headers[1].size_idx = 1;
	pop->hlayout->zone0.chunk_headers[1].type = CHUNK_TYPE_FREE;

	pop->hlayout->zone0.chunk_headers[2].size_idx = 1;
	pop->hlayout->zone0.chunk_headers[2].type = CHUNK_TYPE_RUN;

	UT_ASSERTeq(memblock_autodetect_type(&mhuge_used, pop->hlayout),
		MEMORY_BLOCK_HUGE);
	UT_ASSERTeq(memblock_autodetect_type(&mhuge_free, pop->hlayout),
		MEMORY_BLOCK_HUGE);
	UT_ASSERTeq(memblock_autodetect_type(&mrun, pop->hlayout),
		MEMORY_BLOCK_RUN);
}

static void
test_block_size()
{
	struct memory_block mhuge = { .chunk_id = 0, 0, 0, 0 };
	struct memory_block mrun = { .chunk_id = 1, 0, 0, 0 };
	pop->hlayout->zone0.chunk_headers[0].size_idx = 1;
	pop->hlayout->zone0.chunk_headers[0].type = CHUNK_TYPE_USED;

	pop->hlayout->zone0.chunk_headers[1].size_idx = 1;
	pop->hlayout->zone0.chunk_headers[1].type = CHUNK_TYPE_RUN;
	struct chunk_run *run = (struct chunk_run *)
		&pop->hlayout->zone0.chunks[1];
	run->block_size = 1234;

	UT_ASSERTeq(MEMBLOCK_OPS(, &mhuge)->block_size(&mhuge, pop->hlayout),
		CHUNKSIZE);
	UT_ASSERTeq(MEMBLOCK_OPS(, &mrun)->block_size(&mrun, pop->hlayout),
		1234);
}

int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_memblock");
	PMEMobjpool pool;
	pop = &pool;

	pop->hlayout = ZALLOC(sizeof(struct heap_layout) +
		NCHUNKS * sizeof(struct chunk));

	test_detect();
	test_block_size();

	DONE(NULL);
}
Exemplo n.º 30
0
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 opt;
	int i, j;
	int use_calloc = 0;

	START(argc, argv, "vmem_pages_purging");

	while ((opt = getopt(argc, argv, "z")) != -1) {
		switch (opt) {
		case 'z':
			use_calloc = 1;
			break;
		default:
			usage(argv[0]);
		}
	}

	if (optind < argc) {
		dir = argv[optind];
	} else {
		usage(argv[0]);
	}

	vmp = vmem_create(dir, VMEM_MIN_POOL);
	if (vmp == NULL)
		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));
		ASSERTne(test, NULL);

		if (use_calloc) {
			/* vmem_calloc should return zeroed memory */
			for (j = 0; j < count; j++)
				ASSERTeq(test[j], 0);
		}
		for (j = 0; j < count; j++)
			test[j] = test_value;
		for (j = 0; j < count; j++)
			ASSERTeq(test[j], test_value);

		vmem_free(vmp, test);
	}

	vmem_delete(vmp);

	DONE(NULL);
}