void test_benchmark_queue(int argc, char **argv) { struct pg_error *error = NULL; struct pg_brick *queue_enter; struct pg_brick *queue_exit; struct pg_bench bench; struct pg_bench_stats stats; struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}}; struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}}; uint32_t len; queue_enter = pg_queue_new("enter", 10, &error); if (error) { pg_error_print(error); g_assert(0); } queue_exit = pg_queue_new("enter", 10, &error); if (error) { pg_error_print(error); g_assert(0); } if (pg_queue_friend(queue_enter, queue_exit, &error)) { pg_error_print(error); g_assert(0); } g_assert(!pg_bench_init(&bench, "queue", argc, argv, &error)); bench.input_brick = queue_enter; bench.input_side = WEST_SIDE; bench.output_brick = queue_exit; bench.output_side = WEST_SIDE; bench.output_poll = true; bench.max_burst_cnt = 1000000; bench.count_brick = NULL; bench.pkts_nb = 64; bench.pkts_mask = pg_mask_firsts(64); bench.pkts = pg_packets_create(bench.pkts_mask); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac1, &mac2, ETHER_TYPE_IPv4); len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1400; pg_packets_append_ipv4( bench.pkts, bench.pkts_mask, 0x000000EE, 0x000000CC, len, 17); bench.pkts = pg_packets_append_udp( bench.pkts, bench.pkts_mask, 1000, 2000, 1400); bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400); g_assert(!pg_bench_run(&bench, &stats, &error)); pg_bench_print(&stats); pg_packets_free(bench.pkts, bench.pkts_mask); pg_brick_destroy(queue_enter); pg_brick_destroy(queue_exit); }
static void test_brick_verify_re_link_monopole(void) { struct pg_brick *west_brick, *east_brick; struct pg_error *error = NULL; west_brick = pg_queue_new("q1", 1, &error); g_assert(!error); east_brick = pg_queue_new("q2", 1, &error); g_assert(!error); /* We link the 2 bricks */ pg_brick_link(west_brick, east_brick, &error); g_assert(!error); /* We unlink them */ pg_brick_unlink(west_brick, &error); g_assert(!error); /* We relink them to make sure unlink works */ pg_brick_link(west_brick, east_brick, &error); g_assert(!error); pg_brick_destroy(west_brick); pg_brick_destroy(east_brick); }
static void test_queue_lifecycle(void) { struct pg_error *error = NULL; struct pg_brick *brick; struct pg_queue_state *state; brick = pg_queue_new("test_queue", 0, &error); g_assert(brick); CHECK_ERROR(error); state = pg_brick_get_state(brick, struct pg_queue_state); g_assert(state->rx_max_size == 10); pg_brick_destroy(brick); brick = pg_queue_new("test_queue", 1, &error); g_assert(brick); CHECK_ERROR(error); state = pg_brick_get_state(brick, struct pg_queue_state); g_assert(state->rx_max_size == 1); pg_brick_destroy(brick); CHECK_ERROR(error); }
static void test_queue_friend(void) { struct pg_error *error = NULL; struct pg_brick *q1, *q2, *q3; q1 = pg_queue_new("q1", 1, &error); CHECK_ERROR(error); q2 = pg_queue_new("q2", 1, &error); CHECK_ERROR(error); q3 = pg_queue_new("q3", 1, &error); CHECK_ERROR(error); /* classic scenario */ g_assert(!pg_queue_get_friend(q1)); g_assert(!pg_queue_get_friend(q2)); g_assert(!pg_queue_friend(q1, q2, &error)); CHECK_ERROR(error); g_assert(pg_queue_get_friend(q1) == q2); g_assert(pg_queue_are_friend(q1, q2)); g_assert(pg_queue_get_friend(q2) == q1); g_assert(pg_queue_are_friend(q2, q1)); pg_queue_unfriend(q1); g_assert(!pg_queue_get_friend(q1)); g_assert(!pg_queue_are_friend(q1, q2)); g_assert(!pg_queue_get_friend(q2)); g_assert(!pg_queue_are_friend(q2, q1)); /* same but unfriend with second brick */ g_assert(!pg_queue_friend(q1, q2, &error)); CHECK_ERROR(error); g_assert(pg_queue_are_friend(q1, q2)); g_assert(pg_queue_are_friend(q2, q1)); pg_queue_unfriend(q2); g_assert(!pg_queue_get_friend(q1)); g_assert(!pg_queue_get_friend(q2)); /* friend with itself */ g_assert(!pg_queue_friend(q1, q1, &error)); CHECK_ERROR(error); g_assert(pg_queue_get_friend(q1) == q1); g_assert(pg_queue_are_friend(q1, q1)); pg_queue_unfriend(q1); g_assert(!pg_queue_get_friend(q1)); /* several unfriend ok ? (test should die if not) */ pg_queue_unfriend(q1); pg_queue_unfriend(q1); pg_queue_unfriend(q1); /* error if already friend */ g_assert(!pg_queue_friend(q1, q2, &error)); CHECK_ERROR(error); g_assert(pg_queue_friend(q1, q2, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; g_assert(pg_queue_friend(q2, q1, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; g_assert(pg_queue_friend(q1, q3, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; g_assert(pg_queue_friend(q2, q3, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; g_assert(pg_queue_friend(q3, q1, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; g_assert(pg_queue_friend(q3, q2, &error) == -1); g_assert(pg_error_is_set(&error)); pg_error_free(error); error = NULL; /* check that death break friendship */ pg_brick_decref(q1, &error); CHECK_ERROR(error); g_assert(!pg_queue_get_friend(q2)); /* ... and can be friend again */ g_assert(!pg_queue_friend(q2, q3, &error)); g_assert(pg_queue_are_friend(q2, q3)); g_assert(pg_queue_are_friend(q3, q2)); pg_brick_decref(q2, &error); CHECK_ERROR(error); pg_brick_decref(q3, &error); CHECK_ERROR(error); }
static void test_queue_reset(void) { # define NB_PKTS 64 struct pg_error *error = NULL; struct pg_brick *queue1, *queue2, *collect; struct rte_mbuf **result_pkts; struct rte_mbuf *pkts[NB_PKTS]; uint64_t pkts_mask, i, j; uint16_t count = 0; struct rte_mempool *mbuf_pool = pg_get_mempool(); /** * Burst packets in queue1 and test reset of queue1 * [queue1] ~ [queue2]----[collect] */ queue1 = pg_queue_new("q1", 10, &error); CHECK_ERROR(error); queue2 = pg_queue_new("q2", 10, &error); CHECK_ERROR(error); collect = pg_collect_new("collect", 1, 1, &error); CHECK_ERROR(error); pg_brick_link(queue2, collect, &error); CHECK_ERROR(error); g_assert(!pg_queue_friend(queue1, queue2, &error)); CHECK_ERROR(error); for (i = 0; i < NB_PKTS; i++) { pkts[i] = rte_pktmbuf_alloc(mbuf_pool); g_assert(pkts[i]); pkts[i]->udata64 = i; pg_set_mac_addrs(pkts[i], "F0:F1:F2:F3:F4:F5", "E0:E1:E2:E3:E4:E5"); } for (j = 0; j < 100; j++) { for (i = 0; i < NB_PKTS; i++) pkts[i]->udata64 = i * j; /* burst and reset */ pg_brick_burst_to_east(queue1, 0, pkts, pg_mask_firsts(NB_PKTS), &error); CHECK_ERROR(error); g_assert(pg_queue_pressure(queue1) > 0); g_assert(!pg_brick_reset(queue1, &error)); g_assert(pg_queue_get_friend(queue1) == NULL); g_assert(pg_queue_get_friend(queue2) == NULL); g_assert(pg_queue_pressure(queue1) == 0); g_assert(pg_queue_pressure(queue2) == 0); pg_brick_poll(queue2, &count, &error); g_assert(!error); g_assert(count == 0); /* refriend and burst ok */ g_assert(!pg_queue_friend(queue1, queue2, &error)); g_assert(!error); g_assert(pg_queue_are_friend(queue1, queue2)); g_assert(!error); pg_brick_burst_to_east(queue1, 0, pkts, pg_mask_firsts(NB_PKTS), &error); CHECK_ERROR(error); g_assert(pg_queue_pressure(queue1) > 0); pg_brick_poll(queue2, &count, &error); g_assert(count == NB_PKTS); result_pkts = pg_brick_west_burst_get(collect, &pkts_mask, &error); CHECK_ERROR(error); g_assert(pkts_mask == pg_mask_firsts(NB_PKTS)); for (i = 0; i < NB_PKTS; i++) { g_assert(result_pkts[i]); g_assert(result_pkts[i]->udata64 == i * j); } pg_brick_reset(collect, &error); CHECK_ERROR(error); } /* clean */ for (i = 0; i < NB_PKTS; i++) rte_pktmbuf_free(pkts[i]); pg_brick_decref(queue1, &error); CHECK_ERROR(error); pg_brick_decref(queue2, &error); CHECK_ERROR(error); pg_brick_decref(collect, &error); CHECK_ERROR(error); # undef NB_PKTS }