xref: /dpdk/app/test/test_table_ports.c (revision 3c60274c0995a7a74c5550d2f5bbcfbd9d548515)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5*3c60274cSJie Zhou #ifndef RTE_EXEC_ENV_WINDOWS
6*3c60274cSJie Zhou 
7a9de470cSBruce Richardson #include "test_table_ports.h"
8a9de470cSBruce Richardson #include "test_table.h"
9a9de470cSBruce Richardson 
10a9de470cSBruce Richardson port_test port_tests[] = {
11a9de470cSBruce Richardson 	test_port_ring_reader,
12a9de470cSBruce Richardson 	test_port_ring_writer,
13a9de470cSBruce Richardson };
14a9de470cSBruce Richardson 
15a9de470cSBruce Richardson unsigned n_port_tests = RTE_DIM(port_tests);
16a9de470cSBruce Richardson 
17a9de470cSBruce Richardson /* Port tests */
18a9de470cSBruce Richardson int
test_port_ring_reader(void)19a9de470cSBruce Richardson test_port_ring_reader(void)
20a9de470cSBruce Richardson {
21a9de470cSBruce Richardson 	int status, i;
22a9de470cSBruce Richardson 	struct rte_port_ring_reader_params port_ring_reader_params;
23a9de470cSBruce Richardson 	void *port;
24a9de470cSBruce Richardson 
25a9de470cSBruce Richardson 	/* Invalid params */
26a9de470cSBruce Richardson 	port = rte_port_ring_reader_ops.f_create(NULL, 0);
27a9de470cSBruce Richardson 	if (port != NULL)
28a9de470cSBruce Richardson 		return -1;
29a9de470cSBruce Richardson 
30a9de470cSBruce Richardson 	status = rte_port_ring_reader_ops.f_free(port);
31a9de470cSBruce Richardson 	if (status >= 0)
32a9de470cSBruce Richardson 		return -2;
33a9de470cSBruce Richardson 
34a9de470cSBruce Richardson 	/* Create and free */
35a9de470cSBruce Richardson 	port_ring_reader_params.ring = RING_RX;
36a9de470cSBruce Richardson 	port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
37a9de470cSBruce Richardson 	if (port == NULL)
38a9de470cSBruce Richardson 		return -3;
39a9de470cSBruce Richardson 
40a9de470cSBruce Richardson 	status = rte_port_ring_reader_ops.f_free(port);
41a9de470cSBruce Richardson 	if (status != 0)
42a9de470cSBruce Richardson 		return -4;
43a9de470cSBruce Richardson 
44a9de470cSBruce Richardson 	/* -- Traffic RX -- */
45a9de470cSBruce Richardson 	int expected_pkts, received_pkts;
46a9de470cSBruce Richardson 	struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
47a9de470cSBruce Richardson 	void *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
48a9de470cSBruce Richardson 
49a9de470cSBruce Richardson 	port_ring_reader_params.ring = RING_RX;
50a9de470cSBruce Richardson 	port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
51a9de470cSBruce Richardson 
52a9de470cSBruce Richardson 	/* Single packet */
53a9de470cSBruce Richardson 	mbuf[0] = (void *)rte_pktmbuf_alloc(pool);
54a9de470cSBruce Richardson 
55a9de470cSBruce Richardson 	expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
56a9de470cSBruce Richardson 		mbuf, 1, NULL);
57a9de470cSBruce Richardson 	received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf, 1);
58a9de470cSBruce Richardson 
59a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
60a9de470cSBruce Richardson 		return -5;
61a9de470cSBruce Richardson 
62a9de470cSBruce Richardson 	rte_pktmbuf_free(res_mbuf[0]);
63a9de470cSBruce Richardson 
64a9de470cSBruce Richardson 	/* Multiple packets */
65a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
66a9de470cSBruce Richardson 		mbuf[i] = rte_pktmbuf_alloc(pool);
67a9de470cSBruce Richardson 
68a9de470cSBruce Richardson 	expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
69a9de470cSBruce Richardson 		(void * const *) mbuf, RTE_PORT_IN_BURST_SIZE_MAX, NULL);
70a9de470cSBruce Richardson 	received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf,
71a9de470cSBruce Richardson 		RTE_PORT_IN_BURST_SIZE_MAX);
72a9de470cSBruce Richardson 
73a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
74a9de470cSBruce Richardson 		return -6;
75a9de470cSBruce Richardson 
76a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
77a9de470cSBruce Richardson 		rte_pktmbuf_free(res_mbuf[i]);
78a9de470cSBruce Richardson 
79a9de470cSBruce Richardson 	return 0;
80a9de470cSBruce Richardson }
81a9de470cSBruce Richardson 
82a9de470cSBruce Richardson int
test_port_ring_writer(void)83a9de470cSBruce Richardson test_port_ring_writer(void)
84a9de470cSBruce Richardson {
85a9de470cSBruce Richardson 	int status, i;
86a9de470cSBruce Richardson 	struct rte_port_ring_writer_params port_ring_writer_params;
87a9de470cSBruce Richardson 	void *port;
88a9de470cSBruce Richardson 
89a9de470cSBruce Richardson 	/* Invalid params */
90a9de470cSBruce Richardson 	port = rte_port_ring_writer_ops.f_create(NULL, 0);
91a9de470cSBruce Richardson 	if (port != NULL)
92a9de470cSBruce Richardson 		return -1;
93a9de470cSBruce Richardson 
94a9de470cSBruce Richardson 	status = rte_port_ring_writer_ops.f_free(port);
95a9de470cSBruce Richardson 	if (status >= 0)
96a9de470cSBruce Richardson 		return -2;
97a9de470cSBruce Richardson 
98a9de470cSBruce Richardson 	port_ring_writer_params.ring = NULL;
99a9de470cSBruce Richardson 
100a9de470cSBruce Richardson 	port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
101a9de470cSBruce Richardson 	if (port != NULL)
102a9de470cSBruce Richardson 		return -3;
103a9de470cSBruce Richardson 
104a9de470cSBruce Richardson 	port_ring_writer_params.ring = RING_TX;
105a9de470cSBruce Richardson 	port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX + 1;
106a9de470cSBruce Richardson 
107a9de470cSBruce Richardson 	port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
108a9de470cSBruce Richardson 	if (port != NULL)
109a9de470cSBruce Richardson 		return -4;
110a9de470cSBruce Richardson 
111a9de470cSBruce Richardson 	/* Create and free */
112a9de470cSBruce Richardson 	port_ring_writer_params.ring = RING_TX;
113a9de470cSBruce Richardson 	port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
114a9de470cSBruce Richardson 
115a9de470cSBruce Richardson 	port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
116a9de470cSBruce Richardson 	if (port == NULL)
117a9de470cSBruce Richardson 		return -5;
118a9de470cSBruce Richardson 
119a9de470cSBruce Richardson 	status = rte_port_ring_writer_ops.f_free(port);
120a9de470cSBruce Richardson 	if (status != 0)
121a9de470cSBruce Richardson 		return -6;
122a9de470cSBruce Richardson 
123a9de470cSBruce Richardson 	/* -- Traffic TX -- */
124a9de470cSBruce Richardson 	int expected_pkts, received_pkts;
125a9de470cSBruce Richardson 	struct rte_mbuf *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
126a9de470cSBruce Richardson 	struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
127a9de470cSBruce Richardson 
128a9de470cSBruce Richardson 	port_ring_writer_params.ring = RING_TX;
129a9de470cSBruce Richardson 	port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
130a9de470cSBruce Richardson 	port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
131a9de470cSBruce Richardson 
132a9de470cSBruce Richardson 	/* Single packet */
133a9de470cSBruce Richardson 	mbuf[0] = rte_pktmbuf_alloc(pool);
134a9de470cSBruce Richardson 
135a9de470cSBruce Richardson 	rte_port_ring_writer_ops.f_tx(port, mbuf[0]);
136a9de470cSBruce Richardson 	rte_port_ring_writer_ops.f_flush(port);
137a9de470cSBruce Richardson 	expected_pkts = 1;
138a9de470cSBruce Richardson 	received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
139a9de470cSBruce Richardson 		(void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
140a9de470cSBruce Richardson 
141a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
142a9de470cSBruce Richardson 		return -7;
143a9de470cSBruce Richardson 
144a9de470cSBruce Richardson 	rte_pktmbuf_free(res_mbuf[0]);
145a9de470cSBruce Richardson 
146a9de470cSBruce Richardson 	/* Multiple packets */
147a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++) {
148a9de470cSBruce Richardson 		mbuf[i] = rte_pktmbuf_alloc(pool);
149a9de470cSBruce Richardson 		rte_port_ring_writer_ops.f_tx(port, mbuf[i]);
150a9de470cSBruce Richardson 	}
151a9de470cSBruce Richardson 
152a9de470cSBruce Richardson 	expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
153a9de470cSBruce Richardson 	received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
154a9de470cSBruce Richardson 		(void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
155a9de470cSBruce Richardson 
156a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
157a9de470cSBruce Richardson 		return -8;
158a9de470cSBruce Richardson 
159a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
160a9de470cSBruce Richardson 		rte_pktmbuf_free(res_mbuf[i]);
161a9de470cSBruce Richardson 
162a9de470cSBruce Richardson 	/* TX Bulk */
163a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
164a9de470cSBruce Richardson 		mbuf[i] = rte_pktmbuf_alloc(pool);
165a9de470cSBruce Richardson 	rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-1);
166a9de470cSBruce Richardson 
167a9de470cSBruce Richardson 	expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
168a9de470cSBruce Richardson 	received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
169a9de470cSBruce Richardson 		(void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
170a9de470cSBruce Richardson 
171a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
172a9de470cSBruce Richardson 		return -8;
173a9de470cSBruce Richardson 
174a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
175a9de470cSBruce Richardson 		rte_pktmbuf_free(res_mbuf[i]);
176a9de470cSBruce Richardson 
177a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
178a9de470cSBruce Richardson 		mbuf[i] = rte_pktmbuf_alloc(pool);
179a9de470cSBruce Richardson 	rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-3);
180a9de470cSBruce Richardson 	rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)2);
181a9de470cSBruce Richardson 
182a9de470cSBruce Richardson 	expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
183a9de470cSBruce Richardson 	received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
184a9de470cSBruce Richardson 		(void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
185a9de470cSBruce Richardson 
186a9de470cSBruce Richardson 	if (received_pkts < expected_pkts)
187a9de470cSBruce Richardson 		return -9;
188a9de470cSBruce Richardson 
189a9de470cSBruce Richardson 	for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
190a9de470cSBruce Richardson 		rte_pktmbuf_free(res_mbuf[i]);
191a9de470cSBruce Richardson 
192a9de470cSBruce Richardson 	return 0;
193a9de470cSBruce Richardson }
194*3c60274cSJie Zhou 
195*3c60274cSJie Zhou #endif /* !RTE_EXEC_ENV_WINDOWS */
196