1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2023, Advanced Micro Devices, Inc. 3 */ 4 5 #include <rte_log.h> 6 #include <rte_ethdev.h> 7 8 #include <rte_test.h> 9 #include "test.h" 10 11 #define NUM_RXQ 2 12 #define NUM_TXQ 2 13 #define NUM_RXD 512 14 #define NUM_TXD 512 15 #define NUM_MBUF 1024 16 #define MBUF_CACHE_SIZE 256 17 18 static int32_t 19 ethdev_api_queue_status(void) 20 { 21 struct rte_eth_dev_info dev_info; 22 struct rte_eth_rxq_info rx_qinfo; 23 struct rte_eth_txq_info tx_qinfo; 24 struct rte_mempool *mbuf_pool; 25 struct rte_eth_conf eth_conf; 26 uint16_t port_id; 27 int ret; 28 29 if (rte_eth_dev_count_avail() == 0) 30 return TEST_SKIPPED; 31 32 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUF, MBUF_CACHE_SIZE, 0, 33 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); 34 35 RTE_ETH_FOREACH_DEV(port_id) { 36 memset(ð_conf, 0, sizeof(eth_conf)); 37 ret = rte_eth_dev_configure(port_id, NUM_RXQ, NUM_TXQ, ð_conf); 38 TEST_ASSERT(ret == 0, 39 "Port(%u) failed to configure.\n", port_id); 40 41 /* RxQ setup */ 42 for (uint16_t queue_id = 0; queue_id < NUM_RXQ; queue_id++) { 43 ret = rte_eth_rx_queue_setup(port_id, queue_id, NUM_RXD, 44 rte_socket_id(), NULL, mbuf_pool); 45 TEST_ASSERT(ret == 0, 46 "Port(%u), queue(%u) failed to setup RxQ.\n", 47 port_id, queue_id); 48 } 49 50 /* TxQ setup */ 51 for (uint16_t queue_id = 0; queue_id < NUM_TXQ; queue_id++) { 52 ret = rte_eth_tx_queue_setup(port_id, queue_id, NUM_TXD, 53 rte_socket_id(), NULL); 54 TEST_ASSERT(ret == 0, 55 "Port(%u), queue(%u) failed to setup TxQ.\n", 56 port_id, queue_id); 57 } 58 59 ret = rte_eth_dev_info_get(port_id, &dev_info); 60 TEST_ASSERT(ret == 0, 61 "Port(%u) failed to get dev info.\n", port_id); 62 63 /* Initial RxQ */ 64 for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { 65 ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); 66 if (ret == -ENOTSUP) 67 continue; 68 69 TEST_ASSERT(ret == 0, 70 "Port(%u), queue(%u) failed to get RxQ info.\n", 71 port_id, queue_id); 72 73 TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, 74 "Wrong initial Rx queue(%u) state(%d)\n", 75 queue_id, rx_qinfo.queue_state); 76 } 77 78 /* Initial TxQ */ 79 for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { 80 ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); 81 if (ret == -ENOTSUP) 82 continue; 83 84 TEST_ASSERT(ret == 0, 85 "Port(%u), queue(%u) failed to get TxQ info.\n", 86 port_id, queue_id); 87 88 TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, 89 "Wrong initial Tx queue(%u) state(%d)\n", 90 queue_id, tx_qinfo.queue_state); 91 } 92 93 ret = rte_eth_dev_start(port_id); 94 TEST_ASSERT(ret == 0, 95 "Port(%u) failed to start.\n", port_id); 96 97 /* Started RxQ */ 98 for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { 99 ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); 100 if (ret == -ENOTSUP) 101 continue; 102 103 TEST_ASSERT(ret == 0, 104 "Port(%u), queue(%u) failed to get RxQ info.\n", 105 port_id, queue_id); 106 107 TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED, 108 "Wrong started Rx queue(%u) state(%d)\n", 109 queue_id, rx_qinfo.queue_state); 110 } 111 112 /* Started TxQ */ 113 for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { 114 ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); 115 if (ret == -ENOTSUP) 116 continue; 117 118 TEST_ASSERT(ret == 0, 119 "Port(%u), queue(%u) failed to get TxQ info.\n", 120 port_id, queue_id); 121 122 TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED, 123 "Wrong started Tx queue(%u) state(%d)\n", 124 queue_id, tx_qinfo.queue_state); 125 } 126 127 ret = rte_eth_dev_stop(port_id); 128 TEST_ASSERT(ret == 0, 129 "Port(%u) failed to stop.\n", port_id); 130 131 /* Stopped RxQ */ 132 for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) { 133 ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo); 134 if (ret == -ENOTSUP) 135 continue; 136 137 TEST_ASSERT(ret == 0, 138 "Port(%u), queue(%u) failed to get RxQ info.\n", 139 port_id, queue_id); 140 141 TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, 142 "Wrong stopped Rx queue(%u) state(%d)\n", 143 queue_id, rx_qinfo.queue_state); 144 } 145 146 /* Stopped TxQ */ 147 for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) { 148 ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo); 149 if (ret == -ENOTSUP) 150 continue; 151 152 TEST_ASSERT(ret == 0, 153 "Port(%u), queue(%u) failed to get TxQ info.\n", 154 port_id, queue_id); 155 156 TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED, 157 "Wrong stopped Tx queue(%u) state(%d)\n", 158 queue_id, tx_qinfo.queue_state); 159 } 160 } 161 162 return TEST_SUCCESS; 163 } 164 165 static struct unit_test_suite ethdev_api_testsuite = { 166 .suite_name = "ethdev API tests", 167 .setup = NULL, 168 .teardown = NULL, 169 .unit_test_cases = { 170 TEST_CASE(ethdev_api_queue_status), 171 /* TODO: Add deferred_start queue status test */ 172 TEST_CASES_END() /**< NULL terminate unit test array */ 173 } 174 }; 175 176 static int 177 test_ethdev_api(void) 178 { 179 rte_log_set_global_level(RTE_LOG_DEBUG); 180 rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG); 181 182 return unit_test_suite_runner(ðdev_api_testsuite); 183 } 184 185 /* TODO: Make part of the fast test suite, `REGISTER_FAST_TEST()`, 186 * when all drivers complies to the queue state requirement 187 */ 188 REGISTER_TEST_COMMAND(ethdev_api, test_ethdev_api); 189