app: check status of getting ethdev info
[dpdk.git] / app / test / test_event_eth_rx_adapter.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 #include <string.h>
5 #include <rte_common.h>
6 #include <rte_mempool.h>
7 #include <rte_mbuf.h>
8 #include <rte_ethdev.h>
9 #include <rte_eventdev.h>
10 #include <rte_bus_vdev.h>
11
12 #include <rte_event_eth_rx_adapter.h>
13
14 #include "test.h"
15
16 #define MAX_NUM_RX_QUEUE        64
17 #define NB_MBUFS                (8192 * num_ports * MAX_NUM_RX_QUEUE)
18 #define MBUF_CACHE_SIZE         512
19 #define MBUF_PRIV_SIZE          0
20 #define TEST_INST_ID            0
21 #define TEST_DEV_ID             0
22 #define TEST_ETHDEV_ID          0
23
24 struct event_eth_rx_adapter_test_params {
25         struct rte_mempool *mp;
26         uint16_t rx_rings, tx_rings;
27         uint32_t caps;
28         int rx_intr_port_inited;
29         uint16_t rx_intr_port;
30 };
31
32 static struct event_eth_rx_adapter_test_params default_params;
33
34 static inline int
35 port_init_common(uint16_t port, const struct rte_eth_conf *port_conf,
36                 struct rte_mempool *mp)
37 {
38         const uint16_t rx_ring_size = 512, tx_ring_size = 512;
39         int retval;
40         uint16_t q;
41         struct rte_eth_dev_info dev_info;
42
43         if (!rte_eth_dev_is_valid_port(port))
44                 return -1;
45
46         retval = rte_eth_dev_configure(port, 0, 0, port_conf);
47
48         retval = rte_eth_dev_info_get(port, &dev_info);
49         if (retval != 0)
50                 return retval;
51
52         default_params.rx_rings = RTE_MIN(dev_info.max_rx_queues,
53                                         MAX_NUM_RX_QUEUE);
54         default_params.tx_rings = 1;
55
56         /* Configure the Ethernet device. */
57         retval = rte_eth_dev_configure(port, default_params.rx_rings,
58                                 default_params.tx_rings, port_conf);
59         if (retval != 0)
60                 return retval;
61
62         for (q = 0; q < default_params.rx_rings; q++) {
63                 retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
64                                 rte_eth_dev_socket_id(port), NULL, mp);
65                 if (retval < 0)
66                         return retval;
67         }
68
69         /* Allocate and set up 1 TX queue per Ethernet port. */
70         for (q = 0; q < default_params.tx_rings; q++) {
71                 retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
72                                 rte_eth_dev_socket_id(port), NULL);
73                 if (retval < 0)
74                         return retval;
75         }
76
77         /* Start the Ethernet port. */
78         retval = rte_eth_dev_start(port);
79         if (retval < 0)
80                 return retval;
81
82         /* Display the port MAC address. */
83         struct rte_ether_addr addr;
84         rte_eth_macaddr_get(port, &addr);
85         printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
86                            " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
87                         (unsigned int)port,
88                         addr.addr_bytes[0], addr.addr_bytes[1],
89                         addr.addr_bytes[2], addr.addr_bytes[3],
90                         addr.addr_bytes[4], addr.addr_bytes[5]);
91
92         /* Enable RX in promiscuous mode for the Ethernet device. */
93         rte_eth_promiscuous_enable(port);
94
95         return 0;
96 }
97
98 static inline int
99 port_init_rx_intr(uint16_t port, struct rte_mempool *mp)
100 {
101         static const struct rte_eth_conf port_conf_default = {
102                 .rxmode = {
103                         .mq_mode = ETH_MQ_RX_NONE,
104                 },
105                 .intr_conf = {
106                         .rxq = 1,
107                 },
108         };
109
110         return port_init_common(port, &port_conf_default, mp);
111 }
112
113 static inline int
114 port_init(uint16_t port, struct rte_mempool *mp)
115 {
116         static const struct rte_eth_conf port_conf_default = {
117                 .rxmode = {
118                         .mq_mode = ETH_MQ_RX_NONE,
119                 },
120         };
121
122         return port_init_common(port, &port_conf_default, mp);
123 }
124
125 static int
126 init_port_rx_intr(int num_ports)
127 {
128         int retval;
129         uint16_t portid;
130         int err;
131
132         default_params.mp = rte_pktmbuf_pool_create("packet_pool",
133                                                    NB_MBUFS,
134                                                    MBUF_CACHE_SIZE,
135                                                    MBUF_PRIV_SIZE,
136                                                    RTE_MBUF_DEFAULT_BUF_SIZE,
137                                                    rte_socket_id());
138         if (!default_params.mp)
139                 return -ENOMEM;
140
141         RTE_ETH_FOREACH_DEV(portid) {
142                 retval = port_init_rx_intr(portid, default_params.mp);
143                 if (retval)
144                         continue;
145                 err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID, portid,
146                                                         &default_params.caps);
147                 if (err)
148                         continue;
149                 if (!(default_params.caps &
150                         RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT)) {
151                         default_params.rx_intr_port_inited = 1;
152                         default_params.rx_intr_port = portid;
153                         return 0;
154                 }
155                 rte_eth_dev_stop(portid);
156         }
157         return 0;
158 }
159
160 static int
161 init_ports(int num_ports)
162 {
163         uint16_t portid;
164         int retval;
165
166         struct rte_mempool *ptr = rte_mempool_lookup("packet_pool");
167
168         if (ptr == NULL)
169                 default_params.mp = rte_pktmbuf_pool_create("packet_pool",
170                                                 NB_MBUFS,
171                                                 MBUF_CACHE_SIZE,
172                                                 MBUF_PRIV_SIZE,
173                                                 RTE_MBUF_DEFAULT_BUF_SIZE,
174                                                 rte_socket_id());
175         else
176                 default_params.mp = ptr;
177
178         if (!default_params.mp)
179                 return -ENOMEM;
180
181         RTE_ETH_FOREACH_DEV(portid) {
182                 retval = port_init(portid, default_params.mp);
183                 if (retval)
184                         return retval;
185         }
186
187         return 0;
188 }
189
190 static int
191 testsuite_setup(void)
192 {
193         int err;
194         uint8_t count;
195         struct rte_event_dev_info dev_info;
196
197         count = rte_event_dev_count();
198         if (!count) {
199                 printf("Failed to find a valid event device,"
200                         " testing with event_skeleton device\n");
201                 rte_vdev_init("event_skeleton", NULL);
202         }
203
204         struct rte_event_dev_config config = {
205                         .nb_event_queues = 1,
206                         .nb_event_ports = 1,
207         };
208
209         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
210         config.nb_event_queue_flows = dev_info.max_event_queue_flows;
211         config.nb_event_port_dequeue_depth =
212                         dev_info.max_event_port_dequeue_depth;
213         config.nb_event_port_enqueue_depth =
214                         dev_info.max_event_port_enqueue_depth;
215         config.nb_events_limit =
216                         dev_info.max_num_events;
217         err = rte_event_dev_configure(TEST_DEV_ID, &config);
218         TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
219                         err);
220
221         /*
222          * eth devices like octeontx use event device to receive packets
223          * so rte_eth_dev_start invokes rte_event_dev_start internally, so
224          * call init_ports after rte_event_dev_configure
225          */
226         err = init_ports(rte_eth_dev_count_total());
227         TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);
228
229         err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
230                                                 &default_params.caps);
231         TEST_ASSERT(err == 0, "Failed to get adapter cap err %d\n",
232                         err);
233
234         return err;
235 }
236
237 static int
238 testsuite_setup_rx_intr(void)
239 {
240         int err;
241         uint8_t count;
242         struct rte_event_dev_info dev_info;
243
244         count = rte_event_dev_count();
245         if (!count) {
246                 printf("Failed to find a valid event device,"
247                         " testing with event_skeleton device\n");
248                 rte_vdev_init("event_skeleton", NULL);
249         }
250
251         struct rte_event_dev_config config = {
252                 .nb_event_queues = 1,
253                 .nb_event_ports = 1,
254         };
255
256         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
257         config.nb_event_queue_flows = dev_info.max_event_queue_flows;
258         config.nb_event_port_dequeue_depth =
259                         dev_info.max_event_port_dequeue_depth;
260         config.nb_event_port_enqueue_depth =
261                         dev_info.max_event_port_enqueue_depth;
262         config.nb_events_limit =
263                         dev_info.max_num_events;
264
265         err = rte_event_dev_configure(TEST_DEV_ID, &config);
266         TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
267                         err);
268
269         /*
270          * eth devices like octeontx use event device to receive packets
271          * so rte_eth_dev_start invokes rte_event_dev_start internally, so
272          * call init_ports after rte_event_dev_configure
273          */
274         err = init_port_rx_intr(rte_eth_dev_count_total());
275         TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);
276
277         if (!default_params.rx_intr_port_inited)
278                 return 0;
279
280         err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID,
281                                                 default_params.rx_intr_port,
282                                                 &default_params.caps);
283         TEST_ASSERT(err == 0, "Failed to get adapter cap err %d\n", err);
284
285         return err;
286 }
287
288 static void
289 testsuite_teardown(void)
290 {
291         uint32_t i;
292         RTE_ETH_FOREACH_DEV(i)
293                 rte_eth_dev_stop(i);
294
295         rte_mempool_free(default_params.mp);
296 }
297
298 static void
299 testsuite_teardown_rx_intr(void)
300 {
301         if (!default_params.rx_intr_port_inited)
302                 return;
303
304         rte_eth_dev_stop(default_params.rx_intr_port);
305         rte_mempool_free(default_params.mp);
306 }
307
308 static int
309 adapter_create(void)
310 {
311         int err;
312         struct rte_event_dev_info dev_info;
313         struct rte_event_port_conf rx_p_conf;
314
315         memset(&rx_p_conf, 0, sizeof(rx_p_conf));
316
317         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
318         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
319
320         rx_p_conf.new_event_threshold = dev_info.max_num_events;
321         rx_p_conf.dequeue_depth = dev_info.max_event_port_dequeue_depth;
322         rx_p_conf.enqueue_depth = dev_info.max_event_port_enqueue_depth;
323         err = rte_event_eth_rx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
324                                         &rx_p_conf);
325         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
326
327         return err;
328 }
329
330 static void
331 adapter_free(void)
332 {
333         rte_event_eth_rx_adapter_free(TEST_INST_ID);
334 }
335
336 static int
337 adapter_create_free(void)
338 {
339         int err;
340
341         struct rte_event_port_conf rx_p_conf = {
342                         .dequeue_depth = 8,
343                         .enqueue_depth = 8,
344                         .new_event_threshold = 1200,
345         };
346
347         err = rte_event_eth_rx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
348                                         NULL);
349         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
350
351         err = rte_event_eth_rx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
352                                         &rx_p_conf);
353         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
354
355         err = rte_event_eth_rx_adapter_create(TEST_INST_ID,
356                                         TEST_DEV_ID, &rx_p_conf);
357         TEST_ASSERT(err == -EEXIST, "Expected -EEXIST %d got %d", -EEXIST, err);
358
359         err = rte_event_eth_rx_adapter_free(TEST_INST_ID);
360         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
361
362         err = rte_event_eth_rx_adapter_free(TEST_INST_ID);
363         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);
364
365         err = rte_event_eth_rx_adapter_free(1);
366         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);
367
368         return TEST_SUCCESS;
369 }
370
371 static int
372 adapter_queue_add_del(void)
373 {
374         int err;
375         struct rte_event ev;
376         uint32_t cap;
377
378         struct rte_event_eth_rx_adapter_queue_conf queue_config;
379
380         err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
381                                          &cap);
382         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
383
384         ev.queue_id = 0;
385         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
386         ev.priority = 0;
387
388         queue_config.rx_queue_flags = 0;
389         if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) {
390                 ev.flow_id = 1;
391                 queue_config.rx_queue_flags =
392                         RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID;
393         }
394         queue_config.ev = ev;
395         queue_config.servicing_weight = 1;
396
397         err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
398                                                 rte_eth_dev_count_total(),
399                                                 -1, &queue_config);
400         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
401
402         if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ) {
403                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
404                                                         TEST_ETHDEV_ID, 0,
405                                                         &queue_config);
406                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
407
408                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
409                                                         TEST_ETHDEV_ID, 0);
410                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
411
412                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
413                                                         TEST_ETHDEV_ID,
414                                                         -1,
415                                                         &queue_config);
416                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
417
418                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
419                                                         TEST_ETHDEV_ID,
420                                                         -1);
421                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
422         } else {
423                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
424                                                         TEST_ETHDEV_ID,
425                                                         0,
426                                                         &queue_config);
427                 TEST_ASSERT(err == -EINVAL, "Expected EINVAL got %d", err);
428
429                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
430                                                         TEST_ETHDEV_ID, -1,
431                                                         &queue_config);
432                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
433
434                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
435                                                         TEST_ETHDEV_ID, 0);
436                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
437
438                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
439                                                         TEST_ETHDEV_ID, -1);
440                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
441
442                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
443                                                         TEST_ETHDEV_ID, -1);
444                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
445         }
446
447         err = rte_event_eth_rx_adapter_queue_add(1, TEST_ETHDEV_ID, -1,
448                                                 &queue_config);
449         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
450
451         err = rte_event_eth_rx_adapter_queue_del(1, TEST_ETHDEV_ID, -1);
452         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
453
454         return TEST_SUCCESS;
455 }
456
457 static int
458 adapter_multi_eth_add_del(void)
459 {
460         int err;
461         struct rte_event ev;
462
463         uint16_t port_index, drv_id = 0;
464         char driver_name[50];
465
466         struct rte_event_eth_rx_adapter_queue_conf queue_config;
467
468         ev.queue_id = 0;
469         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
470         ev.priority = 0;
471
472         queue_config.rx_queue_flags = 0;
473         queue_config.ev = ev;
474         queue_config.servicing_weight = 1;
475
476         /* stop eth devices for existing */
477         port_index = 0;
478         for (; port_index < rte_eth_dev_count_total(); port_index += 1)
479                 rte_eth_dev_stop(port_index);
480
481         /* add the max port for rx_adapter */
482         port_index = rte_eth_dev_count_total();
483         for (; port_index < RTE_MAX_ETHPORTS; port_index += 1) {
484                 snprintf(driver_name, sizeof(driver_name), "%s%u", "net_null",
485                                 drv_id);
486                 err = rte_vdev_init(driver_name, NULL);
487                 TEST_ASSERT(err == 0, "Failed driver %s got %d",
488                 driver_name, err);
489                 drv_id += 1;
490         }
491
492         err = init_ports(rte_eth_dev_count_total());
493         TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);
494
495         /* eth_rx_adapter_queue_add for n ports */
496         port_index = 0;
497         for (; port_index < rte_eth_dev_count_total(); port_index += 1) {
498                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
499                                 port_index, -1,
500                                 &queue_config);
501                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
502         }
503
504         /* eth_rx_adapter_queue_del n ports */
505         port_index = 0;
506         for (; port_index < rte_eth_dev_count_total(); port_index += 1) {
507                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
508                                 port_index, -1);
509                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
510         }
511
512         return TEST_SUCCESS;
513 }
514
515 static int
516 adapter_intr_queue_add_del(void)
517 {
518         int err;
519         struct rte_event ev;
520         uint32_t cap;
521         uint16_t eth_port;
522         struct rte_event_eth_rx_adapter_queue_conf queue_config;
523
524         if (!default_params.rx_intr_port_inited)
525                 return 0;
526
527         eth_port = default_params.rx_intr_port;
528         err = rte_event_eth_rx_adapter_caps_get(TEST_DEV_ID, eth_port, &cap);
529         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
530
531         ev.queue_id = 0;
532         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
533         ev.priority = 0;
534
535         queue_config.rx_queue_flags = 0;
536         queue_config.ev = ev;
537
538         /* weight = 0 => interrupt mode */
539         queue_config.servicing_weight = 0;
540
541         if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ) {
542                 /* add queue 0 */
543                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
544                                                         TEST_ETHDEV_ID, 0,
545                                                         &queue_config);
546                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
547         }
548
549         /* add all queues */
550         queue_config.servicing_weight = 0;
551         err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
552                                                 TEST_ETHDEV_ID,
553                                                 -1,
554                                                 &queue_config);
555         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
556
557         if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ) {
558                 /* del queue 0 */
559                 err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
560                                                         TEST_ETHDEV_ID,
561                                                         0);
562                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
563         }
564
565         /* del remaining queues */
566         err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
567                                                 TEST_ETHDEV_ID,
568                                                 -1);
569         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
570
571         /* add all queues */
572         queue_config.servicing_weight = 0;
573         err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
574                                                 TEST_ETHDEV_ID,
575                                                 -1,
576                                                 &queue_config);
577         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
578
579         /* intr -> poll mode queue */
580         queue_config.servicing_weight = 1;
581
582         if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ) {
583                 err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
584                                                         TEST_ETHDEV_ID,
585                                                         0,
586                                                         &queue_config);
587                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
588         }
589
590         err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID,
591                                                 TEST_ETHDEV_ID,
592                                                 -1,
593                                                  &queue_config);
594         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
595
596         /* del queues */
597         err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID,
598                                                 TEST_ETHDEV_ID,
599                                                 -1);
600         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
601
602         return TEST_SUCCESS;
603 }
604
605 static int
606 adapter_start_stop(void)
607 {
608         int err;
609         struct rte_event ev;
610
611         ev.queue_id = 0;
612         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
613         ev.priority = 0;
614
615         struct rte_event_eth_rx_adapter_queue_conf queue_config;
616
617         queue_config.rx_queue_flags = 0;
618         if (default_params.caps &
619                 RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID) {
620                 ev.flow_id = 1;
621                 queue_config.rx_queue_flags =
622                         RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID;
623         }
624
625         queue_config.ev = ev;
626         queue_config.servicing_weight = 1;
627
628         err = rte_event_eth_rx_adapter_queue_add(TEST_INST_ID, TEST_ETHDEV_ID,
629                                         -1, &queue_config);
630         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
631
632         err = rte_event_eth_rx_adapter_start(TEST_INST_ID);
633         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
634
635         err = rte_event_eth_rx_adapter_stop(TEST_INST_ID);
636         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
637
638         err = rte_event_eth_rx_adapter_queue_del(TEST_INST_ID, TEST_ETHDEV_ID,
639                                                 -1);
640         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
641
642         err = rte_event_eth_rx_adapter_start(TEST_INST_ID);
643         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
644
645         err = rte_event_eth_rx_adapter_stop(TEST_INST_ID);
646         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
647
648         err = rte_event_eth_rx_adapter_start(1);
649         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
650
651         err = rte_event_eth_rx_adapter_stop(1);
652         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
653
654         return TEST_SUCCESS;
655 }
656
657 static int
658 adapter_stats(void)
659 {
660         int err;
661         struct rte_event_eth_rx_adapter_stats stats;
662
663         err = rte_event_eth_rx_adapter_stats_get(TEST_INST_ID, NULL);
664         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
665
666         err = rte_event_eth_rx_adapter_stats_get(TEST_INST_ID, &stats);
667         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
668
669         err = rte_event_eth_rx_adapter_stats_get(1, &stats);
670         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
671
672         return TEST_SUCCESS;
673 }
674
675 static struct unit_test_suite event_eth_rx_tests = {
676         .suite_name = "rx event eth adapter test suite",
677         .setup = testsuite_setup,
678         .teardown = testsuite_teardown,
679         .unit_test_cases = {
680                 TEST_CASE_ST(NULL, NULL, adapter_create_free),
681                 TEST_CASE_ST(adapter_create, adapter_free,
682                                         adapter_queue_add_del),
683                 TEST_CASE_ST(adapter_create, adapter_free,
684                                         adapter_multi_eth_add_del),
685                 TEST_CASE_ST(adapter_create, adapter_free, adapter_start_stop),
686                 TEST_CASE_ST(adapter_create, adapter_free, adapter_stats),
687                 TEST_CASES_END() /**< NULL terminate unit test array */
688         }
689 };
690
691 static struct unit_test_suite event_eth_rx_intr_tests = {
692         .suite_name = "rx event eth adapter test suite",
693         .setup = testsuite_setup_rx_intr,
694         .teardown = testsuite_teardown_rx_intr,
695         .unit_test_cases = {
696                 TEST_CASE_ST(adapter_create, adapter_free,
697                         adapter_intr_queue_add_del),
698                 TEST_CASES_END() /**< NULL terminate unit test array */
699         }
700 };
701
702 static int
703 test_event_eth_rx_adapter_common(void)
704 {
705         return unit_test_suite_runner(&event_eth_rx_tests);
706 }
707
708 static int
709 test_event_eth_rx_intr_adapter_common(void)
710 {
711         return unit_test_suite_runner(&event_eth_rx_intr_tests);
712 }
713
714 REGISTER_TEST_COMMAND(event_eth_rx_adapter_autotest,
715                 test_event_eth_rx_adapter_common);
716 REGISTER_TEST_COMMAND(event_eth_rx_intr_adapter_autotest,
717                 test_event_eth_rx_intr_adapter_common);