Пример #1
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);
}
Пример #2
0
int main(int argc, char *argv[]) {
  int ret;
  int slices;
  int slice_sz;
  int i;
  ret = 0;
  srand(time(NULL));
  for (i = 0; i < 4; i++) {
    slices = rand() % 64;
    slice_sz = rand() % (5 * 1000 * 1000);
    ret = pool_test(slice_sz, slices);
    if (ret) break;
  }
  return ret;
}
Пример #3
0
int test_inner(void)
{
    pj_caching_pool caching_pool;
    const char *filename;
    int line;
    int rc = 0;

    mem = &caching_pool.factory;

    pj_log_set_level(3);
    pj_log_set_decor(param_log_decor);

    rc = pj_init();
    if (rc != 0) {
	app_perror("pj_init() error!!", rc);
	return rc;
    }
    
    //pj_dump_config();
    pj_caching_pool_init( &caching_pool, NULL, 0 );

#if INCLUDE_ERRNO_TEST
    DO_TEST( errno_test() );
#endif

#if INCLUDE_EXCEPTION_TEST
    DO_TEST( exception_test() );
#endif

#if INCLUDE_OS_TEST
    DO_TEST( os_test() );
#endif

#if INCLUDE_RAND_TEST
    DO_TEST( rand_test() );
#endif

#if INCLUDE_LIST_TEST
    DO_TEST( list_test() );
#endif

#if INCLUDE_POOL_TEST
    DO_TEST( pool_test() );
#endif

#if INCLUDE_POOL_PERF_TEST
    DO_TEST( pool_perf_test() );
#endif

#if INCLUDE_STRING_TEST
    DO_TEST( string_test() );
#endif
    
#if INCLUDE_FIFOBUF_TEST
    DO_TEST( fifobuf_test() );
#endif

#if INCLUDE_RBTREE_TEST
    DO_TEST( rbtree_test() );
#endif

#if INCLUDE_HASH_TEST
    DO_TEST( hash_test() );
#endif

#if INCLUDE_TIMESTAMP_TEST
    DO_TEST( timestamp_test() );
#endif

#if INCLUDE_ATOMIC_TEST
    DO_TEST( atomic_test() );
#endif

#if INCLUDE_MUTEX_TEST
    DO_TEST( mutex_test() );
#endif

#if INCLUDE_TIMER_TEST
    DO_TEST( timer_test() );
#endif

#if INCLUDE_SLEEP_TEST
    DO_TEST( sleep_test() );
#endif

#if INCLUDE_THREAD_TEST
    DO_TEST( thread_test() );
#endif

#if INCLUDE_SOCK_TEST
    DO_TEST( sock_test() );
#endif

#if INCLUDE_SOCK_PERF_TEST
    DO_TEST( sock_perf_test() );
#endif

#if INCLUDE_SELECT_TEST
    DO_TEST( select_test() );
#endif

#if INCLUDE_UDP_IOQUEUE_TEST
    DO_TEST( udp_ioqueue_test() );
#endif

#if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST
    DO_TEST( tcp_ioqueue_test() );
#endif

#if INCLUDE_IOQUEUE_PERF_TEST
    DO_TEST( ioqueue_perf_test() );
#endif

#if INCLUDE_IOQUEUE_UNREG_TEST
    DO_TEST( udp_ioqueue_unreg_test() );
#endif

#if INCLUDE_ACTIVESOCK_TEST
    DO_TEST( activesock_test() );
#endif

#if INCLUDE_FILE_TEST
    DO_TEST( file_test() );
#endif

#if INCLUDE_SSLSOCK_TEST
    DO_TEST( ssl_sock_test() );
#endif

#if INCLUDE_ECHO_SERVER
    //echo_server();
    //echo_srv_sync();
    udp_echo_srv_ioqueue();

#elif INCLUDE_ECHO_CLIENT
    if (param_echo_sock_type == 0)
        param_echo_sock_type = pj_SOCK_DGRAM();

    echo_client( param_echo_sock_type, 
                 param_echo_server, 
                 param_echo_port);
#endif

    goto on_return;

on_return:

    pj_caching_pool_destroy( &caching_pool );

    PJ_LOG(3,("test", ""));
 
    pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
    PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", 
	              pj_thread_get_stack_max_usage(pj_thread_this()),
		      filename, line));
    if (rc == 0)
	PJ_LOG(3,("test", "Looks like everything is okay!.."));
    else
	PJ_LOG(3,("test", "Test completed with error(s)"));
    
    pj_shutdown();
    
    return 0;
}