예제 #1
0
파일: test.c 프로젝트: Agostin/csipsimple
int test_main(void)
{
    pj_status_t rc;
    pj_caching_pool caching_pool;
    const char *filename;
    unsigned tsx_test_cnt=0;
    struct tsx_test_param tsx_test[10];
    pj_status_t status;
#if INCLUDE_TSX_TEST
    unsigned i;
    pjsip_transport *tp;
#if PJ_HAS_TCP
    pjsip_tpfactory *tpfactory;
#endif	/* PJ_HAS_TCP */
#endif	/* INCLUDE_TSX_TEST */
    int line;

    pj_log_set_level(log_level);
    pj_log_set_decor(param_log_decor);

    if ((rc=pj_init()) != PJ_SUCCESS) {
	app_perror("pj_init", rc);
	return rc;
    }

    if ((rc=pjlib_util_init()) != PJ_SUCCESS) {
	app_perror("pj_init", rc);
	return rc;
    }

    status = init_report();
    if (status != PJ_SUCCESS)
	return status;

    pj_dump_config();

    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 
			  PJSIP_TEST_MEM_SIZE );

    rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt);
    if (rc != PJ_SUCCESS) {
	app_perror("pjsip_endpt_create", rc);
	pj_caching_pool_destroy(&caching_pool);
	return rc;
    }

    PJ_LOG(3,(THIS_FILE,""));

    /* Init logger module. */
    init_msg_logger();
    msg_logger_set_enabled(1);

    /* Start transaction layer module. */
    rc = pjsip_tsx_layer_init_module(endpt);
    if (rc != PJ_SUCCESS) {
	app_perror("   Error initializing transaction module", rc);
	goto on_return;
    }

    /* Create loop transport. */
    rc = pjsip_loop_start(endpt, NULL);
    if (rc != PJ_SUCCESS) {
	app_perror("   error: unable to create datagram loop transport", 
		   rc);
	goto on_return;
    }
    tsx_test[tsx_test_cnt].port = 5060;
    tsx_test[tsx_test_cnt].tp_type = "loop-dgram";
    tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_LOOP_DGRAM;
    ++tsx_test_cnt;


#if INCLUDE_URI_TEST
    DO_TEST(uri_test());
#endif

#if INCLUDE_MSG_TEST
    DO_TEST(msg_test());
    DO_TEST(msg_err_test());
#endif

#if INCLUDE_MULTIPART_TEST
    DO_TEST(multipart_test());
#endif

#if INCLUDE_TXDATA_TEST
    DO_TEST(txdata_test());
#endif

#if INCLUDE_TSX_BENCH
    DO_TEST(tsx_bench());
#endif

#if INCLUDE_UDP_TEST
    DO_TEST(transport_udp_test());
#endif

#if INCLUDE_LOOP_TEST
    DO_TEST(transport_loop_test());
#endif

#if INCLUDE_TCP_TEST
    DO_TEST(transport_tcp_test());
#endif

#if INCLUDE_RESOLVE_TEST
    DO_TEST(resolve_test());
#endif


#if INCLUDE_TSX_TEST
    status = pjsip_udp_transport_start(endpt, NULL, NULL, 1,  &tp);
    if (status == PJ_SUCCESS) {
	tsx_test[tsx_test_cnt].port = tp->local_name.port;
	tsx_test[tsx_test_cnt].tp_type = "udp";
	tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_UDP;
	++tsx_test_cnt;
    }

#if PJ_HAS_TCP
    status = pjsip_tcp_transport_start(endpt, NULL, 1, &tpfactory);
    if (status == PJ_SUCCESS) {
	tsx_test[tsx_test_cnt].port = tpfactory->addr_name.port;
	tsx_test[tsx_test_cnt].tp_type = "tcp";
	tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_TCP;
	++tsx_test_cnt;
    } else {
	app_perror("Unable to create TCP", status);
	rc = -4;
	goto on_return;
    }
#endif


    for (i=0; i<tsx_test_cnt; ++i) {
	DO_TSX_TEST(tsx_basic_test, &tsx_test[i]);
	DO_TSX_TEST(tsx_uac_test, &tsx_test[i]);
	DO_TSX_TEST(tsx_uas_test, &tsx_test[i]);
    }
#endif

#if INCLUDE_INV_OA_TEST
    DO_TEST(inv_offer_answer_test());
#endif

#if INCLUDE_REGC_TEST
    DO_TEST(regc_test());
#endif


on_return:
    flush_events(500);

    /* Dumping memory pool usage */
    PJ_LOG(3,(THIS_FILE, "Peak memory size=%u MB",
		         caching_pool.peak_used_size / 1000000));

    pjsip_endpt_destroy(endpt);
    pj_caching_pool_destroy(&caching_pool);

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

    report_ival("test-status", rc, "", "Overall test status/result (0==success)");
    close_report();
    return rc;
}
예제 #2
0
/**
 * Generate a test matrix for tabu search over TEA1, varying Tabu Search parameters
 * \param arcg number of input arguments
 * \param argv input argument string
 */
int main(int argc,char** argv){
	
	input_options *options;
	full_test_input_options *test_options;
	
	cipher_cont *cipher=NULL;
	output_report *report;
	int lock=TRUE;
	
	unsigned long long tabu_list_length=0;
	unsigned long long tabu_iterations=0;	
	unsigned long long tabu_max_decrease=0; 
	unsigned long long change_move_limit=0; 
	float key_eval_percent=0;           
	
	if((test_options=MALLOC(full_test_input_options))==NULL){
		fprintf(stderr,"ERROR: FAILED TO ALLOCATE MEMORY\n");
		exit(1);
	}
	/*
	 * parse input parameters
	 */
	if(argc>1){
		parse_full_test_arguments(argc,argv,test_options);
		if(test_options->have_input==FALSE){
			fprintf(stderr,"ERROR: NO INPUT FILE");
			return(1);
		}
	}
	else{
		print_full_test_options(argv[0]);
		return(1);
	}
		
	
	
	if(test_options->max_tabu_list_length==0){
		test_options->max_tabu_list_length=TS_LIS_MAX;
	} 
	if(test_options->max_tabu_iterations==0){
		test_options->max_tabu_iterations=TS_ITER_MAX;
	}

	if(test_options->max_tabu_max_decrease==0){
		test_options->max_tabu_max_decrease=TS_MAX_DEC_MAX;
	}
	if(test_options->max_change_move_limit==0){
		test_options->max_change_move_limit=TS_CHM_MAX;
	}
	if(test_options->init_tabu_list_length==0){
		test_options->init_tabu_list_length=TS_INIT_LIST;
	}

	if(test_options->init_tabu_iterations==0){
		test_options->init_tabu_iterations=TS_INIT_ITER;
	}

	if(test_options->init_tabu_max_decrease==0){
		test_options->init_tabu_max_decrease=TS_INIT_MAX_DEC;
	}
 
	if(test_options->init_change_move_limit==0){
		test_options->init_change_move_limit=TS_INIT_CHM;
	}

	if(test_options->var_tabu_list_length==0){
		test_options->var_tabu_list_length=TS_LIST_INCREMENT;
	}

	if(test_options->var_tabu_iterations==0){
		test_options->var_tabu_iterations=TS_ITER_INCREMENT;
	}
  
	if(test_options->var_tabu_max_decrease==0){
		test_options->var_tabu_max_decrease=TS_MAX_DEC_INCREMENT;
	}

	if(test_options->var_change_move_limit==0){
		test_options->var_change_move_limit=TS_CHM_INCREMENT;
	}

	if(test_options->min_key_eval_percent==0){
		test_options->min_key_eval_percent=(float)(TS_INIT_PERCENT);
		test_options->min_key_eval_percent=test_options->min_key_eval_percent/100;
	}
           
	if(test_options->var_key_eval_percent==0){
		test_options->var_key_eval_percent=(float)(TS_PERCENT_INCREMENT);
		test_options->var_key_eval_percent=test_options->var_key_eval_percent/100;
	}
	
	options=convert_full_test_opt_to_gen(test_options);
	
	/* create report*/
	report=open_report(options);
	report_use_test_matrix(report);
	/* read input from file */	
	cipher=read_input(test_options->inputfile);
	/* tabu serach parameters asignation */
	tabu_iterations=test_options->min_key_eval_percent;
	tabu_list_length=test_options->init_tabu_list_length;
	tabu_max_decrease=test_options->init_tabu_max_decrease;
	key_eval_percent=test_options->min_key_eval_percent;       
	change_move_limit=test_options->init_change_move_limit;

	
	printf("init test matrix\n");
	print_mold_test_matrix(stdout);
	
	if(options->save_output)
		print_mold_test_matrix(report->report_file);
	/* iterative test matrix */
	while(lock){
		/* tabu search parameters refactory*/
		options->tabu_list_length=tabu_list_length;   /* tabu list lenght (DEFAULT 0) */
		options->tabu_iterations=tabu_iterations;	  /* tabu iterations (DEFAULT 0) */
		options->tabu_max_decrease=tabu_max_decrease; /* tabu performance max decrease (DEFAULT 0) */
		options->key_eval_percent=key_eval_percent;   /* percer for evaluation key */
		options->change_move_limit=change_move_limit;
		/* perform tabu search */
		tabusearch(cipher,options,report);
		/* use iteration test */
		if(tabu_iterations<=test_options->max_tabu_iterations+1){
			/* use list lenght test */
			if(tabu_list_length<=test_options->max_tabu_list_length){
				/* use key percent test */
				if(key_eval_percent<=1){
					/* use performance decreace test */
					if(tabu_max_decrease<test_options->max_tabu_max_decrease){
						/* use change movement limit test */
						if(change_move_limit<test_options->max_change_move_limit){
							change_move_limit+=test_options->var_change_move_limit;
						}
						else{
							change_move_limit=test_options->init_change_move_limit;
							tabu_max_decrease+=test_options->var_tabu_max_decrease;
						}
					}
					else{
						tabu_max_decrease=test_options->init_tabu_max_decrease;
						change_move_limit=test_options->init_change_move_limit;
						key_eval_percent+=test_options->var_key_eval_percent;
					}
				}else{
					tabu_list_length+=test_options->var_tabu_list_length;
					key_eval_percent=test_options->min_key_eval_percent;
					tabu_max_decrease=test_options->init_tabu_max_decrease;
					change_move_limit=test_options->init_change_move_limit;							
				}
			}
			else{
				tabu_iterations+=test_options->var_tabu_iterations;
				tabu_list_length=test_options->init_tabu_list_length;
				tabu_max_decrease=test_options->init_tabu_max_decrease;
				key_eval_percent=test_options->min_key_eval_percent;       
				change_move_limit=test_options->init_change_move_limit;
			}
		}
		else{
			lock=FALSE;
		}
	}
	printf("end test matrix\n");	
	/* end program */
	close_report(report);
	free((char *)options);
	free((char *)test_options);
	free((char *)report);
	free((char *)cipher);
	return(0);
}