net/virtio: fix incorrect cast of void *
[dpdk.git] / test / test / test_eventdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016 Cavium, Inc. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Cavium, Inc nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38 #include <rte_eventdev.h>
39 #include <rte_dev.h>
40 #include <rte_bus_vdev.h>
41
42 #include "test.h"
43
44 #define TEST_DEV_ID   0
45
46 static int
47 testsuite_setup(void)
48 {
49         RTE_BUILD_BUG_ON(sizeof(struct rte_event) != 16);
50         uint8_t count;
51         count = rte_event_dev_count();
52         if (!count) {
53                 printf("Failed to find a valid event device,"
54                         " testing with event_skeleton device\n");
55                 return rte_vdev_init("event_skeleton", NULL);
56         }
57         return TEST_SUCCESS;
58 }
59
60 static void
61 testsuite_teardown(void)
62 {
63 }
64
65 static int
66 test_eventdev_count(void)
67 {
68         uint8_t count;
69         count = rte_event_dev_count();
70         TEST_ASSERT(count > 0, "Invalid eventdev count %" PRIu8, count);
71         return TEST_SUCCESS;
72 }
73
74 static int
75 test_eventdev_get_dev_id(void)
76 {
77         int ret;
78         ret = rte_event_dev_get_dev_id("not_a_valid_eventdev_driver");
79         TEST_ASSERT_FAIL(ret, "Expected <0 for invalid dev name ret=%d", ret);
80         return TEST_SUCCESS;
81 }
82
83 static int
84 test_eventdev_socket_id(void)
85 {
86         int socket_id;
87         socket_id = rte_event_dev_socket_id(TEST_DEV_ID);
88         TEST_ASSERT(socket_id != -EINVAL, "Failed to get socket_id %d",
89                                 socket_id);
90         socket_id = rte_event_dev_socket_id(RTE_EVENT_MAX_DEVS);
91         TEST_ASSERT(socket_id == -EINVAL, "Expected -EINVAL %d", socket_id);
92
93         return TEST_SUCCESS;
94 }
95
96 static int
97 test_eventdev_info_get(void)
98 {
99         int ret;
100         struct rte_event_dev_info info;
101         ret = rte_event_dev_info_get(TEST_DEV_ID, NULL);
102         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
103         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
104         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
105         TEST_ASSERT(info.max_event_ports > 0,
106                         "Not enough event ports %d", info.max_event_ports);
107         TEST_ASSERT(info.max_event_queues > 0,
108                         "Not enough event queues %d", info.max_event_queues);
109         return TEST_SUCCESS;
110 }
111
112 static inline void
113 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
114                         struct rte_event_dev_info *info)
115 {
116         memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
117         dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
118         dev_conf->nb_event_ports = info->max_event_ports;
119         dev_conf->nb_event_queues = info->max_event_queues;
120         dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
121         dev_conf->nb_event_port_dequeue_depth =
122                         info->max_event_port_dequeue_depth;
123         dev_conf->nb_event_port_enqueue_depth =
124                         info->max_event_port_enqueue_depth;
125         dev_conf->nb_event_port_enqueue_depth =
126                         info->max_event_port_enqueue_depth;
127         dev_conf->nb_events_limit =
128                         info->max_num_events;
129 }
130
131 static int
132 test_ethdev_config_run(struct rte_event_dev_config *dev_conf,
133                 struct rte_event_dev_info *info,
134                 void (*fn)(struct rte_event_dev_config *dev_conf,
135                         struct rte_event_dev_info *info))
136 {
137         devconf_set_default_sane_values(dev_conf, info);
138         fn(dev_conf, info);
139         return rte_event_dev_configure(TEST_DEV_ID, dev_conf);
140 }
141
142 static void
143 max_dequeue_limit(struct rte_event_dev_config *dev_conf,
144                   struct rte_event_dev_info *info)
145 {
146         dev_conf->dequeue_timeout_ns = info->max_dequeue_timeout_ns + 1;
147 }
148
149 static void
150 max_events_limit(struct rte_event_dev_config *dev_conf,
151                   struct rte_event_dev_info *info)
152 {
153         dev_conf->nb_events_limit  = info->max_num_events + 1;
154 }
155
156 static void
157 max_event_ports(struct rte_event_dev_config *dev_conf,
158                   struct rte_event_dev_info *info)
159 {
160         dev_conf->nb_event_ports = info->max_event_ports + 1;
161 }
162
163 static void
164 max_event_queues(struct rte_event_dev_config *dev_conf,
165                   struct rte_event_dev_info *info)
166 {
167         dev_conf->nb_event_queues = info->max_event_queues + 1;
168 }
169
170 static void
171 max_event_queue_flows(struct rte_event_dev_config *dev_conf,
172                   struct rte_event_dev_info *info)
173 {
174         dev_conf->nb_event_queue_flows = info->max_event_queue_flows + 1;
175 }
176
177 static void
178 max_event_port_dequeue_depth(struct rte_event_dev_config *dev_conf,
179                   struct rte_event_dev_info *info)
180 {
181         dev_conf->nb_event_port_dequeue_depth =
182                 info->max_event_port_dequeue_depth + 1;
183 }
184
185 static void
186 max_event_port_enqueue_depth(struct rte_event_dev_config *dev_conf,
187                   struct rte_event_dev_info *info)
188 {
189         dev_conf->nb_event_port_enqueue_depth =
190                 info->max_event_port_enqueue_depth + 1;
191 }
192
193
194 static int
195 test_eventdev_configure(void)
196 {
197         int ret;
198         struct rte_event_dev_config dev_conf;
199         struct rte_event_dev_info info;
200         ret = rte_event_dev_configure(TEST_DEV_ID, NULL);
201         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
202
203         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
204         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
205
206         /* Check limits */
207         TEST_ASSERT_EQUAL(-EINVAL,
208                 test_ethdev_config_run(&dev_conf, &info, max_dequeue_limit),
209                  "Config negative test failed");
210         TEST_ASSERT_EQUAL(-EINVAL,
211                 test_ethdev_config_run(&dev_conf, &info, max_events_limit),
212                  "Config negative test failed");
213         TEST_ASSERT_EQUAL(-EINVAL,
214                 test_ethdev_config_run(&dev_conf, &info, max_event_ports),
215                  "Config negative test failed");
216         TEST_ASSERT_EQUAL(-EINVAL,
217                 test_ethdev_config_run(&dev_conf, &info, max_event_queues),
218                  "Config negative test failed");
219         TEST_ASSERT_EQUAL(-EINVAL,
220                 test_ethdev_config_run(&dev_conf, &info, max_event_queue_flows),
221                  "Config negative test failed");
222         TEST_ASSERT_EQUAL(-EINVAL,
223                 test_ethdev_config_run(&dev_conf, &info,
224                         max_event_port_dequeue_depth),
225                          "Config negative test failed");
226         TEST_ASSERT_EQUAL(-EINVAL,
227                 test_ethdev_config_run(&dev_conf, &info,
228                 max_event_port_enqueue_depth),
229                  "Config negative test failed");
230
231         /* Positive case */
232         devconf_set_default_sane_values(&dev_conf, &info);
233         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
234         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
235
236         /* re-configure */
237         devconf_set_default_sane_values(&dev_conf, &info);
238         dev_conf.nb_event_ports = RTE_MAX(info.max_event_ports/2, 1);
239         dev_conf.nb_event_queues = RTE_MAX(info.max_event_queues/2, 1);
240         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
241         TEST_ASSERT_SUCCESS(ret, "Failed to re configure eventdev");
242
243         /* re-configure back to max_event_queues and max_event_ports */
244         devconf_set_default_sane_values(&dev_conf, &info);
245         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
246         TEST_ASSERT_SUCCESS(ret, "Failed to re-configure eventdev");
247
248         return TEST_SUCCESS;
249
250 }
251
252 static int
253 eventdev_configure_setup(void)
254 {
255         int ret;
256         struct rte_event_dev_config dev_conf;
257         struct rte_event_dev_info info;
258
259         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
260         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
261         devconf_set_default_sane_values(&dev_conf, &info);
262         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
263         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
264
265         return TEST_SUCCESS;
266 }
267
268 static int
269 test_eventdev_queue_default_conf_get(void)
270 {
271         int i, ret;
272         struct rte_event_queue_conf qconf;
273
274         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, NULL);
275         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
276
277         uint32_t queue_count;
278         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
279                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
280                             "Queue count get failed");
281
282         for (i = 0; i < (int)queue_count; i++) {
283                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
284                                                  &qconf);
285                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d info", i);
286         }
287
288         return TEST_SUCCESS;
289 }
290
291 static int
292 test_eventdev_queue_setup(void)
293 {
294         int i, ret;
295         struct rte_event_dev_info info;
296         struct rte_event_queue_conf qconf;
297
298         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
299         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
300
301         /* Negative cases */
302         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
303         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
304         qconf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
305         qconf.nb_atomic_flows = info.max_event_queue_flows + 1;
306         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
307         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
308
309         qconf.nb_atomic_flows = info.max_event_queue_flows;
310         qconf.schedule_type = RTE_SCHED_TYPE_ORDERED;
311         qconf.nb_atomic_order_sequences = info.max_event_queue_flows + 1;
312         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
313         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
314
315         ret = rte_event_queue_setup(TEST_DEV_ID, info.max_event_queues,
316                                         &qconf);
317         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
318
319         /* Positive case */
320         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
321         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
322         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
323         TEST_ASSERT_SUCCESS(ret, "Failed to setup queue0");
324
325         uint32_t queue_count;
326         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
327                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
328                             "Queue count get failed");
329
330         for (i = 0; i < (int)queue_count; i++) {
331                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
332                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
333         }
334
335         return TEST_SUCCESS;
336 }
337
338 static int
339 test_eventdev_queue_count(void)
340 {
341         int ret;
342         struct rte_event_dev_info info;
343
344         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
345         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
346
347         uint32_t queue_count;
348         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
349                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
350                             "Queue count get failed");
351         TEST_ASSERT_EQUAL(queue_count, info.max_event_queues,
352                           "Wrong queue count");
353
354         return TEST_SUCCESS;
355 }
356
357 static int
358 test_eventdev_queue_attr_priority(void)
359 {
360         int i, ret;
361         struct rte_event_dev_info info;
362         struct rte_event_queue_conf qconf;
363         uint8_t priority;
364
365         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
366         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
367
368         uint32_t queue_count;
369         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
370                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
371                             "Queue count get failed");
372
373         for (i = 0; i < (int)queue_count; i++) {
374                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
375                                         &qconf);
376                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d def conf", i);
377                 qconf.priority = i %  RTE_EVENT_DEV_PRIORITY_LOWEST;
378                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
379                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
380         }
381
382         for (i = 0; i < (int)queue_count; i++) {
383                 uint32_t tmp;
384                 TEST_ASSERT_SUCCESS(rte_event_queue_attr_get(TEST_DEV_ID, i,
385                                     RTE_EVENT_QUEUE_ATTR_PRIORITY, &tmp),
386                                     "Queue priority get failed");
387                 priority = tmp;
388
389                 if (info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
390                         TEST_ASSERT_EQUAL(priority,
391                          i %  RTE_EVENT_DEV_PRIORITY_LOWEST,
392                          "Wrong priority value for queue%d", i);
393                 else
394                         TEST_ASSERT_EQUAL(priority,
395                          RTE_EVENT_DEV_PRIORITY_NORMAL,
396                          "Wrong priority value for queue%d", i);
397         }
398
399         return TEST_SUCCESS;
400 }
401
402 static int
403 test_eventdev_queue_attr_nb_atomic_flows(void)
404 {
405         int i, ret;
406         struct rte_event_dev_info info;
407         struct rte_event_queue_conf qconf;
408         uint32_t nb_atomic_flows;
409
410         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
411         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
412
413         uint32_t queue_count;
414         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
415                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
416                             "Queue count get failed");
417
418         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
419         TEST_ASSERT_SUCCESS(ret, "Failed to get queue 0's def conf");
420
421         if (qconf.nb_atomic_flows == 0)
422                 /* Assume PMD doesn't support atomic flows, return early */
423                 return -ENOTSUP;
424
425         qconf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
426
427         for (i = 0; i < (int)queue_count; i++) {
428                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
429                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
430         }
431
432         for (i = 0; i < (int)queue_count; i++) {
433                 TEST_ASSERT_SUCCESS(rte_event_queue_attr_get(TEST_DEV_ID, i,
434                                     RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS,
435                                     &nb_atomic_flows),
436                                     "Queue nb_atomic_flows get failed");
437
438                 TEST_ASSERT_EQUAL(nb_atomic_flows, qconf.nb_atomic_flows,
439                                   "Wrong atomic flows value for queue%d", i);
440         }
441
442         return TEST_SUCCESS;
443 }
444
445 static int
446 test_eventdev_queue_attr_nb_atomic_order_sequences(void)
447 {
448         int i, ret;
449         struct rte_event_dev_info info;
450         struct rte_event_queue_conf qconf;
451         uint32_t nb_atomic_order_sequences;
452
453         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
454         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
455
456         uint32_t queue_count;
457         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
458                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
459                             "Queue count get failed");
460
461         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
462         TEST_ASSERT_SUCCESS(ret, "Failed to get queue 0's def conf");
463
464         if (qconf.nb_atomic_order_sequences == 0)
465                 /* Assume PMD doesn't support reordering */
466                 return -ENOTSUP;
467
468         qconf.schedule_type = RTE_SCHED_TYPE_ORDERED;
469
470         for (i = 0; i < (int)queue_count; i++) {
471                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
472                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
473         }
474
475         for (i = 0; i < (int)queue_count; i++) {
476                 TEST_ASSERT_SUCCESS(rte_event_queue_attr_get(TEST_DEV_ID, i,
477                             RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES,
478                             &nb_atomic_order_sequences),
479                             "Queue nb_atomic_order_sequencess get failed");
480
481                 TEST_ASSERT_EQUAL(nb_atomic_order_sequences,
482                                   qconf.nb_atomic_order_sequences,
483                                   "Wrong atomic order sequences value for queue%d",
484                                   i);
485         }
486
487         return TEST_SUCCESS;
488 }
489
490 static int
491 test_eventdev_queue_attr_event_queue_cfg(void)
492 {
493         int i, ret;
494         struct rte_event_dev_info info;
495         struct rte_event_queue_conf qconf;
496         uint32_t event_queue_cfg;
497
498         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
499         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
500
501         uint32_t queue_count;
502         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
503                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
504                             "Queue count get failed");
505
506         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
507         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 def conf");
508
509         qconf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
510
511         for (i = 0; i < (int)queue_count; i++) {
512                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
513                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
514         }
515
516         for (i = 0; i < (int)queue_count; i++) {
517                 TEST_ASSERT_SUCCESS(rte_event_queue_attr_get(TEST_DEV_ID, i,
518                                     RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG,
519                                     &event_queue_cfg),
520                                     "Queue event_queue_cfg get failed");
521
522                 TEST_ASSERT_EQUAL(event_queue_cfg, qconf.event_queue_cfg,
523                                   "Wrong event_queue_cfg value for queue%d",
524                                   i);
525         }
526
527         return TEST_SUCCESS;
528 }
529
530 static int
531 test_eventdev_port_default_conf_get(void)
532 {
533         int i, ret;
534         struct rte_event_port_conf pconf;
535
536         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, NULL);
537         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
538
539         uint32_t port_count;
540         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
541                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
542                                 &port_count), "Port count get failed");
543
544         ret = rte_event_port_default_conf_get(TEST_DEV_ID,
545                         port_count + 1, NULL);
546         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
547
548         for (i = 0; i < (int)port_count; i++) {
549                 ret = rte_event_port_default_conf_get(TEST_DEV_ID, i,
550                                                         &pconf);
551                 TEST_ASSERT_SUCCESS(ret, "Failed to get port%d info", i);
552         }
553
554         return TEST_SUCCESS;
555 }
556
557 static int
558 test_eventdev_port_setup(void)
559 {
560         int i, ret;
561         struct rte_event_dev_info info;
562         struct rte_event_port_conf pconf;
563
564         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
565         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
566
567         /* Negative cases */
568         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
569         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
570         pconf.new_event_threshold = info.max_num_events + 1;
571         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
572         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
573
574         pconf.new_event_threshold = info.max_num_events;
575         pconf.dequeue_depth = info.max_event_port_dequeue_depth + 1;
576         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
577         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
578
579         pconf.dequeue_depth = info.max_event_port_dequeue_depth;
580         pconf.enqueue_depth = info.max_event_port_enqueue_depth + 1;
581         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
582         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
583
584         ret = rte_event_port_setup(TEST_DEV_ID, info.max_event_ports,
585                                         &pconf);
586         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
587
588         /* Positive case */
589         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
590         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
591         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
592         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
593
594         uint32_t port_count;
595         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
596                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
597                                 &port_count), "Port count get failed");
598
599         for (i = 0; i < (int)port_count; i++) {
600                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
601                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
602         }
603
604         return TEST_SUCCESS;
605 }
606
607 static int
608 test_eventdev_port_attr_dequeue_depth(void)
609 {
610         int ret;
611         struct rte_event_dev_info info;
612         struct rte_event_port_conf pconf;
613
614         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
615         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
616
617         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
618         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
619         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
620         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
621
622         uint32_t value;
623         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
624                         RTE_EVENT_PORT_ATTR_DEQ_DEPTH, &value),
625                         0, "Call to get port dequeue depth failed");
626         TEST_ASSERT_EQUAL(value, pconf.dequeue_depth,
627                         "Wrong port dequeue depth");
628
629         return TEST_SUCCESS;
630 }
631
632 static int
633 test_eventdev_port_attr_enqueue_depth(void)
634 {
635         int ret;
636         struct rte_event_dev_info info;
637         struct rte_event_port_conf pconf;
638
639         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
640         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
641
642         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
643         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
644         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
645         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
646
647         uint32_t value;
648         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
649                         RTE_EVENT_PORT_ATTR_ENQ_DEPTH, &value),
650                         0, "Call to get port enqueue depth failed");
651         TEST_ASSERT_EQUAL(value, pconf.enqueue_depth,
652                         "Wrong port enqueue depth");
653
654         return TEST_SUCCESS;
655 }
656
657 static int
658 test_eventdev_port_attr_new_event_threshold(void)
659 {
660         int ret;
661         struct rte_event_dev_info info;
662         struct rte_event_port_conf pconf;
663
664         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
665         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
666
667         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
668         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
669         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
670         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
671
672         uint32_t value;
673         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
674                         RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD, &value),
675                         0, "Call to get port new event threshold failed");
676         TEST_ASSERT_EQUAL((int32_t) value, pconf.new_event_threshold,
677                         "Wrong port new event threshold");
678
679         return TEST_SUCCESS;
680 }
681
682 static int
683 test_eventdev_port_count(void)
684 {
685         int ret;
686         struct rte_event_dev_info info;
687
688         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
689         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
690
691         uint32_t port_count;
692         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
693                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
694                                 &port_count), "Port count get failed");
695         TEST_ASSERT_EQUAL(port_count, info.max_event_ports, "Wrong port count");
696
697         return TEST_SUCCESS;
698 }
699
700 static int
701 test_eventdev_timeout_ticks(void)
702 {
703         int ret;
704         uint64_t timeout_ticks;
705
706         ret = rte_event_dequeue_timeout_ticks(TEST_DEV_ID, 100, &timeout_ticks);
707         if (ret != -ENOTSUP)
708                 TEST_ASSERT_SUCCESS(ret, "Fail to get timeout_ticks");
709
710         return ret;
711 }
712
713
714 static int
715 test_eventdev_start_stop(void)
716 {
717         int i, ret;
718
719         ret = eventdev_configure_setup();
720         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
721
722         uint32_t queue_count;
723         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
724                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
725                             "Queue count get failed");
726         for (i = 0; i < (int)queue_count; i++) {
727                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
728                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
729         }
730
731         uint32_t port_count;
732         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
733                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
734                                 &port_count), "Port count get failed");
735
736         for (i = 0; i < (int)port_count; i++) {
737                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
738                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
739         }
740
741         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
742         TEST_ASSERT(ret == (int)queue_count, "Failed to link port, device %d",
743                     TEST_DEV_ID);
744
745         ret = rte_event_dev_start(TEST_DEV_ID);
746         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
747
748         rte_event_dev_stop(TEST_DEV_ID);
749         return TEST_SUCCESS;
750 }
751
752
753 static int
754 eventdev_setup_device(void)
755 {
756         int i, ret;
757
758         ret = eventdev_configure_setup();
759         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
760
761         uint32_t queue_count;
762         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
763                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
764                             "Queue count get failed");
765         for (i = 0; i < (int)queue_count; i++) {
766                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
767                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
768         }
769
770         uint32_t port_count;
771         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
772                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
773                                 &port_count), "Port count get failed");
774
775         for (i = 0; i < (int)port_count; i++) {
776                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
777                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
778         }
779
780         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
781         TEST_ASSERT(ret == (int)queue_count, "Failed to link port, device %d",
782                     TEST_DEV_ID);
783
784         ret = rte_event_dev_start(TEST_DEV_ID);
785         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
786
787         return TEST_SUCCESS;
788 }
789
790 static void
791 eventdev_stop_device(void)
792 {
793         rte_event_dev_stop(TEST_DEV_ID);
794 }
795
796 static int
797 test_eventdev_link(void)
798 {
799         int ret, nb_queues, i;
800         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
801         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
802
803         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
804         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
805                                  TEST_DEV_ID);
806
807         uint32_t queue_count;
808         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
809                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
810                             "Queue count get failed");
811         nb_queues = queue_count;
812         for (i = 0; i < nb_queues; i++) {
813                 queues[i] = i;
814                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
815         }
816
817         ret = rte_event_port_link(TEST_DEV_ID, 0, queues,
818                                         priorities, nb_queues);
819         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
820                                  TEST_DEV_ID, ret);
821         return TEST_SUCCESS;
822 }
823
824 static int
825 test_eventdev_unlink(void)
826 {
827         int ret, nb_queues, i;
828         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
829
830         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
831         TEST_ASSERT(ret >= 0, "Failed to unlink with NULL device%d",
832                                  TEST_DEV_ID);
833
834         uint32_t queue_count;
835         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
836                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
837                             "Queue count get failed");
838         nb_queues = queue_count;
839         for (i = 0; i < nb_queues; i++)
840                 queues[i] = i;
841
842
843         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
844         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
845                                  TEST_DEV_ID, ret);
846         return TEST_SUCCESS;
847 }
848
849 static int
850 test_eventdev_link_get(void)
851 {
852         int ret, i;
853         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
854         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
855
856         /* link all queues */
857         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
858         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
859                                  TEST_DEV_ID);
860
861         uint32_t queue_count;
862         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
863                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
864                             "Queue count get failed");
865         const int nb_queues = queue_count;
866         for (i = 0; i < nb_queues; i++)
867                 queues[i] = i;
868
869         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
870         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
871                                  TEST_DEV_ID, ret);
872
873         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
874         TEST_ASSERT(ret == 0, "(%d)Wrong link get=%d", TEST_DEV_ID, ret);
875
876         /* link all queues and get the links */
877         for (i = 0; i < nb_queues; i++) {
878                 queues[i] = i;
879                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
880         }
881         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
882                                          nb_queues);
883         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
884                                  TEST_DEV_ID, ret);
885         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
886         TEST_ASSERT(ret == nb_queues, "(%d)Wrong link get ret=%d expected=%d",
887                                  TEST_DEV_ID, ret, nb_queues);
888         /* unlink all*/
889         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
890         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
891                                  TEST_DEV_ID, ret);
892         /* link just one queue */
893         queues[0] = 0;
894         priorities[0] = RTE_EVENT_DEV_PRIORITY_NORMAL;
895
896         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities, 1);
897         TEST_ASSERT(ret == 1, "Failed to link(device%d) ret=%d",
898                                  TEST_DEV_ID, ret);
899         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
900         TEST_ASSERT(ret == 1, "(%d)Wrong link get ret=%d expected=%d",
901                                         TEST_DEV_ID, ret, 1);
902         /* unlink all*/
903         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
904         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
905                                  TEST_DEV_ID, ret);
906
907         /* 4links and 2 unlinks */
908         if (nb_queues >= 4) {
909                 for (i = 0; i < 4; i++) {
910                         queues[i] = i;
911                         priorities[i] = 0x40;
912                 }
913                 ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
914                                                 4);
915                 TEST_ASSERT(ret == 4, "Failed to link(device%d) ret=%d",
916                                          TEST_DEV_ID, ret);
917
918                 for (i = 0; i < 2; i++)
919                         queues[i] = i;
920
921                 ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, 2);
922                 TEST_ASSERT(ret == 2, "Failed to unlink(device%d) ret=%d",
923                                          TEST_DEV_ID, ret);
924                 ret = rte_event_port_links_get(TEST_DEV_ID, 0,
925                                                 queues, priorities);
926                 TEST_ASSERT(ret == 2, "(%d)Wrong link get ret=%d expected=%d",
927                                                 TEST_DEV_ID, ret, 2);
928                 TEST_ASSERT(queues[0] == 2, "ret=%d expected=%d", ret, 2);
929                 TEST_ASSERT(priorities[0] == 0x40, "ret=%d expected=%d",
930                                                         ret, 0x40);
931                 TEST_ASSERT(queues[1] == 3, "ret=%d expected=%d", ret, 3);
932                 TEST_ASSERT(priorities[1] == 0x40, "ret=%d expected=%d",
933                                         ret, 0x40);
934         }
935
936         return TEST_SUCCESS;
937 }
938
939 static int
940 test_eventdev_close(void)
941 {
942         rte_event_dev_stop(TEST_DEV_ID);
943         return rte_event_dev_close(TEST_DEV_ID);
944 }
945
946 static struct unit_test_suite eventdev_common_testsuite  = {
947         .suite_name = "eventdev common code unit test suite",
948         .setup = testsuite_setup,
949         .teardown = testsuite_teardown,
950         .unit_test_cases = {
951                 TEST_CASE_ST(NULL, NULL,
952                         test_eventdev_count),
953                 TEST_CASE_ST(NULL, NULL,
954                         test_eventdev_get_dev_id),
955                 TEST_CASE_ST(NULL, NULL,
956                         test_eventdev_socket_id),
957                 TEST_CASE_ST(NULL, NULL,
958                         test_eventdev_info_get),
959                 TEST_CASE_ST(NULL, NULL,
960                         test_eventdev_configure),
961                 TEST_CASE_ST(eventdev_configure_setup, NULL,
962                         test_eventdev_queue_default_conf_get),
963                 TEST_CASE_ST(eventdev_configure_setup, NULL,
964                         test_eventdev_queue_setup),
965                 TEST_CASE_ST(eventdev_configure_setup, NULL,
966                         test_eventdev_queue_count),
967                 TEST_CASE_ST(eventdev_configure_setup, NULL,
968                         test_eventdev_queue_attr_priority),
969                 TEST_CASE_ST(eventdev_configure_setup, NULL,
970                         test_eventdev_queue_attr_nb_atomic_flows),
971                 TEST_CASE_ST(eventdev_configure_setup, NULL,
972                         test_eventdev_queue_attr_nb_atomic_order_sequences),
973                 TEST_CASE_ST(eventdev_configure_setup, NULL,
974                         test_eventdev_queue_attr_event_queue_cfg),
975                 TEST_CASE_ST(eventdev_configure_setup, NULL,
976                         test_eventdev_port_default_conf_get),
977                 TEST_CASE_ST(eventdev_configure_setup, NULL,
978                         test_eventdev_port_setup),
979                 TEST_CASE_ST(eventdev_configure_setup, NULL,
980                         test_eventdev_port_attr_dequeue_depth),
981                 TEST_CASE_ST(eventdev_configure_setup, NULL,
982                         test_eventdev_port_attr_enqueue_depth),
983                 TEST_CASE_ST(eventdev_configure_setup, NULL,
984                         test_eventdev_port_attr_new_event_threshold),
985                 TEST_CASE_ST(eventdev_configure_setup, NULL,
986                         test_eventdev_port_count),
987                 TEST_CASE_ST(eventdev_configure_setup, NULL,
988                         test_eventdev_timeout_ticks),
989                 TEST_CASE_ST(NULL, NULL,
990                         test_eventdev_start_stop),
991                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
992                         test_eventdev_link),
993                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
994                         test_eventdev_unlink),
995                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
996                         test_eventdev_link_get),
997                 TEST_CASE_ST(eventdev_setup_device, NULL,
998                         test_eventdev_close),
999                 TEST_CASES_END() /**< NULL terminate unit test array */
1000         }
1001 };
1002
1003 static int
1004 test_eventdev_common(void)
1005 {
1006         return unit_test_suite_runner(&eventdev_common_testsuite);
1007 }
1008
1009 REGISTER_TEST_COMMAND(eventdev_common_autotest, test_eventdev_common);