tile: fix build
[dpdk.git] / app / test / test_table_ports.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include "test_table_ports.h"
35 #include "test_table.h"
36
37 port_test port_tests[] = {
38         test_port_ring_reader,
39         test_port_ring_writer,
40 };
41
42 unsigned n_port_tests = RTE_DIM(port_tests);
43
44 /* Port tests */
45 int
46 test_port_ring_reader(void)
47 {
48         int status, i;
49         struct rte_port_ring_reader_params port_ring_reader_params;
50         void *port;
51
52         /* Invalid params */
53         port = rte_port_ring_reader_ops.f_create(NULL, 0);
54         if (port != NULL)
55                 return -1;
56
57         status = rte_port_ring_reader_ops.f_free(port);
58         if (status >= 0)
59                 return -2;
60
61         /* Create and free */
62         port_ring_reader_params.ring = RING_RX;
63         port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
64         if (port == NULL)
65                 return -3;
66
67         status = rte_port_ring_reader_ops.f_free(port);
68         if (status != 0)
69                 return -4;
70
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];
75
76         port_ring_reader_params.ring = RING_RX;
77         port = rte_port_ring_reader_ops.f_create(&port_ring_reader_params, 0);
78
79         /* Single packet */
80         mbuf[0] = (void *)rte_pktmbuf_alloc(pool);
81
82         expected_pkts = rte_ring_sp_enqueue_burst(port_ring_reader_params.ring,
83                 mbuf, 1);
84         received_pkts = rte_port_ring_reader_ops.f_rx(port, res_mbuf, 1);
85
86         if (received_pkts < expected_pkts)
87                 return -5;
88
89         rte_pktmbuf_free(res_mbuf[0]);
90
91         /* Multiple packets */
92         for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
93                 mbuf[i] = rte_pktmbuf_alloc(pool);
94
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);
99
100         if (received_pkts < expected_pkts)
101                 return -6;
102
103         for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
104                 rte_pktmbuf_free(res_mbuf[i]);
105
106         return 0;
107 }
108
109 int
110 test_port_ring_writer(void)
111 {
112         int status, i;
113         struct rte_port_ring_writer_params port_ring_writer_params;
114         void *port;
115
116         /* Invalid params */
117         port = rte_port_ring_writer_ops.f_create(NULL, 0);
118         if (port != NULL)
119                 return -1;
120
121         status = rte_port_ring_writer_ops.f_free(port);
122         if (status >= 0)
123                 return -2;
124
125         port_ring_writer_params.ring = NULL;
126
127         port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
128         if (port != NULL)
129                 return -3;
130
131         port_ring_writer_params.ring = RING_TX;
132         port_ring_writer_params.tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX + 1;
133
134         port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
135         if (port != NULL)
136                 return -4;
137
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;
141
142         port = rte_port_ring_writer_ops.f_create(&port_ring_writer_params, 0);
143         if (port == NULL)
144                 return -5;
145
146         status = rte_port_ring_writer_ops.f_free(port);
147         if (status != 0)
148                 return -6;
149
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];
154
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);
158
159         /* Single packet */
160         mbuf[0] = rte_pktmbuf_alloc(pool);
161
162         rte_port_ring_writer_ops.f_tx(port, mbuf[0]);
163         rte_port_ring_writer_ops.f_flush(port);
164         expected_pkts = 1;
165         received_pkts = rte_ring_sc_dequeue_burst(port_ring_writer_params.ring,
166                 (void **)res_mbuf, port_ring_writer_params.tx_burst_sz);
167
168         if (received_pkts < expected_pkts)
169                 return -7;
170
171         rte_pktmbuf_free(res_mbuf[0]);
172
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]);
177         }
178
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);
182
183         if (received_pkts < expected_pkts)
184                 return -8;
185
186         for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
187                 rte_pktmbuf_free(res_mbuf[i]);
188
189         /* TX Bulk */
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);
193
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);
197
198         if (received_pkts < expected_pkts)
199                 return -8;
200
201         for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
202                 rte_pktmbuf_free(res_mbuf[i]);
203
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);
208
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);
212
213         if (received_pkts < expected_pkts)
214                 return -9;
215
216         for (i = 0; i < RTE_PORT_IN_BURST_SIZE_MAX; i++)
217                 rte_pktmbuf_free(res_mbuf[i]);
218
219         return 0;
220 }