int main(int argc, char **argv) { int ret; odp_shm_t shm; int max_thrs; if (odp_init_global(NULL, NULL) != 0) LOG_ABORT("Failed global init.\n"); if (odp_init_local(ODP_THREAD_CONTROL) != 0) LOG_ABORT("Failed local init.\n"); shm = odp_shm_reserve("test_globals", sizeof(test_globals_t), ODP_CACHE_LINE_SIZE, 0); gbl_args = odp_shm_addr(shm); if (gbl_args == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args, 0, sizeof(test_globals_t)); max_thrs = odp_thread_count_max(); gbl_args->rx_stats_size = max_thrs * sizeof(pkt_rx_stats_t); gbl_args->tx_stats_size = max_thrs * sizeof(pkt_tx_stats_t); shm = odp_shm_reserve("test_globals.rx_stats", gbl_args->rx_stats_size, ODP_CACHE_LINE_SIZE, 0); gbl_args->rx_stats = odp_shm_addr(shm); if (gbl_args->rx_stats == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args->rx_stats, 0, gbl_args->rx_stats_size); shm = odp_shm_reserve("test_globals.tx_stats", gbl_args->tx_stats_size, ODP_CACHE_LINE_SIZE, 0); gbl_args->tx_stats = odp_shm_addr(shm); if (gbl_args->tx_stats == NULL) LOG_ABORT("Shared memory reserve failed.\n"); memset(gbl_args->tx_stats, 0, gbl_args->tx_stats_size); parse_args(argc, argv, &gbl_args->args); ret = test_init(); if (ret == 0) { ret = run_test(); test_term(); } return ret; }
/* * Process the results from a single fixed rate test run to determine whether * it passed or failed. Pass criteria are that the requested transmit packet * rate was achieved and that all of the transmitted packets were received. */ static int process_results(uint64_t expected_tx_cnt, test_status_t *status) { int fail = 0; uint64_t drops = 0; uint64_t rx_pkts = 0; uint64_t tx_pkts = 0; uint64_t attempted_pps; int i; char str[512]; int len = 0; for (i = 0; i < odp_thread_count_max(); ++i) { rx_pkts += gbl_args->rx_stats[i].s.rx_cnt; tx_pkts += gbl_args->tx_stats[i].s.tx_cnt; } if (rx_pkts == 0) { LOG_ERR("no packets received\n"); return -1; } if (tx_pkts < (expected_tx_cnt - (expected_tx_cnt / 100))) { /* failed to transmit packets at (99% of) requested rate */ fail = 1; } else if (tx_pkts > rx_pkts) { /* failed to receive all of the transmitted packets */ fail = 1; drops = tx_pkts - rx_pkts; } attempted_pps = status->pps_curr; len += snprintf(&str[len], sizeof(str) - 1 - len, "PPS: %-8" PRIu64 " ", attempted_pps); len += snprintf(&str[len], sizeof(str) - 1 - len, "Succeeded: %-4s ", fail ? "No" : "Yes"); len += snprintf(&str[len], sizeof(str) - 1 - len, "TxPkts: %-8" PRIu64 " ", tx_pkts); len += snprintf(&str[len], sizeof(str) - 1 - len, "RxPkts: %-8" PRIu64 " ", rx_pkts); len += snprintf(&str[len], sizeof(str) - 1 - len, "DropPkts: %-8" PRIu64 " ", drops); printf("%s\n", str); if (gbl_args->args.search == 0) { printf("Result: %s\n", fail ? "FAILED" : "PASSED"); return fail ? -1 : 0; } if (fail && (status->pps_fail == 0 || attempted_pps < status->pps_fail)) { status->pps_fail = attempted_pps; } else if (attempted_pps > status->pps_pass) { status->pps_pass = attempted_pps; } if (status->pps_fail == 0) { /* ramping up, double the previously attempted pps */ status->pps_curr *= 2; } else { /* set the new target to half way between the upper and lower * limits */ status->pps_curr = status->pps_pass + ((status->pps_fail - status->pps_pass) / 2); } /* stop once the pass and fail measurements are within range */ if ((status->pps_fail - status->pps_pass) < RATE_SEARCH_ACCURACY_PPS) { unsigned pkt_len = gbl_args->args.pkt_len + PKT_HDR_LEN; int mbps = (pkt_len * status->pps_pass * 8) / 1024 / 1024; printf("Maximum packet rate: %" PRIu64 " PPS (%d Mbps)\n", status->pps_pass, mbps); return 0; } return 1; }