Branch data Line data Source code
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 : 0 : 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 [ # # ]: 0 : if (rte_eth_dev_count_avail() == 0)
30 : : return TEST_SKIPPED;
31 : :
32 : 0 : mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUF, MBUF_CACHE_SIZE, 0,
33 : 0 : RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
34 : :
35 [ # # ]: 0 : RTE_ETH_FOREACH_DEV(port_id) {
36 : : memset(ð_conf, 0, sizeof(eth_conf));
37 : 0 : ret = rte_eth_dev_configure(port_id, NUM_RXQ, NUM_TXQ, ð_conf);
38 [ # # ]: 0 : TEST_ASSERT(ret == 0,
39 : : "Port(%u) failed to configure.\n", port_id);
40 : :
41 : : /* RxQ setup */
42 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < NUM_RXQ; queue_id++) {
43 : 0 : ret = rte_eth_rx_queue_setup(port_id, queue_id, NUM_RXD,
44 : : rte_socket_id(), NULL, mbuf_pool);
45 [ # # ]: 0 : 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 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < NUM_TXQ; queue_id++) {
52 : 0 : ret = rte_eth_tx_queue_setup(port_id, queue_id, NUM_TXD,
53 : : rte_socket_id(), NULL);
54 [ # # ]: 0 : TEST_ASSERT(ret == 0,
55 : : "Port(%u), queue(%u) failed to setup TxQ.\n",
56 : : port_id, queue_id);
57 : : }
58 : :
59 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
60 [ # # ]: 0 : TEST_ASSERT(ret == 0,
61 : : "Port(%u) failed to get dev info.\n", port_id);
62 : :
63 : : /* Initial RxQ */
64 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
65 : 0 : ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
66 [ # # ]: 0 : if (ret == -ENOTSUP)
67 : 0 : continue;
68 : :
69 [ # # ]: 0 : TEST_ASSERT(ret == 0,
70 : : "Port(%u), queue(%u) failed to get RxQ info.\n",
71 : : port_id, queue_id);
72 : :
73 [ # # ]: 0 : 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 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
80 : 0 : ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
81 [ # # ]: 0 : if (ret == -ENOTSUP)
82 : 0 : continue;
83 : :
84 [ # # ]: 0 : TEST_ASSERT(ret == 0,
85 : : "Port(%u), queue(%u) failed to get TxQ info.\n",
86 : : port_id, queue_id);
87 : :
88 [ # # ]: 0 : 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 : 0 : ret = rte_eth_dev_start(port_id);
94 [ # # ]: 0 : TEST_ASSERT(ret == 0,
95 : : "Port(%u) failed to start.\n", port_id);
96 : :
97 : : /* Started RxQ */
98 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
99 : 0 : ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
100 [ # # ]: 0 : if (ret == -ENOTSUP)
101 : 0 : continue;
102 : :
103 [ # # ]: 0 : TEST_ASSERT(ret == 0,
104 : : "Port(%u), queue(%u) failed to get RxQ info.\n",
105 : : port_id, queue_id);
106 : :
107 [ # # ]: 0 : 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 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
114 : 0 : ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
115 [ # # ]: 0 : if (ret == -ENOTSUP)
116 : 0 : continue;
117 : :
118 [ # # ]: 0 : TEST_ASSERT(ret == 0,
119 : : "Port(%u), queue(%u) failed to get TxQ info.\n",
120 : : port_id, queue_id);
121 : :
122 [ # # ]: 0 : 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 : 0 : ret = rte_eth_dev_stop(port_id);
128 [ # # ]: 0 : TEST_ASSERT(ret == 0,
129 : : "Port(%u) failed to stop.\n", port_id);
130 : :
131 : : /* Stopped RxQ */
132 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
133 : 0 : ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
134 [ # # ]: 0 : if (ret == -ENOTSUP)
135 : 0 : continue;
136 : :
137 [ # # ]: 0 : TEST_ASSERT(ret == 0,
138 : : "Port(%u), queue(%u) failed to get RxQ info.\n",
139 : : port_id, queue_id);
140 : :
141 [ # # ]: 0 : 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 [ # # ]: 0 : for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
148 : 0 : ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
149 [ # # ]: 0 : if (ret == -ENOTSUP)
150 : 0 : continue;
151 : :
152 [ # # ]: 0 : TEST_ASSERT(ret == 0,
153 : : "Port(%u), queue(%u) failed to get TxQ info.\n",
154 : : port_id, queue_id);
155 : :
156 [ # # ]: 0 : 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 : 0 : test_ethdev_api(void)
178 : : {
179 : 0 : rte_log_set_global_level(RTE_LOG_DEBUG);
180 : 0 : rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);
181 : :
182 : 0 : 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 : 252 : REGISTER_TEST_COMMAND(ethdev_api, test_ethdev_api);
|