4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "test_table_ports.h"
35 #include "test_table.h"
37 port_test port_tests[] = {
38 test_port_ring_reader,
39 test_port_ring_writer,
42 unsigned n_port_tests = RTE_DIM(port_tests);
46 test_port_ring_reader(void)
49 struct rte_port_ring_reader_params port_ring_reader_params;
53 port = rte_port_ring_reader_ops.f_create(NULL, 0);
57 status = rte_port_ring_reader_ops.f_free(port);
62 port_ring_reader_params.ring = RING_RX;
63 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
67 status = rte_port_ring_reader_ops.f_free(port);
71 /* -- Traffic RX -- */
72 int expected_pkts, received_pkts;
73 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
74 void *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
76 port_ring_reader_params.ring = RING_RX;
77 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
80 mbuf[0] = (void *)rte_pktmbuf_alloc(pool);
82 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
84 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf, 1);
86 if (received_pkts < expected_pkts)
89 rte_pktmbuf_free(res_mbuf[0]);
91 /* Multiple packets */
92 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
93 mbuf[i] = rte_pktmbuf_alloc(pool);
95 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
96 (void * const *) mbuf, RTE_PORT_IN_BURST_SIZE_MAX);
97 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf,
98 RTE_PORT_IN_BURST_SIZE_MAX);
100 if (received_pkts < expected_pkts)
103 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
104 rte_pktmbuf_free(res_mbuf[i]);
110 test_port_ring_writer(void)
113 struct rte_port_ring_writer_params port_ring_writer_params;
117 port = rte_port_ring_writer_ops.f_create(NULL, 0);
121 status = rte_port_ring_writer_ops.f_free(port);
125 port_ring_writer_params.ring = NULL;
127 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
131 port_ring_writer_params.ring = RING_TX;
132 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX + 1;
134 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
138 /* Create and free */
139 port_ring_writer_params.ring = RING_TX;
140 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
142 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
146 status = rte_port_ring_writer_ops.f_free(port);
150 /* -- Traffic TX -- */
151 int expected_pkts, received_pkts;
152 struct rte_mbuf *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
153 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
155 port_ring_writer_params.ring = RING_TX;
156 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
157 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
160 mbuf[0] = rte_pktmbuf_alloc(pool);
162 rte_port_ring_writer_ops.f_tx(port, mbuf[0]);
163 rte_port_ring_writer_ops.f_flush(port);
165 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
166 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
168 if (received_pkts < expected_pkts)
171 rte_pktmbuf_free(res_mbuf[0]);
173 /* Multiple packets */
174 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++) {
175 mbuf[i] = rte_pktmbuf_alloc(pool);
176 rte_port_ring_writer_ops.f_tx(port, mbuf[i]);
179 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
180 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
181 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
183 if (received_pkts < expected_pkts)
186 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
187 rte_pktmbuf_free(res_mbuf[i]);
190 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
191 mbuf[i] = rte_pktmbuf_alloc(pool);
192 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-1);
194 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
195 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
196 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
198 if (received_pkts < expected_pkts)
201 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
202 rte_pktmbuf_free(res_mbuf[i]);
204 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
205 mbuf[i] = rte_pktmbuf_alloc(pool);
206 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-3);
207 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)2);
209 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
210 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
211 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
213 if (received_pkts < expected_pkts)
216 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
217 rte_pktmbuf_free(res_mbuf[i]);