1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #include "test_table_ports.h"
6 #include "test_table.h"
8 port_test port_tests[] = {
10 test_port_ring_writer,
13 unsigned n_port_tests = RTE_DIM(port_tests);
17 test_port_ring_reader(void)
20 struct rte_port_ring_reader_params port_ring_reader_params;
24 port = rte_port_ring_reader_ops.f_create(NULL, 0);
28 status = rte_port_ring_reader_ops.f_free(port);
33 port_ring_reader_params.ring = RING_RX;
34 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
38 status = rte_port_ring_reader_ops.f_free(port);
42 /* -- Traffic RX -- */
43 int expected_pkts, received_pkts;
44 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
45 void *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
47 port_ring_reader_params.ring = RING_RX;
48 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
51 mbuf[0] = (void *)rte_pktmbuf_alloc(pool);
53 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
55 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf, 1);
57 if (received_pkts < expected_pkts)
60 rte_pktmbuf_free(res_mbuf[0]);
62 /* Multiple packets */
63 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
64 mbuf[i] = rte_pktmbuf_alloc(pool);
66 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
67 (void * const *) mbuf, RTE_PORT_IN_BURST_SIZE_MAX, NULL);
68 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf,
69 RTE_PORT_IN_BURST_SIZE_MAX);
71 if (received_pkts < expected_pkts)
74 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
75 rte_pktmbuf_free(res_mbuf[i]);
81 test_port_ring_writer(void)
84 struct rte_port_ring_writer_params port_ring_writer_params;
88 port = rte_port_ring_writer_ops.f_create(NULL, 0);
92 status = rte_port_ring_writer_ops.f_free(port);
96 port_ring_writer_params.ring = NULL;
98 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
102 port_ring_writer_params.ring = RING_TX;
103 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX + 1;
105 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
109 /* Create and free */
110 port_ring_writer_params.ring = RING_TX;
111 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
113 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
117 status = rte_port_ring_writer_ops.f_free(port);
121 /* -- Traffic TX -- */
122 int expected_pkts, received_pkts;
123 struct rte_mbuf *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
124 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
126 port_ring_writer_params.ring = RING_TX;
127 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
128 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
131 mbuf[0] = rte_pktmbuf_alloc(pool);
133 rte_port_ring_writer_ops.f_tx(port, mbuf[0]);
134 rte_port_ring_writer_ops.f_flush(port);
136 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
137 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
139 if (received_pkts < expected_pkts)
142 rte_pktmbuf_free(res_mbuf[0]);
144 /* Multiple packets */
145 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++) {
146 mbuf[i] = rte_pktmbuf_alloc(pool);
147 rte_port_ring_writer_ops.f_tx(port, mbuf[i]);
150 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
151 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
152 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
154 if (received_pkts < expected_pkts)
157 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
158 rte_pktmbuf_free(res_mbuf[i]);
161 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
162 mbuf[i] = rte_pktmbuf_alloc(pool);
163 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-1);
165 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
166 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
167 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
169 if (received_pkts < expected_pkts)
172 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
173 rte_pktmbuf_free(res_mbuf[i]);
175 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
176 mbuf[i] = rte_pktmbuf_alloc(pool);
177 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-3);
178 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)2);
180 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
181 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
182 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz, NULL);
184 if (received_pkts < expected_pkts)
187 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
188 rte_pktmbuf_free(res_mbuf[i]);