Lines Matching defs:test
9 * See test_xsk.sh for detailed information on test topology
12 * This test program contains two threads, each thread is single socket with
18 * These selftests test AF_XDP SKB and Native/DRV modes using veth
33 * are incremented. Within this test, the following statistics are tested:
118 #define busy_poll_string(test) (test)->ifobj_tx->busy_poll ? "BUSY-POLL " : ""
119 static char *mode_string(struct test_spec *test)
121 switch (test->mode) {
133 static void report_failure(struct test_spec *test)
135 if (test->fail)
138 ksft_test_result_fail("FAIL: %s %s%s\n", mode_string(test), busy_poll_string(test),
139 test->name);
140 test->fail = true;
381 static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
399 ifobj->pkt_stream = test->tx_pkt_stream_default;
403 ifobj->pkt_stream = test->rx_pkt_stream_default;
416 test->ifobj_tx = ifobj_tx;
417 test->ifobj_rx = ifobj_rx;
418 test->current_step = 0;
419 test->total_steps = 1;
420 test->nb_sockets = 1;
421 test->fail = false;
422 test->mtu = MAX_ETH_PKT_SIZE;
423 test->xdp_prog_rx = ifobj_rx->xdp_progs->progs.xsk_def_prog;
424 test->xskmap_rx = ifobj_rx->xdp_progs->maps.xsk;
425 test->xdp_prog_tx = ifobj_tx->xdp_progs->progs.xsk_def_prog;
426 test->xskmap_tx = ifobj_tx->xdp_progs->maps.xsk;
429 static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
436 tx_pkt_stream = test->tx_pkt_stream_default;
437 rx_pkt_stream = test->rx_pkt_stream_default;
438 memset(test, 0, sizeof(*test));
439 test->tx_pkt_stream_default = tx_pkt_stream;
440 test->rx_pkt_stream_default = rx_pkt_stream;
452 test->mode = mode;
453 __test_spec_init(test, ifobj_tx, ifobj_rx);
456 static void test_spec_reset(struct test_spec *test)
458 __test_spec_init(test, test->ifobj_tx, test->ifobj_rx);
461 static void test_spec_set_name(struct test_spec *test, const char *name)
463 strncpy(test->name, name, MAX_TEST_NAME_SIZE);
466 static void test_spec_set_xdp_prog(struct test_spec *test, struct bpf_program *xdp_prog_rx,
470 test->xdp_prog_rx = xdp_prog_rx;
471 test->xdp_prog_tx = xdp_prog_tx;
472 test->xskmap_rx = xskmap_rx;
473 test->xskmap_tx = xskmap_tx;
476 static int test_spec_set_mtu(struct test_spec *test, int mtu)
480 if (test->ifobj_rx->mtu != mtu) {
481 err = xsk_set_mtu(test->ifobj_rx->ifindex, mtu);
484 test->ifobj_rx->mtu = mtu;
486 if (test->ifobj_tx->mtu != mtu) {
487 err = xsk_set_mtu(test->ifobj_tx->ifindex, mtu);
490 test->ifobj_tx->mtu = mtu;
527 static void pkt_stream_restore_default(struct test_spec *test)
529 struct pkt_stream *tx_pkt_stream = test->ifobj_tx->pkt_stream;
530 struct pkt_stream *rx_pkt_stream = test->ifobj_rx->pkt_stream;
532 if (tx_pkt_stream != test->tx_pkt_stream_default) {
533 pkt_stream_delete(test->ifobj_tx->pkt_stream);
534 test->ifobj_tx->pkt_stream = test->tx_pkt_stream_default;
537 if (rx_pkt_stream != test->rx_pkt_stream_default) {
538 pkt_stream_delete(test->ifobj_rx->pkt_stream);
539 test->ifobj_rx->pkt_stream = test->rx_pkt_stream_default;
641 static void pkt_stream_replace(struct test_spec *test, u32 nb_pkts, u32 pkt_len)
645 pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, nb_pkts, pkt_len);
646 test->ifobj_tx->pkt_stream = pkt_stream;
647 pkt_stream = pkt_stream_generate(test->ifobj_rx->umem, nb_pkts, pkt_len);
648 test->ifobj_rx->pkt_stream = pkt_stream;
665 static void pkt_stream_replace_half(struct test_spec *test, u32 pkt_len, int offset)
667 __pkt_stream_replace_half(test->ifobj_tx, pkt_len, offset);
668 __pkt_stream_replace_half(test->ifobj_rx, pkt_len, offset);
671 static void pkt_stream_receive_half(struct test_spec *test)
673 struct xsk_umem_info *umem = test->ifobj_rx->umem;
674 struct pkt_stream *pkt_stream = test->ifobj_tx->pkt_stream;
677 test->ifobj_rx->pkt_stream = pkt_stream_generate(umem, pkt_stream->nb_pkts,
679 pkt_stream = test->ifobj_rx->pkt_stream;
760 static void pkt_stream_generate_custom(struct test_spec *test, struct pkt *pkts, u32 nb_pkts)
764 pkt_stream = __pkt_stream_generate_custom(test->ifobj_tx, pkts, nb_pkts, true);
765 test->ifobj_tx->pkt_stream = pkt_stream;
767 pkt_stream = __pkt_stream_generate_custom(test->ifobj_rx, pkts, nb_pkts, false);
768 test->ifobj_rx->pkt_stream = pkt_stream;
967 static int receive_pkts(struct test_spec *test, struct pollfd *fds)
970 struct pkt_stream *pkt_stream = test->ifobj_rx->pkt_stream;
971 struct xsk_socket_info *xsk = test->ifobj_rx->xsk;
973 struct ifobject *ifobj = test->ifobj_rx;
1003 if (!is_umem_valid(test->ifobj_tx))
1216 static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
1219 bool timeout = !is_umem_valid(test->ifobj_rx);
1228 if (ret == TEST_CONTINUE && !test->fail)
1230 if ((ret || test->fail) && !timeout)
1276 * packet which is not the final packet sent in this test (valid and
1351 static void xsk_configure_socket(struct test_spec *test, struct ifobject *ifobject,
1356 for (i = 0; i < test->nb_sockets; i++) {
1376 static void thread_common_ops_tx(struct test_spec *test, struct ifobject *ifobject)
1378 xsk_configure_socket(test, ifobject, test->ifobj_rx->umem, true);
1380 ifobject->xskmap = test->ifobj_rx->xskmap;
1381 memcpy(ifobject->umem, test->ifobj_rx->umem, sizeof(struct xsk_umem_info));
1429 static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
1451 xsk_configure_socket(test, ifobject, ifobject->umem, false);
1467 struct test_spec *test = (struct test_spec *)arg;
1468 struct ifobject *ifobject = test->ifobj_tx;
1471 if (test->current_step == 1) {
1473 thread_common_ops(test, ifobject);
1475 thread_common_ops_tx(test, ifobject);
1480 err = send_pkts(test, ifobject);
1485 report_failure(test);
1492 struct test_spec *test = (struct test_spec *)arg;
1493 struct ifobject *ifobject = test->ifobj_rx;
1497 if (test->current_step == 1) {
1498 thread_common_ops(test, ifobject);
1513 err = receive_pkts(test, &fds);
1518 report_failure(test);
1545 static bool xdp_prog_changed_rx(struct test_spec *test)
1547 struct ifobject *ifobj = test->ifobj_rx;
1549 return ifobj->xdp_prog != test->xdp_prog_rx || ifobj->mode != test->mode;
1552 static bool xdp_prog_changed_tx(struct test_spec *test)
1554 struct ifobject *ifobj = test->ifobj_tx;
1556 return ifobj->xdp_prog != test->xdp_prog_tx || ifobj->mode != test->mode;
1582 static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
1585 if (xdp_prog_changed_rx(test))
1586 xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
1591 if (xdp_prog_changed_tx(test))
1592 xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
1595 static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
1601 if (test->mtu > MAX_ETH_PKT_SIZE) {
1602 if (test->mode == TEST_MODE_ZC && (!ifobj1->multi_buff_zc_supp ||
1607 if (test->mode != TEST_MODE_ZC && (!ifobj1->multi_buff_supp ||
1613 err = test_spec_set_mtu(test, test->mtu);
1625 test->current_step++;
1631 pthread_create(&t0, NULL, ifobj1->func_ptr, test);
1639 pthread_create(&t1, NULL, ifobj2->func_ptr, test);
1649 if (test->total_steps == test->current_step || test->fail) {
1658 return !!test->fail;
1661 static int testapp_validate_traffic(struct test_spec *test)
1663 struct ifobject *ifobj_rx = test->ifobj_rx;
1664 struct ifobject *ifobj_tx = test->ifobj_tx;
1672 xsk_attach_xdp_progs(test, ifobj_rx, ifobj_tx);
1673 return __testapp_validate_traffic(test, ifobj_rx, ifobj_tx);
1676 static int testapp_validate_traffic_single_thread(struct test_spec *test, struct ifobject *ifobj)
1678 return __testapp_validate_traffic(test, ifobj, NULL);
1681 static int testapp_teardown(struct test_spec *test)
1685 test_spec_set_name(test, "TEARDOWN");
1687 if (testapp_validate_traffic(test))
1689 test_spec_reset(test);
1707 static int testapp_bidi(struct test_spec *test)
1711 test_spec_set_name(test, "BIDIRECTIONAL");
1712 test->ifobj_tx->rx_on = true;
1713 test->ifobj_rx->tx_on = true;
1714 test->total_steps = 2;
1715 if (testapp_validate_traffic(test))
1719 swap_directions(&test->ifobj_rx, &test->ifobj_tx);
1720 res = __testapp_validate_traffic(test, test->ifobj_rx, test->ifobj_tx);
1722 swap_directions(&test->ifobj_rx, &test->ifobj_tx);
1740 static int testapp_bpf_res(struct test_spec *test)
1742 test_spec_set_name(test, "BPF_RES");
1743 test->total_steps = 2;
1744 test->nb_sockets = 2;
1745 if (testapp_validate_traffic(test))
1748 swap_xsk_resources(test->ifobj_tx, test->ifobj_rx);
1749 return testapp_validate_traffic(test);
1752 static int testapp_headroom(struct test_spec *test)
1754 test_spec_set_name(test, "UMEM_HEADROOM");
1755 test->ifobj_rx->umem->frame_headroom = UMEM_HEADROOM_TEST_SIZE;
1756 return testapp_validate_traffic(test);
1759 static int testapp_stats_rx_dropped(struct test_spec *test)
1761 test_spec_set_name(test, "STAT_RX_DROPPED");
1762 if (test->mode == TEST_MODE_ZC) {
1763 ksft_test_result_skip("Can not run RX_DROPPED test for ZC mode\n");
1767 pkt_stream_replace_half(test, MIN_PKT_SIZE * 4, 0);
1768 test->ifobj_rx->umem->frame_headroom = test->ifobj_rx->umem->frame_size -
1770 pkt_stream_receive_half(test);
1771 test->ifobj_rx->validation_func = validate_rx_dropped;
1772 return testapp_validate_traffic(test);
1775 static int testapp_stats_tx_invalid_descs(struct test_spec *test)
1777 test_spec_set_name(test, "STAT_TX_INVALID");
1778 pkt_stream_replace_half(test, XSK_UMEM__INVALID_FRAME_SIZE, 0);
1779 test->ifobj_tx->validation_func = validate_tx_invalid_descs;
1780 return testapp_validate_traffic(test);
1783 static int testapp_stats_rx_full(struct test_spec *test)
1785 test_spec_set_name(test, "STAT_RX_FULL");
1786 pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
1787 test->ifobj_rx->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1790 test->ifobj_rx->xsk->rxqsize = DEFAULT_UMEM_BUFFERS;
1791 test->ifobj_rx->release_rx = false;
1792 test->ifobj_rx->validation_func = validate_rx_full;
1793 return testapp_validate_traffic(test);
1796 static int testapp_stats_fill_empty(struct test_spec *test)
1798 test_spec_set_name(test, "STAT_RX_FILL_EMPTY");
1799 pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
1800 test->ifobj_rx->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1803 test->ifobj_rx->use_fill_ring = false;
1804 test->ifobj_rx->validation_func = validate_fill_empty;
1805 return testapp_validate_traffic(test);
1808 static int testapp_unaligned(struct test_spec *test)
1810 test_spec_set_name(test, "UNALIGNED_MODE");
1811 test->ifobj_tx->umem->unaligned_mode = true;
1812 test->ifobj_rx->umem->unaligned_mode = true;
1814 pkt_stream_replace_half(test, MIN_PKT_SIZE, -MIN_PKT_SIZE / 2);
1816 return testapp_validate_traffic(test);
1819 static int testapp_unaligned_mb(struct test_spec *test)
1821 test_spec_set_name(test, "UNALIGNED_MODE_9K");
1822 test->mtu = MAX_ETH_JUMBO_SIZE;
1823 test->ifobj_tx->umem->unaligned_mode = true;
1824 test->ifobj_rx->umem->unaligned_mode = true;
1825 pkt_stream_replace(test, DEFAULT_PKT_CNT, MAX_ETH_JUMBO_SIZE);
1826 return testapp_validate_traffic(test);
1829 static int testapp_single_pkt(struct test_spec *test)
1833 pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts));
1834 return testapp_validate_traffic(test);
1837 static int testapp_multi_buffer(struct test_spec *test)
1839 test_spec_set_name(test, "RUN_TO_COMPLETION_9K_PACKETS");
1840 test->mtu = MAX_ETH_JUMBO_SIZE;
1841 pkt_stream_replace(test, DEFAULT_PKT_CNT, MAX_ETH_JUMBO_SIZE);
1843 return testapp_validate_traffic(test);
1846 static int testapp_invalid_desc_mb(struct test_spec *test)
1848 struct xsk_umem_info *umem = test->ifobj_tx->umem;
1881 test->mtu = MAX_ETH_JUMBO_SIZE;
1882 pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts));
1883 return testapp_validate_traffic(test);
1886 static int testapp_invalid_desc(struct test_spec *test)
1888 struct xsk_umem_info *umem = test->ifobj_tx->umem;
1921 if (test->ifobj_tx->shared_umem) {
1927 pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts));
1928 return testapp_validate_traffic(test);
1931 static int testapp_xdp_drop(struct test_spec *test)
1933 struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs;
1934 struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
1936 test_spec_set_name(test, "XDP_DROP_HALF");
1937 test_spec_set_xdp_prog(test, skel_rx->progs.xsk_xdp_drop, skel_tx->progs.xsk_xdp_drop,
1940 pkt_stream_receive_half(test);
1941 return testapp_validate_traffic(test);
1944 static int testapp_xdp_metadata_count(struct test_spec *test)
1946 struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs;
1947 struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
1952 test_spec_set_xdp_prog(test, skel_rx->progs.xsk_xdp_populate_metadata,
1955 test->ifobj_rx->use_metadata = true;
1964 return testapp_validate_traffic(test);
1967 static int testapp_poll_txq_tmout(struct test_spec *test)
1969 test_spec_set_name(test, "POLL_TXQ_FULL");
1971 test->ifobj_tx->use_poll = true;
1973 test->ifobj_tx->umem->frame_size = 2048;
1974 pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048);
1975 return testapp_validate_traffic_single_thread(test, test->ifobj_tx);
1978 static int testapp_poll_rxq_tmout(struct test_spec *test)
1980 test_spec_set_name(test, "POLL_RXQ_EMPTY");
1981 test->ifobj_rx->use_poll = true;
1982 return testapp_validate_traffic_single_thread(test, test->ifobj_rx);
1985 static int testapp_too_many_frags(struct test_spec *test)
1990 test_spec_set_name(test, "TOO_MANY_FRAGS");
1991 if (test->mode == TEST_MODE_ZC)
1992 max_frags = test->ifobj_tx->xdp_zc_max_segs;
1996 test->mtu = MAX_ETH_JUMBO_SIZE;
2023 pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2);
2024 return testapp_validate_traffic(test);
2041 /* Simple test */
2094 static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_type type)
2100 ret = testapp_stats_rx_dropped(test);
2103 ret = testapp_stats_tx_invalid_descs(test);
2106 ret = testapp_stats_rx_full(test);
2109 ret = testapp_stats_fill_empty(test);
2112 ret = testapp_teardown(test);
2115 ret = testapp_bidi(test);
2118 ret = testapp_bpf_res(test);
2121 test_spec_set_name(test, "RUN_TO_COMPLETION");
2122 ret = testapp_validate_traffic(test);
2125 ret = testapp_multi_buffer(test);
2128 test_spec_set_name(test, "RUN_TO_COMPLETION_SINGLE_PKT");
2129 ret = testapp_single_pkt(test);
2132 test_spec_set_name(test, "RUN_TO_COMPLETION_2K_FRAME_SIZE");
2133 test->ifobj_tx->umem->frame_size = 2048;
2134 test->ifobj_rx->umem->frame_size = 2048;
2135 pkt_stream_replace(test, DEFAULT_PKT_CNT, MIN_PKT_SIZE);
2136 ret = testapp_validate_traffic(test);
2139 test->ifobj_rx->use_poll = true;
2140 test_spec_set_name(test, "POLL_RX");
2141 ret = testapp_validate_traffic(test);
2144 test->ifobj_tx->use_poll = true;
2145 test_spec_set_name(test, "POLL_TX");
2146 ret = testapp_validate_traffic(test);
2149 ret = testapp_poll_txq_tmout(test);
2152 ret = testapp_poll_rxq_tmout(test);
2155 test_spec_set_name(test, "ALIGNED_INV_DESC");
2156 ret = testapp_invalid_desc(test);
2159 test_spec_set_name(test, "ALIGNED_INV_DESC_2K_FRAME_SIZE");
2160 test->ifobj_tx->umem->frame_size = 2048;
2161 test->ifobj_rx->umem->frame_size = 2048;
2162 ret = testapp_invalid_desc(test);
2165 test_spec_set_name(test, "UNALIGNED_INV_DESC");
2166 test->ifobj_tx->umem->unaligned_mode = true;
2167 test->ifobj_rx->umem->unaligned_mode = true;
2168 ret = testapp_invalid_desc(test);
2173 test_spec_set_name(test, "UNALIGNED_INV_DESC_4K1_FRAME_SIZE");
2175 test->ifobj_tx->umem->frame_size = 4001;
2176 test->ifobj_rx->umem->frame_size = 4001;
2177 test->ifobj_tx->umem->unaligned_mode = true;
2178 test->ifobj_rx->umem->unaligned_mode = true;
2179 /* This test exists to test descriptors that staddle the end of
2183 umem_size = test->ifobj_tx->umem->num_frames * test->ifobj_tx->umem->frame_size;
2186 ret = testapp_invalid_desc(test);
2190 test_spec_set_name(test, "ALIGNED_INV_DESC_MULTI_BUFF");
2191 ret = testapp_invalid_desc_mb(test);
2194 test_spec_set_name(test, "UNALIGNED_INV_DESC_MULTI_BUFF");
2195 test->ifobj_tx->umem->unaligned_mode = true;
2196 test->ifobj_rx->umem->unaligned_mode = true;
2197 ret = testapp_invalid_desc_mb(test);
2200 ret = testapp_unaligned(test);
2203 ret = testapp_unaligned_mb(test);
2206 ret = testapp_headroom(test);
2209 ret = testapp_xdp_drop(test);
2212 test_spec_set_name(test, "XDP_METADATA_COUNT");
2213 ret = testapp_xdp_metadata_count(test);
2216 test_spec_set_name(test, "XDP_METADATA_COUNT_MULTI_BUFF");
2217 test->mtu = MAX_ETH_JUMBO_SIZE;
2218 ret = testapp_xdp_metadata_count(test);
2221 ret = testapp_too_many_frags(test);
2228 ksft_test_result_pass("PASS: %s %s%s\n", mode_string(test), busy_poll_string(test),
2229 test->name);
2230 pkt_stream_restore_default(test);
2300 struct test_spec test;
2335 test_spec_init(&test, ifobj_tx, ifobj_rx, 0);
2340 test.tx_pkt_stream_default = tx_pkt_stream_default;
2341 test.rx_pkt_stream_default = rx_pkt_stream_default;
2347 test_spec_init(&test, ifobj_tx, ifobj_rx, i);
2348 run_pkt_test(&test, i, j);
2351 if (test.fail)