File: test_ethdev_api.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (188 lines) | stat: -rw-r--r-- 5,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (C) 2023, Advanced Micro Devices, Inc.
 */

#include <rte_log.h>
#include <rte_ethdev.h>

#include <rte_test.h>
#include "test.h"

#define NUM_RXQ	2
#define NUM_TXQ	2
#define NUM_RXD 512
#define NUM_TXD 512
#define NUM_MBUF 1024
#define MBUF_CACHE_SIZE 256

static int32_t
ethdev_api_queue_status(void)
{
	struct rte_eth_dev_info dev_info;
	struct rte_eth_rxq_info rx_qinfo;
	struct rte_eth_txq_info tx_qinfo;
	struct rte_mempool *mbuf_pool;
	struct rte_eth_conf eth_conf;
	uint16_t port_id;
	int ret;

	if (rte_eth_dev_count_avail() == 0)
		return TEST_SKIPPED;

	mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUF, MBUF_CACHE_SIZE, 0,
			RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());

	RTE_ETH_FOREACH_DEV(port_id) {
		memset(&eth_conf, 0, sizeof(eth_conf));
		ret = rte_eth_dev_configure(port_id, NUM_RXQ, NUM_TXQ, &eth_conf);
		TEST_ASSERT(ret == 0,
			"Port(%u) failed to configure.\n", port_id);

		/* RxQ setup */
		for (uint16_t queue_id = 0; queue_id < NUM_RXQ; queue_id++) {
			ret = rte_eth_rx_queue_setup(port_id, queue_id, NUM_RXD,
				rte_socket_id(), NULL,  mbuf_pool);
			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to setup RxQ.\n",
				port_id, queue_id);
		}

		/* TxQ setup */
		for (uint16_t queue_id = 0; queue_id < NUM_TXQ; queue_id++) {
			ret = rte_eth_tx_queue_setup(port_id, queue_id, NUM_TXD,
				rte_socket_id(), NULL);
			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to setup TxQ.\n",
				port_id, queue_id);
		}

		ret = rte_eth_dev_info_get(port_id, &dev_info);
		TEST_ASSERT(ret == 0,
			"Port(%u) failed to get dev info.\n", port_id);

		/* Initial RxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
			ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get RxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED,
				"Wrong initial Rx queue(%u) state(%d)\n",
				queue_id, rx_qinfo.queue_state);
		}

		/* Initial TxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
			ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get TxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED,
				"Wrong initial Tx queue(%u) state(%d)\n",
				queue_id, tx_qinfo.queue_state);
		}

		ret = rte_eth_dev_start(port_id);
		TEST_ASSERT(ret == 0,
			"Port(%u) failed to start.\n", port_id);

		/* Started RxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
			ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get RxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED,
				"Wrong started Rx queue(%u) state(%d)\n",
				queue_id, rx_qinfo.queue_state);
		}

		/* Started TxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
			ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get TxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STARTED,
				"Wrong started Tx queue(%u) state(%d)\n",
				queue_id, tx_qinfo.queue_state);
		}

		ret = rte_eth_dev_stop(port_id);
		TEST_ASSERT(ret == 0,
			"Port(%u) failed to stop.\n", port_id);

		/* Stopped RxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_rx_queues; queue_id++) {
			ret = rte_eth_rx_queue_info_get(port_id, queue_id, &rx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get RxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(rx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED,
				"Wrong stopped Rx queue(%u) state(%d)\n",
				queue_id, rx_qinfo.queue_state);
		}

		/* Stopped TxQ */
		for (uint16_t queue_id = 0; queue_id < dev_info.nb_tx_queues; queue_id++) {
			ret = rte_eth_tx_queue_info_get(port_id, queue_id, &tx_qinfo);
			if (ret == -ENOTSUP)
				continue;

			TEST_ASSERT(ret == 0,
				"Port(%u), queue(%u) failed to get TxQ info.\n",
				port_id, queue_id);

			TEST_ASSERT(tx_qinfo.queue_state == RTE_ETH_QUEUE_STATE_STOPPED,
				"Wrong stopped Tx queue(%u) state(%d)\n",
				queue_id, tx_qinfo.queue_state);
		}
	}

	return TEST_SUCCESS;
}

static struct unit_test_suite ethdev_api_testsuite = {
	.suite_name = "ethdev API tests",
	.setup = NULL,
	.teardown = NULL,
	.unit_test_cases = {
		TEST_CASE(ethdev_api_queue_status),
		/* TODO: Add deferred_start queue status test */
		TEST_CASES_END() /**< NULL terminate unit test array */
	}
};

static int
test_ethdev_api(void)
{
	rte_log_set_global_level(RTE_LOG_DEBUG);
	rte_log_set_level(RTE_LOGTYPE_EAL, RTE_LOG_DEBUG);

	return unit_test_suite_runner(&ethdev_api_testsuite);
}

/* TODO: Make part of the fast test suite, `REGISTER_FAST_TEST()`,
 *       when all drivers complies to the queue state requirement
 */
REGISTER_TEST_COMMAND(ethdev_api, test_ethdev_api);