7db9a9f5a6d0786ab33ebbe0c4feb67c960e1d69
[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
41 #include "test.h"
42
43 #define TEST_DEV_ID   0
44
45 static int
46 testsuite_setup(void)
47 {
48         RTE_BUILD_BUG_ON(sizeof(struct rte_event) != 16);
49         uint8_t count;
50         count = rte_event_dev_count();
51         if (!count) {
52                 printf("Failed to find a valid event device,"
53                         " testing with event_skeleton device\n");
54                 return rte_vdev_init("event_skeleton", NULL);
55         }
56         return TEST_SUCCESS;
57 }
58
59 static void
60 testsuite_teardown(void)
61 {
62 }
63
64 static int
65 test_eventdev_count(void)
66 {
67         uint8_t count;
68         count = rte_event_dev_count();
69         TEST_ASSERT(count > 0, "Invalid eventdev count %" PRIu8, count);
70         return TEST_SUCCESS;
71 }
72
73 static int
74 test_eventdev_get_dev_id(void)
75 {
76         int ret;
77         ret = rte_event_dev_get_dev_id("not_a_valid_eventdev_driver");
78         TEST_ASSERT_FAIL(ret, "Expected <0 for invalid dev name ret=%d", ret);
79         return TEST_SUCCESS;
80 }
81
82 static int
83 test_eventdev_socket_id(void)
84 {
85         int socket_id;
86         socket_id = rte_event_dev_socket_id(TEST_DEV_ID);
87         TEST_ASSERT(socket_id != -EINVAL, "Failed to get socket_id %d",
88                                 socket_id);
89         socket_id = rte_event_dev_socket_id(RTE_EVENT_MAX_DEVS);
90         TEST_ASSERT(socket_id == -EINVAL, "Expected -EINVAL %d", socket_id);
91
92         return TEST_SUCCESS;
93 }
94
95 static int
96 test_eventdev_info_get(void)
97 {
98         int ret;
99         struct rte_event_dev_info info;
100         ret = rte_event_dev_info_get(TEST_DEV_ID, NULL);
101         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
102         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
103         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
104         TEST_ASSERT(info.max_event_ports > 0,
105                         "Not enough event ports %d", info.max_event_ports);
106         TEST_ASSERT(info.max_event_queues > 0,
107                         "Not enough event queues %d", info.max_event_queues);
108         return TEST_SUCCESS;
109 }
110
111 static inline void
112 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
113                         struct rte_event_dev_info *info)
114 {
115         memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
116         dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
117         dev_conf->nb_event_ports = info->max_event_ports;
118         dev_conf->nb_event_queues = info->max_event_queues;
119         dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
120         dev_conf->nb_event_port_dequeue_depth =
121                         info->max_event_port_dequeue_depth;
122         dev_conf->nb_event_port_enqueue_depth =
123                         info->max_event_port_enqueue_depth;
124         dev_conf->nb_event_port_enqueue_depth =
125                         info->max_event_port_enqueue_depth;
126         dev_conf->nb_events_limit =
127                         info->max_num_events;
128 }
129
130 static int
131 test_ethdev_config_run(struct rte_event_dev_config *dev_conf,
132                 struct rte_event_dev_info *info,
133                 void (*fn)(struct rte_event_dev_config *dev_conf,
134                         struct rte_event_dev_info *info))
135 {
136         devconf_set_default_sane_values(dev_conf, info);
137         fn(dev_conf, info);
138         return rte_event_dev_configure(TEST_DEV_ID, dev_conf);
139 }
140
141 static void
142 max_dequeue_limit(struct rte_event_dev_config *dev_conf,
143                   struct rte_event_dev_info *info)
144 {
145         dev_conf->dequeue_timeout_ns = info->max_dequeue_timeout_ns + 1;
146 }
147
148 static void
149 max_events_limit(struct rte_event_dev_config *dev_conf,
150                   struct rte_event_dev_info *info)
151 {
152         dev_conf->nb_events_limit  = info->max_num_events + 1;
153 }
154
155 static void
156 max_event_ports(struct rte_event_dev_config *dev_conf,
157                   struct rte_event_dev_info *info)
158 {
159         dev_conf->nb_event_ports = info->max_event_ports + 1;
160 }
161
162 static void
163 max_event_queues(struct rte_event_dev_config *dev_conf,
164                   struct rte_event_dev_info *info)
165 {
166         dev_conf->nb_event_queues = info->max_event_queues + 1;
167 }
168
169 static void
170 max_event_queue_flows(struct rte_event_dev_config *dev_conf,
171                   struct rte_event_dev_info *info)
172 {
173         dev_conf->nb_event_queue_flows = info->max_event_queue_flows + 1;
174 }
175
176 static void
177 max_event_port_dequeue_depth(struct rte_event_dev_config *dev_conf,
178                   struct rte_event_dev_info *info)
179 {
180         dev_conf->nb_event_port_dequeue_depth =
181                 info->max_event_port_dequeue_depth + 1;
182 }
183
184 static void
185 max_event_port_enqueue_depth(struct rte_event_dev_config *dev_conf,
186                   struct rte_event_dev_info *info)
187 {
188         dev_conf->nb_event_port_enqueue_depth =
189                 info->max_event_port_enqueue_depth + 1;
190 }
191
192
193 static int
194 test_eventdev_configure(void)
195 {
196         int ret;
197         struct rte_event_dev_config dev_conf;
198         struct rte_event_dev_info info;
199         ret = rte_event_dev_configure(TEST_DEV_ID, NULL);
200         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
201
202         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
203         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
204
205         /* Check limits */
206         TEST_ASSERT_EQUAL(-EINVAL,
207                 test_ethdev_config_run(&dev_conf, &info, max_dequeue_limit),
208                  "Config negative test failed");
209         TEST_ASSERT_EQUAL(-EINVAL,
210                 test_ethdev_config_run(&dev_conf, &info, max_events_limit),
211                  "Config negative test failed");
212         TEST_ASSERT_EQUAL(-EINVAL,
213                 test_ethdev_config_run(&dev_conf, &info, max_event_ports),
214                  "Config negative test failed");
215         TEST_ASSERT_EQUAL(-EINVAL,
216                 test_ethdev_config_run(&dev_conf, &info, max_event_queues),
217                  "Config negative test failed");
218         TEST_ASSERT_EQUAL(-EINVAL,
219                 test_ethdev_config_run(&dev_conf, &info, max_event_queue_flows),
220                  "Config negative test failed");
221         TEST_ASSERT_EQUAL(-EINVAL,
222                 test_ethdev_config_run(&dev_conf, &info,
223                         max_event_port_dequeue_depth),
224                          "Config negative test failed");
225         TEST_ASSERT_EQUAL(-EINVAL,
226                 test_ethdev_config_run(&dev_conf, &info,
227                 max_event_port_enqueue_depth),
228                  "Config negative test failed");
229
230         /* Positive case */
231         devconf_set_default_sane_values(&dev_conf, &info);
232         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
233         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
234
235         /* re-configure */
236         devconf_set_default_sane_values(&dev_conf, &info);
237         dev_conf.nb_event_ports = RTE_MAX(info.max_event_ports/2, 1);
238         dev_conf.nb_event_queues = RTE_MAX(info.max_event_queues/2, 1);
239         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
240         TEST_ASSERT_SUCCESS(ret, "Failed to re configure eventdev");
241
242         /* re-configure back to max_event_queues and max_event_ports */
243         devconf_set_default_sane_values(&dev_conf, &info);
244         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
245         TEST_ASSERT_SUCCESS(ret, "Failed to re-configure eventdev");
246
247         return TEST_SUCCESS;
248
249 }
250
251 static int
252 eventdev_configure_setup(void)
253 {
254         int ret;
255         struct rte_event_dev_config dev_conf;
256         struct rte_event_dev_info info;
257
258         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
259         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
260         devconf_set_default_sane_values(&dev_conf, &info);
261         ret = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
262         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
263
264         return TEST_SUCCESS;
265 }
266
267 static int
268 test_eventdev_queue_default_conf_get(void)
269 {
270         int i, ret;
271         struct rte_event_queue_conf qconf;
272
273         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, NULL);
274         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
275
276         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
277                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
278                                                  &qconf);
279                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d info", i);
280         }
281
282         return TEST_SUCCESS;
283 }
284
285 static int
286 test_eventdev_queue_setup(void)
287 {
288         int i, ret;
289         struct rte_event_dev_info info;
290         struct rte_event_queue_conf qconf;
291
292         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
293         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
294
295         /* Negative cases */
296         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
297         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
298         qconf.event_queue_cfg = (RTE_EVENT_QUEUE_CFG_ALL_TYPES &
299                  RTE_EVENT_QUEUE_CFG_TYPE_MASK);
300         qconf.nb_atomic_flows = info.max_event_queue_flows + 1;
301         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
302         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
303
304         qconf.nb_atomic_flows = info.max_event_queue_flows;
305         qconf.event_queue_cfg = (RTE_EVENT_QUEUE_CFG_ORDERED_ONLY &
306                  RTE_EVENT_QUEUE_CFG_TYPE_MASK);
307         qconf.nb_atomic_order_sequences = info.max_event_queue_flows + 1;
308         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
309         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
310
311         ret = rte_event_queue_setup(TEST_DEV_ID, info.max_event_queues,
312                                         &qconf);
313         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
314
315         /* Positive case */
316         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
317         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
318         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
319         TEST_ASSERT_SUCCESS(ret, "Failed to setup queue0");
320
321
322         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
323                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
324                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
325         }
326
327         return TEST_SUCCESS;
328 }
329
330 static int
331 test_eventdev_queue_count(void)
332 {
333         int ret;
334         struct rte_event_dev_info info;
335
336         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
337         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
338
339         TEST_ASSERT_EQUAL(rte_event_queue_count(TEST_DEV_ID),
340                  info.max_event_queues, "Wrong queue count");
341
342         return TEST_SUCCESS;
343 }
344
345 static int
346 test_eventdev_queue_priority(void)
347 {
348         int i, ret;
349         struct rte_event_dev_info info;
350         struct rte_event_queue_conf qconf;
351         uint8_t priority;
352
353         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
354         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
355
356         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
357                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
358                                         &qconf);
359                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d def conf", i);
360                 qconf.priority = i %  RTE_EVENT_DEV_PRIORITY_LOWEST;
361                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
362                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
363         }
364
365         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
366                 priority =  rte_event_queue_priority(TEST_DEV_ID, i);
367                 if (info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
368                         TEST_ASSERT_EQUAL(priority,
369                          i %  RTE_EVENT_DEV_PRIORITY_LOWEST,
370                          "Wrong priority value for queue%d", i);
371                 else
372                         TEST_ASSERT_EQUAL(priority,
373                          RTE_EVENT_DEV_PRIORITY_NORMAL,
374                          "Wrong priority value for queue%d", i);
375         }
376
377         return TEST_SUCCESS;
378 }
379
380 static int
381 test_eventdev_port_default_conf_get(void)
382 {
383         int i, ret;
384         struct rte_event_port_conf pconf;
385
386         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, NULL);
387         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
388
389         ret = rte_event_port_default_conf_get(TEST_DEV_ID,
390                         rte_event_port_count(TEST_DEV_ID) + 1, NULL);
391         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
392
393         for (i = 0; i < rte_event_port_count(TEST_DEV_ID); i++) {
394                 ret = rte_event_port_default_conf_get(TEST_DEV_ID, i,
395                                                         &pconf);
396                 TEST_ASSERT_SUCCESS(ret, "Failed to get port%d info", i);
397         }
398
399         return TEST_SUCCESS;
400 }
401
402 static int
403 test_eventdev_port_setup(void)
404 {
405         int i, ret;
406         struct rte_event_dev_info info;
407         struct rte_event_port_conf pconf;
408
409         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
410         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
411
412         /* Negative cases */
413         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
414         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
415         pconf.new_event_threshold = info.max_num_events + 1;
416         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
417         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
418
419         pconf.new_event_threshold = info.max_num_events;
420         pconf.dequeue_depth = info.max_event_port_dequeue_depth + 1;
421         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
422         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
423
424         pconf.dequeue_depth = info.max_event_port_dequeue_depth;
425         pconf.enqueue_depth = info.max_event_port_enqueue_depth + 1;
426         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
427         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
428
429         ret = rte_event_port_setup(TEST_DEV_ID, info.max_event_ports,
430                                         &pconf);
431         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
432
433         /* Positive case */
434         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
435         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
436         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
437         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
438
439
440         for (i = 0; i < rte_event_port_count(TEST_DEV_ID); i++) {
441                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
442                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
443         }
444
445         return TEST_SUCCESS;
446 }
447
448 static int
449 test_eventdev_dequeue_depth(void)
450 {
451         int ret;
452         struct rte_event_dev_info info;
453         struct rte_event_port_conf pconf;
454
455         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
456         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
457
458         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
459         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
460         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
461         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
462
463         uint32_t value;
464         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
465                         RTE_EVENT_PORT_ATTR_DEQ_DEPTH, &value),
466                         0, "Call to port dequeue depth failed");
467         TEST_ASSERT_EQUAL(value, pconf.dequeue_depth,
468                         "Wrong port dequeue depth");
469
470         return TEST_SUCCESS;
471 }
472
473 static int
474 test_eventdev_enqueue_depth(void)
475 {
476         int ret;
477         struct rte_event_dev_info info;
478         struct rte_event_port_conf pconf;
479
480         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
481         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
482
483         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
484         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
485         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
486         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
487
488         uint32_t value;
489         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
490                         RTE_EVENT_PORT_ATTR_ENQ_DEPTH, &value),
491                         0, "Call to port enqueue depth failed");
492         TEST_ASSERT_EQUAL(value, pconf.enqueue_depth,
493                         "Wrong port enqueue depth");
494
495         return TEST_SUCCESS;
496 }
497
498 static int
499 test_eventdev_port_count(void)
500 {
501         int ret;
502         struct rte_event_dev_info info;
503
504         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
505         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
506
507         TEST_ASSERT_EQUAL(rte_event_port_count(TEST_DEV_ID),
508                  info.max_event_ports, "Wrong port count");
509
510         return TEST_SUCCESS;
511 }
512
513 static int
514 test_eventdev_timeout_ticks(void)
515 {
516         int ret;
517         uint64_t timeout_ticks;
518
519         ret = rte_event_dequeue_timeout_ticks(TEST_DEV_ID, 100, &timeout_ticks);
520         if (ret != -ENOTSUP)
521                 TEST_ASSERT_SUCCESS(ret, "Fail to get timeout_ticks");
522
523         return ret;
524 }
525
526
527 static int
528 test_eventdev_start_stop(void)
529 {
530         int i, ret;
531
532         ret = eventdev_configure_setup();
533         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
534
535         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
536                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
537                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
538         }
539
540         for (i = 0; i < rte_event_port_count(TEST_DEV_ID); i++) {
541                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
542                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
543         }
544
545         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
546         TEST_ASSERT(ret == rte_event_queue_count(TEST_DEV_ID),
547                         "Failed to link port, device %d", TEST_DEV_ID);
548
549         ret = rte_event_dev_start(TEST_DEV_ID);
550         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
551
552         rte_event_dev_stop(TEST_DEV_ID);
553         return TEST_SUCCESS;
554 }
555
556
557 static int
558 eventdev_setup_device(void)
559 {
560         int i, ret;
561
562         ret = eventdev_configure_setup();
563         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
564
565         for (i = 0; i < rte_event_queue_count(TEST_DEV_ID); i++) {
566                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
567                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
568         }
569
570         for (i = 0; i < rte_event_port_count(TEST_DEV_ID); i++) {
571                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
572                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
573         }
574
575         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
576         TEST_ASSERT(ret == rte_event_queue_count(TEST_DEV_ID),
577                         "Failed to link port, device %d", TEST_DEV_ID);
578
579         ret = rte_event_dev_start(TEST_DEV_ID);
580         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
581
582         return TEST_SUCCESS;
583 }
584
585 static void
586 eventdev_stop_device(void)
587 {
588         rte_event_dev_stop(TEST_DEV_ID);
589 }
590
591 static int
592 test_eventdev_link(void)
593 {
594         int ret, nb_queues, i;
595         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
596         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
597
598         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
599         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
600                                  TEST_DEV_ID);
601
602         nb_queues = rte_event_queue_count(TEST_DEV_ID);
603         for (i = 0; i < nb_queues; i++) {
604                 queues[i] = i;
605                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
606         }
607
608         ret = rte_event_port_link(TEST_DEV_ID, 0, queues,
609                                         priorities, nb_queues);
610         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
611                                  TEST_DEV_ID, ret);
612         return TEST_SUCCESS;
613 }
614
615 static int
616 test_eventdev_unlink(void)
617 {
618         int ret, nb_queues, i;
619         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
620
621         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
622         TEST_ASSERT(ret >= 0, "Failed to unlink with NULL device%d",
623                                  TEST_DEV_ID);
624
625         nb_queues = rte_event_queue_count(TEST_DEV_ID);
626         for (i = 0; i < nb_queues; i++)
627                 queues[i] = i;
628
629
630         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
631         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
632                                  TEST_DEV_ID, ret);
633         return TEST_SUCCESS;
634 }
635
636 static int
637 test_eventdev_link_get(void)
638 {
639         int ret, nb_queues, i;
640         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
641         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
642
643         /* link all queues */
644         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
645         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
646                                  TEST_DEV_ID);
647
648         nb_queues = rte_event_queue_count(TEST_DEV_ID);
649         for (i = 0; i < nb_queues; i++)
650                 queues[i] = i;
651
652         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
653         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
654                                  TEST_DEV_ID, ret);
655
656         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
657         TEST_ASSERT(ret == 0, "(%d)Wrong link get=%d", TEST_DEV_ID, ret);
658
659         /* link all queues and get the links */
660         nb_queues = rte_event_queue_count(TEST_DEV_ID);
661         for (i = 0; i < nb_queues; i++) {
662                 queues[i] = i;
663                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
664         }
665         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
666                                          nb_queues);
667         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
668                                  TEST_DEV_ID, ret);
669         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
670         TEST_ASSERT(ret == nb_queues, "(%d)Wrong link get ret=%d expected=%d",
671                                  TEST_DEV_ID, ret, nb_queues);
672         /* unlink all*/
673         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
674         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
675                                  TEST_DEV_ID, ret);
676         /* link just one queue */
677         queues[0] = 0;
678         priorities[0] = RTE_EVENT_DEV_PRIORITY_NORMAL;
679
680         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities, 1);
681         TEST_ASSERT(ret == 1, "Failed to link(device%d) ret=%d",
682                                  TEST_DEV_ID, ret);
683         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
684         TEST_ASSERT(ret == 1, "(%d)Wrong link get ret=%d expected=%d",
685                                         TEST_DEV_ID, ret, 1);
686         /* unlink all*/
687         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
688         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
689                                  TEST_DEV_ID, ret);
690         /* 4links and 2 unlinks */
691         nb_queues = rte_event_queue_count(TEST_DEV_ID);
692         if (nb_queues >= 4) {
693                 for (i = 0; i < 4; i++) {
694                         queues[i] = i;
695                         priorities[i] = 0x40;
696                 }
697                 ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
698                                                 4);
699                 TEST_ASSERT(ret == 4, "Failed to link(device%d) ret=%d",
700                                          TEST_DEV_ID, ret);
701
702                 for (i = 0; i < 2; i++)
703                         queues[i] = i;
704
705                 ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, 2);
706                 TEST_ASSERT(ret == 2, "Failed to unlink(device%d) ret=%d",
707                                          TEST_DEV_ID, ret);
708                 ret = rte_event_port_links_get(TEST_DEV_ID, 0,
709                                                 queues, priorities);
710                 TEST_ASSERT(ret == 2, "(%d)Wrong link get ret=%d expected=%d",
711                                                 TEST_DEV_ID, ret, 2);
712                 TEST_ASSERT(queues[0] == 2, "ret=%d expected=%d", ret, 2);
713                 TEST_ASSERT(priorities[0] == 0x40, "ret=%d expected=%d",
714                                                         ret, 0x40);
715                 TEST_ASSERT(queues[1] == 3, "ret=%d expected=%d", ret, 3);
716                 TEST_ASSERT(priorities[1] == 0x40, "ret=%d expected=%d",
717                                         ret, 0x40);
718         }
719
720         return TEST_SUCCESS;
721 }
722
723 static int
724 test_eventdev_close(void)
725 {
726         rte_event_dev_stop(TEST_DEV_ID);
727         return rte_event_dev_close(TEST_DEV_ID);
728 }
729
730 static struct unit_test_suite eventdev_common_testsuite  = {
731         .suite_name = "eventdev common code unit test suite",
732         .setup = testsuite_setup,
733         .teardown = testsuite_teardown,
734         .unit_test_cases = {
735                 TEST_CASE_ST(NULL, NULL,
736                         test_eventdev_count),
737                 TEST_CASE_ST(NULL, NULL,
738                         test_eventdev_get_dev_id),
739                 TEST_CASE_ST(NULL, NULL,
740                         test_eventdev_socket_id),
741                 TEST_CASE_ST(NULL, NULL,
742                         test_eventdev_info_get),
743                 TEST_CASE_ST(NULL, NULL,
744                         test_eventdev_configure),
745                 TEST_CASE_ST(eventdev_configure_setup, NULL,
746                         test_eventdev_queue_default_conf_get),
747                 TEST_CASE_ST(eventdev_configure_setup, NULL,
748                         test_eventdev_queue_setup),
749                 TEST_CASE_ST(eventdev_configure_setup, NULL,
750                         test_eventdev_queue_count),
751                 TEST_CASE_ST(eventdev_configure_setup, NULL,
752                         test_eventdev_queue_priority),
753                 TEST_CASE_ST(eventdev_configure_setup, NULL,
754                         test_eventdev_port_default_conf_get),
755                 TEST_CASE_ST(eventdev_configure_setup, NULL,
756                         test_eventdev_port_setup),
757                 TEST_CASE_ST(eventdev_configure_setup, NULL,
758                         test_eventdev_dequeue_depth),
759                 TEST_CASE_ST(eventdev_configure_setup, NULL,
760                         test_eventdev_enqueue_depth),
761                 TEST_CASE_ST(eventdev_configure_setup, NULL,
762                         test_eventdev_port_count),
763                 TEST_CASE_ST(eventdev_configure_setup, NULL,
764                         test_eventdev_timeout_ticks),
765                 TEST_CASE_ST(NULL, NULL,
766                         test_eventdev_start_stop),
767                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
768                         test_eventdev_link),
769                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
770                         test_eventdev_unlink),
771                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
772                         test_eventdev_link_get),
773                 TEST_CASE_ST(eventdev_setup_device, NULL,
774                         test_eventdev_close),
775                 TEST_CASES_END() /**< NULL terminate unit test array */
776         }
777 };
778
779 static int
780 test_eventdev_common(void)
781 {
782         return unit_test_suite_runner(&eventdev_common_testsuite);
783 }
784
785 REGISTER_TEST_COMMAND(eventdev_common_autotest, test_eventdev_common);