Пример #1
0
static void malloc_func(void** state) {
	size_t pool_size = 0x40000;
/*
	void* malloc_pool = malloc(pool_size);
	init_memory_pool(pool_size, malloc_pool, 0);
	
	size_t mem_size = 0x3e000;
	void* mem = __malloc(mem_size, malloc_pool);
	assert_in_range(mem, malloc_pool, malloc_pool + pool_size);	

	printf("extra malloc\n");
	void* mem2 = __malloc(1800, malloc_pool);
	assert_in_range(mem2, malloc_pool, malloc_pool + pool_size);	

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;

	return;
*/

	/*
	 * 0x3e000 is max size that won't make failure of malloc
	 * when pool size is set to 0x4000
	 * If malloc size over the 0x3e000(may be 0x3e001), malloc failed.
	 * more problems is descirbed in Packetngin App Test Sheet.
	 */

	/* use private malloc_pool */
	for(size_t i = 1; i < pool_size - 0x3e001; i++) {
		void* malloc_pool = malloc(pool_size);
		init_memory_pool(pool_size, malloc_pool, 0);
		
		size_t mem_size = i;
		void* mem = __malloc(mem_size, malloc_pool);
		assert_in_range(mem, malloc_pool, malloc_pool + pool_size);	

		destroy_memory_pool(malloc_pool);
		free(malloc_pool);
		malloc_pool = NULL;
	}	

	/* use __malloc_pool */
	for(size_t i = 1; i < pool_size - 0x3e001; i++) {
		__malloc_pool = malloc(pool_size);
		init_memory_pool(pool_size, __malloc_pool, 0);
		
		size_t mem_size = i;
		void* mem = __malloc(mem_size, NULL);

		assert_in_range(mem, __malloc_pool, __malloc_pool + pool_size);	

		destroy_memory_pool(__malloc_pool);
		free(__malloc_pool);
		__malloc_pool = NULL;
	}	
}
Пример #2
0
static void arp_pack_func(void** state) {
	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x10c37b9309d1;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	uint32_t spa = 0xc0a80a6f;
	uint32_t dpa = 0xc0a80a90;
	arp_request(__nics[0], dpa, spa);

	Packet* packet = fifo_pop(__nics[0]->output_buffer); 
	uint32_t comp_size = packet->end;
	packet->end = 0;

	arp_pack(packet);

	// Checking packet->end
	assert_int_equal(comp_size, packet->end);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #3
0
static void arp_announce_func(void** state) {
	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x10c37b9309d1;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	uint32_t spa = 0xc0a80a6f;
	arp_announce(__nics[0], spa);

	Packet* packet = fifo_pop(__nics[0]->output_buffer); 
	
	assert_memory_equal(packet->buffer + packet->start, arp_announce_packet, 46);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #4
0
 ~data(void)
 {
     scoped_lock lock(*this);
     if(pool) {
         destroy_memory_pool(pool);
         operator delete(pool);
     }
 }
Пример #5
0
static void arp_process_func(void** state) {
	// Timer setting
	timer_init("IntelCore(TM) i5-4670 CPU @ 3.40GHz");

	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x74d4358f66cb;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);


	// Arp request
	Packet* packet = nic_alloc(__nics[0], sizeof(arp_request_packet));
	memcpy(packet->buffer + packet->start, arp_request_packet, sizeof(arp_request_packet));

	Ether* ether = (Ether*)(packet->buffer + packet->start);
	ARP* arp = (ARP*)ether->payload;
	uint32_t addr = endian32(arp->tpa);
	nic_ip_add(__nics[0], addr);

	assert_true(arp_process(packet));
	packet = fifo_pop(__nics[0]->output_buffer); 
	assert_memory_equal(packet->buffer + packet->start, arp_reply_packet, 42);

	nic_free(packet);
	packet = NULL;
	
	// Arp response
	packet = nic_alloc(__nics[0], sizeof(arp_reply_packet));
	memcpy(packet->buffer + packet->start, arp_reply_packet, sizeof(arp_reply_packet));

	ether = (Ether*)(packet->buffer + packet->start);
	arp = (ARP*)ether->payload;
	addr = endian32(arp->tpa);
	nic_ip_add(__nics[0], addr);

	uint8_t comp_mac[6] = { 0xcb, 0x66, 0x8f, 0x35, 0xd4, 0x74 }; 
	uint32_t sip = endian32(arp->spa);
	Map* arp_table = nic_config_get(packet->nic, "net.arp.arptable");
	assert_true(arp_process(packet));
	ARPEntity* entity = map_get(arp_table, (void*)(uintptr_t)sip);

	assert_memory_equal((uint8_t*)&entity->mac, comp_mac, 6);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #6
0
static void interface_alloc_func(void** state) {
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	IPv4Interface* interface = interface_alloc(malloc_pool);
	assert_in_range(interface, malloc_pool, malloc_pool + POOL_SIZE);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #7
0
void HeapTlsf::TLSF_RESET()
{	
	if (mTotalSize > 0)
	{
		for (unsigned int n=0;n<mTlsfIndex;n++)
		{
			LOGI("Tlsf reset pool: %d\n", n);
			destroy_memory_pool(mTlsfPools[n]);	
			memset(mTlsfPools[n], 9, DEFAULT_TLSF_SIZE);
			mTlsfPoolsMem[n] = init_memory_pool( DEFAULT_TLSF_SIZE, mTlsfPools[n] );
		}
	}
}
Пример #8
0
static void file_write_func() {
	int file_fd = 0;
	int file_context = 0;

	int size = 1024;
	char* buffer;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	buffer = malloc(size); 

	__fio = fio_create(__malloc_pool);

	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();

	for(int i = 0; i < 256; i++) {
		file_context = file_fd = i;
		
		sprintf(buffer, "Write Test %d", file_fd);
		int status = file_read(file_fd, buffer, size, write_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_WRITE;
		output_buffer->context = &file_context;
		output_buffer->fd = file_fd;
		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;

		output_buffer->op.file_io.buffer = buffer;
		output_buffer->op.file_io.size = size;
		
		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(status, FIO_OK);

		event_loop();
	}

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Пример #9
0
static void free_func() {
	size_t pool_size = 0x40000;
	size_t malloc_size = 253951;
	void* mem;

	/* use private pool */
	void* malloc_pool = malloc(pool_size);
	init_memory_pool(pool_size, malloc_pool, 0);
	
	mem = __malloc(malloc_size, malloc_pool);			
	__free(mem, malloc_pool);
	mem = NULL;

	mem = __malloc(malloc_size, malloc_pool);
	assert_non_null(mem);
	__free(mem, malloc_pool);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;

	/* use __malloc_pool */
	__malloc_pool = malloc(pool_size);
	init_memory_pool(pool_size, __malloc_pool, 0);	

	mem = __malloc(malloc_size, __malloc_pool);
	__free(mem, __malloc_pool);
	mem = NULL;

	mem = __malloc(malloc_size, __malloc_pool);
	assert_non_null(mem);
	__free(mem, __malloc_pool);
	mem = NULL;

	destroy_memory_pool(__malloc_pool);
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Пример #10
0
void
kogmo_rtdb_obj_mem_destroy (kogmo_rtdb_handle_t *db_h)
{
    void *base = db_h->localdata_p->heap;
    DBGL(DBGL_DB,"mem_destroy: release %p, %lli bytes were used, %lli free",
         base,
         (long long int) db_h->localdata_p->heap_used,
         (long long int) db_h->localdata_p->heap_free);
#if defined(RTMALLOC_tlsf)
    destroy_memory_pool (base);
#elif defined(RTMALLOC_suba)
// do nothing
#else
// do nothing
#endif
}
Пример #11
0
int main(int argc, char **argv)
{
	int ret;
	size_t pool_size;
	char *fname;

	if (argc < 2) {
		printf("Usage: tlsf_test <file>\n");
		printf("\t<file> is swap replay dump file from sr_collect\n");
		goto out;
	}

	fname = argv[1];	
	ret = set_sr_file(fname);
	if (ret < 0) {
		printf("Error setting replay data file.\n");
		goto out;
	}

	pool = malloc(MAX_POOL_SIZE);
	if (pool == NULL) {
		printf("Error allocating memory pool.\n");
		goto out;
	}

	pool_size = init_memory_pool(MAX_POOL_SIZE, pool);
	printf("# total pool size: %u\n", pool_size);

	page_table = calloc(MAX_TABLE_SIZE, sizeof(*page_table));
	if (page_table == NULL) {
		printf("Error allocating page table structure.\n");
		goto out_pgtbl;
	}

	set_sr_callbacks(event_read, event_write, event_replay_end);
	
	sr_start();

	free(page_table);

out_pgtbl:
	destroy_memory_pool(pool);
	free(pool);

out:
	return 0;
}
Пример #12
0
static void file_opendir_func() {
	int file_fd = 0;
	int file_context = 0;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	__fio = fio_create(__malloc_pool);					
	
	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();

	/* check context & fd unitl get to Max request id */ 
	for(int i = 0; i < 256; i++) {
		file_context = i;
		int status = file_opendir("Test", opendir_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		/* FIORequest that put in to output_buffer of __fio */
		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_OPENDIR;
		output_buffer->context = &file_context;

		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;
		output_buffer->fd = file_fd = i;

		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(FIO_OK, status);

		event_loop();
	}

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Пример #13
0
static void file_close_func() {
	int file_fd = 0;
	int file_context = 0;

	__malloc_pool = malloc(0x40000);
	init_memory_pool(0x40000, __malloc_pool, 0);

	__fio = fio_create(__malloc_pool);

	timer_init("Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz");
	event_init();
	file_init();
	
	for(int i = 0; i < 256; i++) {
		file_context = file_fd = i;

		int status = file_close(file_fd, close_callback, &file_context);

		__fio->output_buffer->head = i;
		__fio->output_buffer->tail = i + 1;

		FIORequest* output_buffer = malloc(sizeof(FIORequest));
		output_buffer->type = FILE_T_CLOSE;
		output_buffer->context = &file_context;
		output_buffer->id = (__fio->request_id - 1) % FIO_MAX_REQUEST_ID;
		output_buffer->fd = file_fd;

		__fio->output_buffer->array[i] = output_buffer;

		assert_int_equal(status, FIO_OK);

		event_loop();
	}	

	fifo_destroy(__fio->input_buffer);
	fifo_destroy(__fio->output_buffer);
	__free(__fio, __malloc_pool);
	
	destroy_memory_pool(__malloc_pool);	
	free(__malloc_pool);
	__malloc_pool = NULL;
}
Пример #14
0
main(){
  int *ptr[100];
  int i, free_mem;
  
  free_mem = init_memory_pool(POOL_SIZE, pool);
  printf("Total free memory= %d\n", free_mem);
  
  for (i=0; i< 100; i++)
    if (!(ptr[i]=malloc_ex(1024, pool))){
      printf("Error\n");
      exit(-1);
    }
  
  for (i=0; i< 100; i++)
    free_ex(ptr[i], pool);
 
  destroy_memory_pool(pool);
  printf("Test OK\n");
  exit(0);
}
Пример #15
0
static void interface_free_func(void** state) {
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	size_t first_size = get_used_size(malloc_pool);

	IPv4Interface* interface = interface_alloc(malloc_pool);

	size_t comp_size = get_used_size(malloc_pool);
	assert_int_not_equal(comp_size, first_size);

	interface_free(interface, malloc_pool);

	comp_size = get_used_size(malloc_pool);
	assert_int_equal(comp_size, first_size);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #16
0
static void arp_get_mac_func(void** state) {
	//timer setting
	timer_init("IntelCore(TM) i5-4670 CPU @ 3.40GHz");

	// Nic initialization
	void* malloc_pool = malloc(POOL_SIZE);
	init_memory_pool(POOL_SIZE, malloc_pool, 0);

	__nics[0] = malloc(sizeof(NIC));
	__nic_count++;

	__nics[0]->mac = 0x74d4358f66cb;
	__nics[0]->pool_size = POOL_SIZE;
	__nics[0]->pool = malloc_pool;
	__nics[0]->output_buffer = fifo_create(8, malloc_pool);
	__nics[0]->config = map_create(8, NULL, NULL, __nics[0]->pool);

	Packet* packet = nic_alloc(__nics[0], sizeof(arp_reply_packet));
	memcpy(packet->buffer + packet->start, arp_reply_packet, sizeof(arp_reply_packet));

	Ether* ether = (Ether*)(packet->buffer + packet->start);
	ARP* arp = (ARP*)ether->payload;
	uint32_t addr = endian32(arp->tpa);

	nic_ip_add(__nics[0], addr);

	if(!arp_process(packet))
		return;

	uint32_t spa = 0xc0a80a6f;
	uint32_t dpa = 0xc0a80a90;

	uint64_t comp_tha = 0x74d4358f66cb;
	uint64_t d_mac = arp_get_mac(__nics[0], dpa, spa);

	assert_memory_equal((uint8_t*)&d_mac, (uint8_t*)&comp_tha, 6);

	destroy_memory_pool(malloc_pool);
	free(malloc_pool);
	malloc_pool = NULL;
}
Пример #17
0
static void realloc_func() {
	size_t pool_size = 0x40000;
	size_t malloc_size;

	for(size_t i = 1; i < pool_size - 0x3e001; i++) {
		malloc_size = i;

		void* malloc_pool = malloc(pool_size);
		init_memory_pool(pool_size, malloc_pool, 0);

		void* mem = __malloc(malloc_size, malloc_pool);		
		assert_in_range(mem, malloc_pool, malloc_pool + pool_size);

		mem = __realloc(mem, 0x3e000, malloc_pool);
		assert_in_range(mem, malloc_pool, malloc_pool + pool_size);

		destroy_memory_pool(malloc_pool);
		free(malloc_pool);
		malloc_pool = NULL;
	}
}
Пример #18
0
int heapobj_pkg_init_private(void)
{
	size_t size;
	void *mem;

	/*
	 * We want to know how many bytes from a memory pool TLSF will
	 * use for its own internal use. We get the probe memory from
	 * tlsf_malloc(), so that the main pool will be set up in the
	 * same move.
	 */
	mem = tlsf_malloc(__this_node.mem_pool);
	size = init_memory_pool(__this_node.mem_pool, mem);
	if (size == (size_t)-1)
		panic("cannot initialize TLSF memory manager");

	destroy_memory_pool(mem);
	tlsf_pool_overhead = __this_node.mem_pool - size;
	tlsf_pool_overhead = (tlsf_pool_overhead + 15) & ~15;
	tlsf_free(mem);

	return 0;
}
Пример #19
0
void nx_memalloc_destroy(void) {
  destroy_memory_pool(mp);
}
Пример #20
0
void __heapobj_destroy(struct heapobj *hobj)
{
	destroy_memory_pool(hobj->pool);
	__RT(pthread_mutex_destroy(&hobj->lock));
}