/***************************************************************************** ** ** TEST1_BRANCH_ID: Basic 2xx final response ** TEST2_BRANCH_ID: Basic non-2xx final response ** ***************************************************************************** */ static int tsx_basic_final_response_test(void) { unsigned duration; int status; PJ_LOG(3,(THIS_FILE," test1: basic sending 2xx final response")); /* Test duration must be greater than 32 secs if unreliable transport * is used. */ duration = (tp_flag & PJSIP_TRANSPORT_RELIABLE) ? 1 : 33; status = perform_test(TARGET_URI, FROM_URI, TEST1_BRANCH_ID, duration, &pjsip_options_method, 1, 0, 0); if (status != 0) return status; PJ_LOG(3,(THIS_FILE," test2: basic sending non-2xx final response")); status = perform_test(TARGET_URI, FROM_URI, TEST2_BRANCH_ID, duration, &pjsip_options_method, 1, 0, 0); if (status != 0) return status; return 0; }
/***************************************************************************** ** ** TEST4_BRANCH_ID: Absorbs retransmissions in TRYING state ** TEST5_BRANCH_ID: Absorbs retransmissions in PROCEEDING state ** TEST6_BRANCH_ID: Absorbs retransmissions in COMPLETED state ** ***************************************************************************** */ static int tsx_retransmit_last_response_test(const char *title, char *branch_id, int request_cnt, int status_code) { int status; PJ_LOG(3,(THIS_FILE," %s", title)); status = perform_test(TARGET_URI, FROM_URI, branch_id, 5, &pjsip_options_method, request_cnt, 1000, 1); if (status && status != TEST_TIMEOUT_ERROR) return status; if (!status) { PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); return -31; } terminate_our_tsx(status_code); flush_events(100); if (test_complete != 1) return test_complete; flush_events(100); return 0; }
void main() { u8 key_1[10] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34}; u8 key_2[10] = {0xf1, 0x1a, 0x56, 0x27, 0xce, 0x43, 0xb6, 0x1f, 0x89, 0x12}; u8 key_3[10] = {0x3b, 0x80, 0xfc, 0x8c, 0x47, 0x5f, 0xc2, 0x70, 0xfa, 0x26}; u8 key_4[10] = {0x82, 0xac, 0xb3, 0x8c, 0x5d, 0x7a, 0x3c, 0x78, 0xd9, 0x8f}; u8 iv_1[4] = {0x21, 0x43, 0x65, 0x87}; u8 iv_2[10] = {0x9c, 0x53, 0x2f, 0x8a, 0xc3, 0xea, 0x4b, 0x2e, 0xa0, 0xf5}; /* Initialise the algorithm */ ECRYPT_init (); /* Generate the test data */ perform_test (key_1, iv_1, 32); perform_test (key_2, iv_2, 80); perform_test (key_3, NULL, 0); perform_iterated_test (key_4); }
int inv_offer_answer_test(void) { unsigned i; int rc = 0; /* Init UA layer */ if (pjsip_ua_instance()->id == -1) { pjsip_ua_init_param ua_param; pj_bzero(&ua_param, sizeof(ua_param)); ua_param.on_dlg_forked = &on_dlg_forked; pjsip_ua_init_module(endpt, &ua_param); } /* Init inv-usage */ if (pjsip_inv_usage_instance()->id == -1) { pjsip_inv_callback inv_cb; pj_bzero(&inv_cb, sizeof(inv_cb)); inv_cb.on_media_update = &on_media_update; inv_cb.on_rx_offer = &on_rx_offer; inv_cb.on_create_offer = &on_create_offer; inv_cb.on_state_changed = &on_state_changed; inv_cb.on_new_session = &on_new_session; pjsip_inv_usage_init(endpt, &inv_cb); } /* 100rel module */ pjsip_100rel_init_module(endpt); /* Our module */ pjsip_endpt_register_module(endpt, &mod_inv_oa_test); pjsip_endpt_register_module(endpt, &mod_msg_logger); /* Create SIP UDP transport */ { pj_sockaddr_in addr; pjsip_transport *tp; pj_status_t status; pj_sockaddr_in_init(&addr, NULL, PORT); status = pjsip_udp_transport_start(endpt, &addr, NULL, 1, &tp); pj_assert(status == PJ_SUCCESS); } /* Do tests */ for (i=0; i<PJ_ARRAY_SIZE(test_params); ++i) { rc = perform_test(&test_params[i]); if (rc != 0) goto on_return; } on_return: return rc; }
/***************************************************************************** ** ** TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test ** TEST8_BRANCH_ID: INVITE 2xx final response retransmission test ** ***************************************************************************** */ static int tsx_final_response_retransmission_test(void) { int status; PJ_LOG(3,(THIS_FILE, " test7: INVITE non-2xx final response retransmission")); status = perform_test(TARGET_URI, FROM_URI, TEST7_BRANCH_ID, 33, /* Test duration must be greater than 32 secs */ &pjsip_invite_method, 1, 0, 0); if (status != 0) return status; PJ_LOG(3,(THIS_FILE, " test8: INVITE 2xx final response retransmission")); status = perform_test(TARGET_URI, FROM_URI, TEST8_BRANCH_ID, 33, /* Test duration must be greater than 32 secs */ &pjsip_invite_method, 1, 0, 0); if (status != 0) return status; return 0; }
/***************************************************************************** ** ** TEST3_BRANCH_ID: Sending provisional response ** ***************************************************************************** */ static int tsx_basic_provisional_response_test(void) { unsigned duration; int status; PJ_LOG(3,(THIS_FILE," test3: basic sending 2xx final response")); duration = (tp_flag & PJSIP_TRANSPORT_RELIABLE) ? 1 : 33; duration += 2; status = perform_test(TARGET_URI, FROM_URI, TEST3_BRANCH_ID, duration, &pjsip_options_method, 1, 0, 0); return status; }
/***************************************************************************** ** ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must ** cease when ACK is received ** ***************************************************************************** */ static int tsx_ack_test(void) { int status; PJ_LOG(3,(THIS_FILE, " test9: receiving ACK for non-2xx final response")); status = perform_test(TARGET_URI, FROM_URI, TEST9_BRANCH_ID, 20, /* allow 5 retransmissions */ &pjsip_invite_method, 1, 0, 0); if (status != 0) return status; return 0; }
int sdp_neg_test() { unsigned i; int status; for (i=START_TEST; i<PJ_ARRAY_SIZE(test); ++i) { pj_pool_t *pool; pool = pj_pool_create(mem, "sdp_neg_test", 4000, 4000, NULL); if (!pool) return PJ_ENOMEM; PJ_LOG(3,(THIS_FILE," test %d: %s", i, test[i].title)); status = perform_test(pool, i); pj_pool_release(pool); if (status != 0) { return status; } } return 0; }
static int ioqueue_perf_test_imp(pj_bool_t allow_concur) { enum { BUF_SIZE = 512 }; int i, rc; struct { int type; const char *type_name; int thread_cnt; int sockpair_cnt; } test_param[] = { { pj_SOCK_DGRAM(), "udp", 1, 1}, { pj_SOCK_DGRAM(), "udp", 1, 2}, { pj_SOCK_DGRAM(), "udp", 1, 4}, { pj_SOCK_DGRAM(), "udp", 1, 8}, { pj_SOCK_DGRAM(), "udp", 2, 1}, { pj_SOCK_DGRAM(), "udp", 2, 2}, { pj_SOCK_DGRAM(), "udp", 2, 4}, { pj_SOCK_DGRAM(), "udp", 2, 8}, { pj_SOCK_DGRAM(), "udp", 4, 1}, { pj_SOCK_DGRAM(), "udp", 4, 2}, { pj_SOCK_DGRAM(), "udp", 4, 4}, { pj_SOCK_DGRAM(), "udp", 4, 8}, { pj_SOCK_DGRAM(), "udp", 4, 16}, { pj_SOCK_STREAM(), "tcp", 1, 1}, { pj_SOCK_STREAM(), "tcp", 1, 2}, { pj_SOCK_STREAM(), "tcp", 1, 4}, { pj_SOCK_STREAM(), "tcp", 1, 8}, { pj_SOCK_STREAM(), "tcp", 2, 1}, { pj_SOCK_STREAM(), "tcp", 2, 2}, { pj_SOCK_STREAM(), "tcp", 2, 4}, { pj_SOCK_STREAM(), "tcp", 2, 8}, { pj_SOCK_STREAM(), "tcp", 4, 1}, { pj_SOCK_STREAM(), "tcp", 4, 2}, { pj_SOCK_STREAM(), "tcp", 4, 4}, { pj_SOCK_STREAM(), "tcp", 4, 8}, { pj_SOCK_STREAM(), "tcp", 4, 16}, /* { pj_SOCK_DGRAM(), "udp", 32, 1}, { pj_SOCK_DGRAM(), "udp", 32, 1}, { pj_SOCK_DGRAM(), "udp", 32, 1}, { pj_SOCK_DGRAM(), "udp", 32, 1}, { pj_SOCK_DGRAM(), "udp", 1, 32}, { pj_SOCK_DGRAM(), "udp", 1, 32}, { pj_SOCK_DGRAM(), "udp", 1, 32}, { pj_SOCK_DGRAM(), "udp", 1, 32}, { pj_SOCK_STREAM(), "tcp", 32, 1}, { pj_SOCK_STREAM(), "tcp", 32, 1}, { pj_SOCK_STREAM(), "tcp", 32, 1}, { pj_SOCK_STREAM(), "tcp", 32, 1}, { pj_SOCK_STREAM(), "tcp", 1, 32}, { pj_SOCK_STREAM(), "tcp", 1, 32}, { pj_SOCK_STREAM(), "tcp", 1, 32}, { pj_SOCK_STREAM(), "tcp", 1, 32}, */ }; pj_size_t best_bandwidth; int best_index = 0; PJ_LOG(3,(THIS_FILE, " Benchmarking %s ioqueue:", pj_ioqueue_name())); PJ_LOG(3,(THIS_FILE, " Testing with concurency=%d", allow_concur)); PJ_LOG(3,(THIS_FILE, " =======================================")); PJ_LOG(3,(THIS_FILE, " Type Threads Skt.Pairs Bandwidth")); PJ_LOG(3,(THIS_FILE, " =======================================")); best_bandwidth = 0; for (i=0; i<(int)(sizeof(test_param)/sizeof(test_param[0])); ++i) { pj_size_t bandwidth; rc = perform_test(allow_concur, test_param[i].type, test_param[i].type_name, test_param[i].thread_cnt, test_param[i].sockpair_cnt, BUF_SIZE, &bandwidth); if (rc != 0) return rc; if (bandwidth > best_bandwidth) best_bandwidth = bandwidth, best_index = i; /* Give it a rest before next test, to allow system to close the * sockets properly. */ pj_thread_sleep(500); } PJ_LOG(3,(THIS_FILE, " Best: Type=%s Threads=%d, Skt.Pairs=%d, Bandwidth=%u KB/s", test_param[best_index].type_name, test_param[best_index].thread_cnt, test_param[best_index].sockpair_cnt, best_bandwidth)); PJ_LOG(3,(THIS_FILE, " (Note: packet size=%d, total errors=%u)", BUF_SIZE, last_error_counter)); return 0; }
int ice_test(void) { pj_pool_t *pool; pj_stun_config stun_cfg; unsigned i; int rc; struct sess_cfg_t { const char *title; unsigned server_flag; struct test_cfg ua1; struct test_cfg ua2; } sess_cfg[] = { /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ { "hosts candidates only", 0xFFFF, {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, { "host and srflxes", 0xFFFF, {ROLE1, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, { "host vs relay", 0xFFFF, {ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, { "relay vs host", 0xFFFF, {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, { "relay vs relay", 0xFFFF, {ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, { "all candidates", 0xFFFF, {ROLE1, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }, }; pool = pj_pool_create(mem, NULL, 512, 512, NULL); rc = create_stun_config(pool, &stun_cfg); if (rc != PJ_SUCCESS) { pj_pool_release(pool); return -7; } /* Simple test first with host candidate */ if (1) { struct sess_cfg_t cfg = { "Basic with host candidates", 0x0, /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; rc = perform_test("Basic with host candidates, 2 components", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } /* Simple test first with srflx candidate */ if (1) { struct sess_cfg_t cfg = { "Basic with srflx candidates", 0xFFFF, /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; rc = perform_test("Basic with srflx candidates, 2 components", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } /* Simple test with relay candidate */ if (1) { struct sess_cfg_t cfg = { "Basic with relay candidates", 0xFFFF, /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}}, {ROLE2, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; rc = perform_test("Basic with relay candidates, 2 components", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } /* Failure test with STUN resolution */ if (1) { struct sess_cfg_t cfg = { "STUN resolution failure", 0x0, /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 2, NO, YES, NO, 0, 0, 0, 0, {PJNATH_ESTUNTIMEDOUT, -1}}, {ROLE2, 2, NO, YES, NO, 0, 0, 0, 0, {PJNATH_ESTUNTIMEDOUT, -1}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; rc = perform_test("STUN resolution failure with destroy on callback", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } /* Failure test with TURN resolution */ if (1) { struct sess_cfg_t cfg = { "TURN allocation failure", 0xFFFF, /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_STATUS_FROM_STUN_CODE(401), -1}}, {ROLE2, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_STATUS_FROM_STUN_CODE(401), -1}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; rc = perform_test("TURN allocation failure with destroy on callback", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } /* STUN failure, testing TURN deallocation */ if (1) { struct sess_cfg_t cfg = { "STUN failure, testing TURN deallocation", 0xFFFF & (~(CREATE_STUN_SERVER)), /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ {ROLE1, 2, YES, YES, YES, 0, 0, 0, 0, {PJNATH_ESTUNTIMEDOUT, -1}}, {ROLE2, 2, YES, YES, YES, 0, 0, 0, 0, {PJNATH_ESTUNTIMEDOUT, -1}} }; rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; rc = perform_test("STUN failure, testing TURN deallocation (cb)", &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } rc = 0; /* Iterate each test item */ for (i=0; i<PJ_ARRAY_SIZE(sess_cfg); ++i) { struct sess_cfg_t *cfg = &sess_cfg[i]; unsigned delay[] = { 50, 2000 }; unsigned d; PJ_LOG(3,("", " %s", cfg->title)); /* For each test item, test with various answer delay */ for (d=0; d<PJ_ARRAY_SIZE(delay); ++d) { struct role_t { pj_ice_sess_role ua1; pj_ice_sess_role ua2; } role[] = { { ROLE1, ROLE2}, { ROLE2, ROLE1}, { ROLE1, ROLE1}, { ROLE2, ROLE2} }; unsigned j; cfg->ua1.answer_delay = delay[d]; cfg->ua2.answer_delay = delay[d]; /* For each test item, test with role conflict scenarios */ for (j=0; j<PJ_ARRAY_SIZE(role); ++j) { unsigned k1; cfg->ua1.role = role[j].ua1; cfg->ua2.role = role[j].ua2; /* For each test item, test with different number of components */ for (k1=1; k1<=2; ++k1) { unsigned k2; cfg->ua1.comp_cnt = k1; for (k2=1; k2<=2; ++k2) { char title[120]; sprintf(title, "%s/%s, %dms answer delay, %d vs %d components", pj_ice_sess_role_name(role[j].ua1), pj_ice_sess_role_name(role[j].ua2), delay[d], k1, k2); cfg->ua2.comp_cnt = k2; rc = perform_test(title, &stun_cfg, cfg->server_flag, &cfg->ua1, &cfg->ua2); if (rc != 0) goto on_return; } } } } } on_return: destroy_stun_config(&stun_cfg); pj_pool_release(pool); return rc; }
int main(int argc, char *argv[]) { srand(time(NULL)); if (argc < 2) { size_t num_size; for (num_size = MINN; num_size <= MAXN; num_size *= STEP) { long double running_add = 0.0; long double running_sub = 0.0; long double running_mult = 0.0; long double running_karat = 0.0; size_t j; for (j = 0; j < NUMTESTS; j++) { Integer a, b, result; integer_initialize(&a); integer_initialize(&b); integer_initialize(&result); integer_resize_if_necessary(&a, num_size); integer_resize_if_necessary(&b, num_size); memset(a.values, MAX_INTEGER_VALUE, num_size * sizeof *a.values); a.assigned = num_size; memset(b.values, MAX_INTEGER_VALUE, num_size * sizeof *b.values); b.assigned = num_size; //integer_random(&a, num_size); //integer_random(&b, num_size); running_add += perform_test(integer_add_integer, &result, &a, &b); running_sub += perform_test(integer_subtract_integer, &result, &a, &b); running_mult += perform_test(integer_multiply_integer, &result, &a, &b); running_karat += perform_test(karatsuba, &result, &a, &b); //running_pow += perform_test(integer_power_integer, &result, &a, &b); integer_uninitialize(&a); integer_uninitialize(&b); integer_uninitialize(&result); } printf("%zu,%.30Le,%.30Le,%.30Le,%.30Le\n", num_size, running_add, running_sub, running_mult, running_karat); } } else if (strcmp(argv[1], "1") == 0) { uint64_t power; Integer a; integer_initialize(&a); integer_assign_from_int(&a, MAX_INTEGER_VALUE); integer_add_int(&a, &a, 1); for (power = MINPOWER; power <= MAXPOWER; power *= 2) { long double running_power = 0.0; long double running_power_by_squaring = 0.0; size_t j; for (j = 0; j < NUMTESTS; j++) { Integer result; integer_initialize(&result); running_power += perform_power_test(integer_power_int, &result, &a, power); running_power_by_squaring += perform_power_test(power_by_squaring, &result, &a, power); } printf("%zu,%Le,%Le\n", power, running_power, running_power_by_squaring); } } else if (strcmp(argv[1], "2") == 0) { mpz_t twoTo64, twoTo64Minus1, running_val; mpz_init_set_ui(twoTo64, MAX_INTEGER_VALUE); mpz_init_set_ui(twoTo64Minus1, MAX_INTEGER_VALUE); mpz_init_set(running_val, twoTo64Minus1); mpz_add_ui(twoTo64, twoTo64, 1); size_t num_size; for (num_size = 10; num_size <= MAXN; num_size *= STEP) { long double running_add = 0.0; long double running_sub = 0.0; long double running_mul = 0.0; size_t j; for (j = 0; j < NUMTESTS; j++) { mpz_t a, b, result; mpz_init_set(a, running_val); mpz_init_set(b, running_val); mpz_sub_ui(b, b, 1); mpz_init(result); running_add += perform_mpz_test(mpz_add, result, a, b); running_sub += perform_mpz_test(mpz_sub, result, a, b); running_mul += perform_mpz_test(mpz_mul, result, a, b); } size_t i; for (i = num_size; i < STEP * num_size; i++) { mpz_add(running_val, running_val, twoTo64Minus1); mpz_mul(running_val, running_val, twoTo64); } printf("%zu,%.30Le,%.30Le,%.30Le\n", num_size, running_add, running_sub, running_mul); } } else if (strcmp(argv[1], "3") == 0) { mpz_t a; mpz_init_set_ui(a, MAX_INTEGER_VALUE); mpz_add_ui(a, a, 1); size_t power; for (power = MINPOWER; power <= MAXPOWER; power *= 2) { long double running_power = 0.0; size_t j; for (j = 0; j < NUMTESTS; j++) { mpz_t result; mpz_init(result); timeval start, end; gettimeofday(&start, NULL); mpz_pow_ui(result, a, power); gettimeofday(&end, NULL); running_power += ((long double) end.tv_sec - start.tv_sec) + ((long double) end.tv_usec - (long double) start.tv_usec) / MICRO_FACTOR; } printf("%zu,%.30Le\n", power, running_power); } } return 0; }
int main (int argc, char **argv) { int c; const char *truth_file = NULL; const char *test_file = NULL; const char *format = NULL; int compare_before = FALSE; int compare_after = TRUE; int seed = 0; const struct option lopt[] = { {"help", 0, 0, 'h'}, {"seed", 1, 0, 'd'}, {"truth", 1, 0, 'b'}, {"test", 1, 0, 't'}, {"format", 1, 0, 'f'}, {"rand_time", 1, 0, 'n'}, {"fail_prob", 1, 0, 'u'}, {"cancel_prob", 1, 0, 'c'}, {"flush_prob", 1, 0, 'w'}, {"round", 1, 0, 'r'}, {"parallel", 1, 0, 'p'}, {"compare_before", 1, 0, 'm'}, {"verify_write", 1, 0, 'v'}, {"compare_after", 1, 0, 'a'}, {"max_iov", 1, 0, 'i'}, {"io_size", 1, 0, 's'}, {"instant_qemubh", 1, 0, 'q'}, {NULL, 0, NULL, 0} }; progname = basename (argv[0]); while ((c = getopt_long (argc, argv, "hc:u:p:q:i:f:d:b:t:r:m:v:a:s:", lopt, NULL)) != -1) { switch (c) { case 'h': usage (); return 0; case 'q': instant_qemubh = read_bool (optarg); break; case 'w': flush_prob = atof (optarg); break; case 'c': cancel_prob = atof (optarg); break; case 'u': fail_prob = atof (optarg); break; case 'n': rand_time = atoll (optarg); break; case 'i': max_iov = atoi (optarg); break; case 'p': parallel = atoi (optarg); break; case 'v': verify_write = read_bool (optarg); break; case 'm': compare_before = read_bool (optarg); break; case 'a': compare_after = read_bool (optarg); break; case 'd': seed = atoll (optarg); break; case 'f': format = optarg; break; case 'b': truth_file = optarg; break; case 't': test_file = optarg; break; case 's': io_size = atoll (optarg); break; case 'r': round = atoll (optarg); break; default: usage (); return 1; } } if (!truth_file || !test_file) { usage (); return 1; } if (parallel <= 0) { parallel = 1; } srandom (seed); /* Convince FVD this is not in a qemu-tool. */ in_qemu_tool = false; enable_block_sim (FALSE /*no print */ , rand_time); fvd_enable_host_crash_test (); bdrv_init (); perform_test (truth_file, test_file, format, compare_before, compare_after); return 0; }
rc_t CC KMain ( int argc, char *argv [] ) { Args * args; rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1, QfileTestOptions, sizeof ( QfileTestOptions ) / sizeof ( OptDef ) ); if ( rc != 0 ) { OUTMSG(( "ArgsMakeAndHandle( ... ) failed: %R\n", rc )); } else { uint32_t arg_count = 0; rc = ArgsParamCount ( args, &arg_count ); if ( rc != 0 ) { OUTMSG(( "ArgsParamCount( ... ) failed: %R\n", rc )); } else { KDirectory *dir = NULL; uint64_t position = get_uint64_option( args, OPTION_POS, 0 ); uint64_t count = get_uint64_option( args, OPTION_COUNT, 0 ); uint32_t qsize = get_uint32_option( args, OPTION_QSIZE, 1024 ); uint32_t bsize = get_uint32_option( args, OPTION_BSIZE, 0 ); uint32_t csize = get_uint32_option( args, OPTION_CSIZE, 1024 ); uint64_t pos2 = get_uint64_option( args, OPTION_POS2, 0 ); OUTMSG(( "start-position : %lu\n", position )); if ( pos2 > 0 ) { OUTMSG(( "2nd position : %lu\n", pos2 )); } if ( count > 0 ) { OUTMSG(( "count : %lu\n", count )); } OUTMSG(( "queue-size : %u\n", qsize )); OUTMSG(( "block-size : %u\n", bsize )); OUTMSG(( "chunk-size : %u\n", csize )); rc = KDirectoryNativeDir( &dir ); if ( rc != 0 ) { OUTMSG(( "KDirectoryNativeDir( ... ) failed: %R\n", rc )); } else { uint32_t i; for ( i = 0; i < arg_count && rc == 0; ++i ) { const char * filename; rc = ArgsParamValue ( args, i, &filename ); if ( rc != 0 ) { OUTMSG(( "ArgsParamValue( %d ) failed: %R\n", i, rc )); } else { OUTMSG(( "file to read : '%s'\n", filename )); rc = perform_test( dir, filename, position, pos2, count, qsize, bsize, csize ); } } KDirectoryRelease( dir ); } } ArgsWhack ( args ); } return rc; }
static void foreach_test_func(const gchar* testfile, gpointer user_data) { test_result* result; xmlDocPtr doc; xmlNodePtr root; xmlNodePtr child; GSList* requests; InfTextChunk* initial; GSList* users; guint max_total_log_size; GError* error; gboolean res; /* Only process XML files, not the Makefiles or other stuff */ if(!g_str_has_suffix(testfile, ".xml")) return; result = (test_result*)user_data; doc = xmlParseFile(testfile); requests = NULL; initial = NULL; users = NULL; max_total_log_size = 0; error = NULL; printf("%s... ", testfile); fflush(stdout); ++ result->total; if(doc != NULL) { root = xmlDocGetRootElement(doc); for(child = root->children; child != NULL; child = child->next) { if(child->type != XML_ELEMENT_NODE) continue; if(strcmp((const char*)child->name, "log") == 0) { res = inf_xml_util_get_attribute_uint_required( child, "size", &max_total_log_size, &error ); if(!res) break; } else if(strcmp((const char*)child->name, "initial-buffer") == 0) { if(initial != NULL) inf_text_chunk_free(initial); initial = inf_test_util_parse_buffer(child, &error); if(initial == NULL) break; } else if(strcmp((const char*)child->name, "user") == 0) { if(inf_test_util_parse_user(child, &users, &error) == FALSE) break; } else if(strcmp((const char*)child->name, "request") == 0 || strcmp((const char*)child->name, "verify") == 0) { requests = g_slist_prepend(requests, child); } else { g_set_error( &error, inf_test_util_parse_error_quark(), INF_TEST_UTIL_PARSE_ERROR_UNEXPECTED_NODE, "Node '%s' unexpected", (const gchar*)child->name ); break; } } if(error != NULL) { printf("Failed to parse: %s\n", error->message); g_error_free(error); xmlFreeDoc(doc); g_slist_free(requests); if(initial != NULL) inf_text_chunk_free(initial); g_slist_free(users); } else { g_assert(initial != NULL); requests = g_slist_reverse(requests); if(perform_test(max_total_log_size, initial, users, requests, &error) == TRUE) { ++ result->passed; printf("OK\n"); } else { printf("FAILED (%s)\n", error->message); g_error_free(error); } xmlFreeDoc(doc); g_slist_free(requests); inf_text_chunk_free(initial); g_slist_free(users); } } }
/***************************************************************************** ** ** TEST10_BRANCH_ID: test transport failure in TRYING state. ** TEST11_BRANCH_ID: test transport failure in PROCEEDING state. ** TEST12_BRANCH_ID: test transport failure in CONNECTED state. ** TEST13_BRANCH_ID: test transport failure in CONFIRMED state. ** ***************************************************************************** */ static int tsx_transport_failure_test(void) { struct test_desc { int transport_delay; int fail_delay; char *branch_id; char *title; } tests[] = { { 0, 10, TEST10_BRANCH_ID, "test10: failed transport in TRYING state (no delay)" }, { 50, 10, TEST10_BRANCH_ID, "test10: failed transport in TRYING state (50 ms delay)" }, { 0, 1500, TEST11_BRANCH_ID, "test11: failed transport in PROCEEDING state (no delay)" }, { 50, 1500, TEST11_BRANCH_ID, "test11: failed transport in PROCEEDING state (50 ms delay)" }, { 0, 2500, TEST12_BRANCH_ID, "test12: failed transport in COMPLETED state (no delay)" }, { 50, 2500, TEST12_BRANCH_ID, "test12: failed transport in COMPLETED state (50 ms delay)" }, }; int i, status; for (i=0; i<(int)PJ_ARRAY_SIZE(tests); ++i) { pj_time_val fail_time, end_test, now; PJ_LOG(3,(THIS_FILE, " %s", tests[i].title)); pjsip_loop_set_failure(loop, 0, NULL); pjsip_loop_set_delay(loop, tests[i].transport_delay); status = perform_test(TARGET_URI, FROM_URI, tests[i].branch_id, 0, &pjsip_invite_method, 1, 0, 1); if (status && status != TEST_TIMEOUT_ERROR) return status; if (!status) { PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); return -40; } pj_gettimeofday(&fail_time); fail_time.msec += tests[i].fail_delay; pj_time_val_normalize(&fail_time); do { pj_time_val interval = { 0, 1 }; pj_gettimeofday(&now); pjsip_endpt_handle_events(endpt, &interval); } while (PJ_TIME_VAL_LT(now, fail_time)); pjsip_loop_set_failure(loop, 1, NULL); end_test = now; end_test.sec += 5; do { pj_time_val interval = { 0, 1 }; pj_gettimeofday(&now); pjsip_endpt_handle_events(endpt, &interval); } while (!test_complete && PJ_TIME_VAL_LT(now, end_test)); if (test_complete == 0) { PJ_LOG(3,(THIS_FILE, " error: test has timed out")); return -41; } if (test_complete != 1) return test_complete; } return 0; }
int main(int argc, char *argv[]) { pj_caching_pool cp; pjmedia_endpt *med_endpt; int id = -1, verbose = 0; int clock_rate = 8000; int frame = -1; int channel = 1; struct pj_getopt_option long_options[] = { { "id", 1, 0, 'i' }, { "rate", 1, 0, 'r' }, { "frame", 1, 0, 'f' }, { "channel", 1, 0, 'n' }, { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { NULL, 0, 0, 0 } }; int c, option_index; pj_status_t status; /* Init pjlib */ status = pj_init(); PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* * Initialize media endpoint. * This will implicitly initialize PJMEDIA too. */ status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Print devices */ enum_devices(); /* Parse options */ pj_optind = 0; while((c=pj_getopt_long(argc,argv, "i:r:f:n:vh", long_options, &option_index))!=-1) { switch (c) { case 'i': id = atoi(pj_optarg); break; case 'r': clock_rate = atoi(pj_optarg); break; case 'f': frame = atoi(pj_optarg); break; case 'n': channel = atoi(pj_optarg); break; case 'v': verbose = 1; break; case 'h': puts(desc); return 0; break; default: printf("Error: invalid options %s\n", argv[pj_optind-1]); puts(desc); return 1; } } if (pj_optind != argc) { printf("Error: invalid options\n"); puts(desc); return 1; } if (!verbose) pj_log_set_level(3); if (frame == -1) frame = 10 * clock_rate / 1000; status = perform_test(get_dev_name(id), id, PJMEDIA_DIR_CAPTURE_PLAYBACK, clock_rate, frame, channel, verbose); if (status != 0) return 1; return 0; }