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 #ifdef RTE_LIBRTE_TABLE
36 #include "test_table_ports.h"
37 #include "test_table.h"
39 port_test port_tests[] = {
40 test_port_ring_reader,
41 test_port_ring_writer,
44 unsigned n_port_tests = RTE_DIM(port_tests);
48 test_port_ring_reader(void)
51 struct rte_port_ring_reader_params port_ring_reader_params;
55 port = rte_port_ring_reader_ops.f_create(NULL, 0);
59 status = rte_port_ring_reader_ops.f_free(port);
64 port_ring_reader_params.ring = RING_RX;
65 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
69 status = rte_port_ring_reader_ops.f_free(port);
73 /* -- Traffic RX -- */
74 int expected_pkts, received_pkts;
75 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
76 void *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
78 port_ring_reader_params.ring = RING_RX;
79 port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
82 mbuf[0] = (void *)rte_pktmbuf_alloc(pool);
84 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
86 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf, 1);
88 if (received_pkts < expected_pkts)
91 rte_pktmbuf_free(res_mbuf[0]);
93 /* Multiple packets */
94 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
95 mbuf[i] = rte_pktmbuf_alloc(pool);
97 expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
98 (void * const *) mbuf, RTE_PORT_IN_BURST_SIZE_MAX);
99 received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf,
100 RTE_PORT_IN_BURST_SIZE_MAX);
102 if (received_pkts < expected_pkts)
105 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
106 rte_pktmbuf_free(res_mbuf[i]);
112 test_port_ring_writer(void)
115 struct rte_port_ring_writer_params port_ring_writer_params;
119 port = rte_port_ring_writer_ops.f_create(NULL, 0);
123 status = rte_port_ring_writer_ops.f_free(port);
127 port_ring_writer_params.ring = NULL;
129 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
133 port_ring_writer_params.ring = RING_TX;
134 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX + 1;
136 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
140 /* Create and free */
141 port_ring_writer_params.ring = RING_TX;
142 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
144 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
148 status = rte_port_ring_writer_ops.f_free(port);
152 /* -- Traffic TX -- */
153 int expected_pkts, received_pkts;
154 struct rte_mbuf *mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
155 struct rte_mbuf *res_mbuf[RTE_PORT_IN_BURST_SIZE_MAX];
157 port_ring_writer_params.ring = RING_TX;
158 port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX;
159 port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
162 mbuf[0] = rte_pktmbuf_alloc(pool);
164 rte_port_ring_writer_ops.f_tx(port, mbuf[0]);
165 rte_port_ring_writer_ops.f_flush(port);
167 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
168 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
170 if (received_pkts < expected_pkts)
173 rte_pktmbuf_free(res_mbuf[0]);
175 /* Multiple packets */
176 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++) {
177 mbuf[i] = rte_pktmbuf_alloc(pool);
178 rte_port_ring_writer_ops.f_tx(port, mbuf[i]);
181 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
182 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
183 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
185 if (received_pkts < expected_pkts)
188 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
189 rte_pktmbuf_free(res_mbuf[i]);
192 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
193 mbuf[i] = rte_pktmbuf_alloc(pool);
194 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-1);
196 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
197 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
198 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
200 if (received_pkts < expected_pkts)
203 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
204 rte_pktmbuf_free(res_mbuf[i]);
206 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
207 mbuf[i] = rte_pktmbuf_alloc(pool);
208 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)-3);
209 rte_port_ring_writer_ops.f_tx_bulk(port, mbuf, (uint64_t)2);
211 expected_pkts = RTE_PORT_IN_BURST_SIZE_MAX;
212 received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
213 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
215 if (received_pkts < expected_pkts)
218 for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
219 rte_pktmbuf_free(res_mbuf[i]);