47514e631d312b1411b742b284c4a24da5e342da
[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         uint32_t queue_count;
277         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
278                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
279                             "Queue count get failed");
280
281         for (i = 0; i < (int)queue_count; i++) {
282                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
283                                                  &qconf);
284                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d info", i);
285         }
286
287         return TEST_SUCCESS;
288 }
289
290 static int
291 test_eventdev_queue_setup(void)
292 {
293         int i, ret;
294         struct rte_event_dev_info info;
295         struct rte_event_queue_conf qconf;
296
297         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
298         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
299
300         /* Negative cases */
301         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
302         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
303         qconf.event_queue_cfg = (RTE_EVENT_QUEUE_CFG_ALL_TYPES &
304                  RTE_EVENT_QUEUE_CFG_TYPE_MASK);
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.event_queue_cfg = (RTE_EVENT_QUEUE_CFG_ORDERED_ONLY &
311                  RTE_EVENT_QUEUE_CFG_TYPE_MASK);
312         qconf.nb_atomic_order_sequences = info.max_event_queue_flows + 1;
313         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
314         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
315
316         ret = rte_event_queue_setup(TEST_DEV_ID, info.max_event_queues,
317                                         &qconf);
318         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
319
320         /* Positive case */
321         ret = rte_event_queue_default_conf_get(TEST_DEV_ID, 0, &qconf);
322         TEST_ASSERT_SUCCESS(ret, "Failed to get queue0 info");
323         ret = rte_event_queue_setup(TEST_DEV_ID, 0, &qconf);
324         TEST_ASSERT_SUCCESS(ret, "Failed to setup queue0");
325
326         uint32_t queue_count;
327         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
328                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
329                             "Queue count get failed");
330
331         for (i = 0; i < (int)queue_count; i++) {
332                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
333                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
334         }
335
336         return TEST_SUCCESS;
337 }
338
339 static int
340 test_eventdev_queue_count(void)
341 {
342         int ret;
343         struct rte_event_dev_info info;
344
345         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
346         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
347
348         uint32_t queue_count;
349         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
350                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
351                             "Queue count get failed");
352         TEST_ASSERT_EQUAL(queue_count, info.max_event_queues,
353                           "Wrong queue count");
354
355         return TEST_SUCCESS;
356 }
357
358 static int
359 test_eventdev_queue_priority(void)
360 {
361         int i, ret;
362         struct rte_event_dev_info info;
363         struct rte_event_queue_conf qconf;
364         uint8_t priority;
365
366         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
367         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
368
369         uint32_t queue_count;
370         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
371                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
372                             "Queue count get failed");
373
374         for (i = 0; i < (int)queue_count; i++) {
375                 ret = rte_event_queue_default_conf_get(TEST_DEV_ID, i,
376                                         &qconf);
377                 TEST_ASSERT_SUCCESS(ret, "Failed to get queue%d def conf", i);
378                 qconf.priority = i %  RTE_EVENT_DEV_PRIORITY_LOWEST;
379                 ret = rte_event_queue_setup(TEST_DEV_ID, i, &qconf);
380                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
381         }
382
383         for (i = 0; i < (int)queue_count; i++) {
384                 priority =  rte_event_queue_priority(TEST_DEV_ID, i);
385
386                 if (info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
387                         TEST_ASSERT_EQUAL(priority,
388                          i %  RTE_EVENT_DEV_PRIORITY_LOWEST,
389                          "Wrong priority value for queue%d", i);
390                 else
391                         TEST_ASSERT_EQUAL(priority,
392                          RTE_EVENT_DEV_PRIORITY_NORMAL,
393                          "Wrong priority value for queue%d", i);
394         }
395
396         return TEST_SUCCESS;
397 }
398
399 static int
400 test_eventdev_port_default_conf_get(void)
401 {
402         int i, ret;
403         struct rte_event_port_conf pconf;
404
405         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, NULL);
406         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
407
408         uint32_t port_count;
409         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
410                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
411                                 &port_count), "Port count get failed");
412
413         ret = rte_event_port_default_conf_get(TEST_DEV_ID,
414                         port_count + 1, NULL);
415         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
416
417         for (i = 0; i < (int)port_count; i++) {
418                 ret = rte_event_port_default_conf_get(TEST_DEV_ID, i,
419                                                         &pconf);
420                 TEST_ASSERT_SUCCESS(ret, "Failed to get port%d info", i);
421         }
422
423         return TEST_SUCCESS;
424 }
425
426 static int
427 test_eventdev_port_setup(void)
428 {
429         int i, ret;
430         struct rte_event_dev_info info;
431         struct rte_event_port_conf pconf;
432
433         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
434         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
435
436         /* Negative cases */
437         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
438         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
439         pconf.new_event_threshold = info.max_num_events + 1;
440         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
441         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
442
443         pconf.new_event_threshold = info.max_num_events;
444         pconf.dequeue_depth = info.max_event_port_dequeue_depth + 1;
445         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
446         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
447
448         pconf.dequeue_depth = info.max_event_port_dequeue_depth;
449         pconf.enqueue_depth = info.max_event_port_enqueue_depth + 1;
450         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
451         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
452
453         ret = rte_event_port_setup(TEST_DEV_ID, info.max_event_ports,
454                                         &pconf);
455         TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret);
456
457         /* Positive case */
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 port_count;
464         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
465                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
466                                 &port_count), "Port count get failed");
467
468         for (i = 0; i < (int)port_count; i++) {
469                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
470                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
471         }
472
473         return TEST_SUCCESS;
474 }
475
476 static int
477 test_eventdev_dequeue_depth(void)
478 {
479         int ret;
480         struct rte_event_dev_info info;
481         struct rte_event_port_conf pconf;
482
483         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
484         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
485
486         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
487         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
488         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
489         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
490
491         uint32_t value;
492         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
493                         RTE_EVENT_PORT_ATTR_DEQ_DEPTH, &value),
494                         0, "Call to port dequeue depth failed");
495         TEST_ASSERT_EQUAL(value, pconf.dequeue_depth,
496                         "Wrong port dequeue depth");
497
498         return TEST_SUCCESS;
499 }
500
501 static int
502 test_eventdev_enqueue_depth(void)
503 {
504         int ret;
505         struct rte_event_dev_info info;
506         struct rte_event_port_conf pconf;
507
508         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
509         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
510
511         ret = rte_event_port_default_conf_get(TEST_DEV_ID, 0, &pconf);
512         TEST_ASSERT_SUCCESS(ret, "Failed to get port0 info");
513         ret = rte_event_port_setup(TEST_DEV_ID, 0, &pconf);
514         TEST_ASSERT_SUCCESS(ret, "Failed to setup port0");
515
516         uint32_t value;
517         TEST_ASSERT_EQUAL(rte_event_port_attr_get(TEST_DEV_ID, 0,
518                         RTE_EVENT_PORT_ATTR_ENQ_DEPTH, &value),
519                         0, "Call to port enqueue depth failed");
520         TEST_ASSERT_EQUAL(value, pconf.enqueue_depth,
521                         "Wrong port enqueue depth");
522
523         return TEST_SUCCESS;
524 }
525
526 static int
527 test_eventdev_port_count(void)
528 {
529         int ret;
530         struct rte_event_dev_info info;
531
532         ret = rte_event_dev_info_get(TEST_DEV_ID, &info);
533         TEST_ASSERT_SUCCESS(ret, "Failed to get event dev info");
534
535         uint32_t port_count;
536         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
537                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
538                                 &port_count), "Port count get failed");
539         TEST_ASSERT_EQUAL(port_count, info.max_event_ports, "Wrong port count");
540
541         return TEST_SUCCESS;
542 }
543
544 static int
545 test_eventdev_timeout_ticks(void)
546 {
547         int ret;
548         uint64_t timeout_ticks;
549
550         ret = rte_event_dequeue_timeout_ticks(TEST_DEV_ID, 100, &timeout_ticks);
551         if (ret != -ENOTSUP)
552                 TEST_ASSERT_SUCCESS(ret, "Fail to get timeout_ticks");
553
554         return ret;
555 }
556
557
558 static int
559 test_eventdev_start_stop(void)
560 {
561         int i, ret;
562
563         ret = eventdev_configure_setup();
564         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
565
566         uint32_t queue_count;
567         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
568                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
569                             "Queue count get failed");
570         for (i = 0; i < (int)queue_count; i++) {
571                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
572                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
573         }
574
575         uint32_t port_count;
576         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
577                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
578                                 &port_count), "Port count get failed");
579
580         for (i = 0; i < (int)port_count; i++) {
581                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
582                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
583         }
584
585         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
586         TEST_ASSERT(ret == (int)queue_count, "Failed to link port, device %d",
587                     TEST_DEV_ID);
588
589         ret = rte_event_dev_start(TEST_DEV_ID);
590         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
591
592         rte_event_dev_stop(TEST_DEV_ID);
593         return TEST_SUCCESS;
594 }
595
596
597 static int
598 eventdev_setup_device(void)
599 {
600         int i, ret;
601
602         ret = eventdev_configure_setup();
603         TEST_ASSERT_SUCCESS(ret, "Failed to configure eventdev");
604
605         uint32_t queue_count;
606         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
607                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
608                             "Queue count get failed");
609         for (i = 0; i < (int)queue_count; i++) {
610                 ret = rte_event_queue_setup(TEST_DEV_ID, i, NULL);
611                 TEST_ASSERT_SUCCESS(ret, "Failed to setup queue%d", i);
612         }
613
614         uint32_t port_count;
615         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
616                                 RTE_EVENT_DEV_ATTR_PORT_COUNT,
617                                 &port_count), "Port count get failed");
618
619         for (i = 0; i < (int)port_count; i++) {
620                 ret = rte_event_port_setup(TEST_DEV_ID, i, NULL);
621                 TEST_ASSERT_SUCCESS(ret, "Failed to setup port%d", i);
622         }
623
624         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
625         TEST_ASSERT(ret == (int)queue_count, "Failed to link port, device %d",
626                     TEST_DEV_ID);
627
628         ret = rte_event_dev_start(TEST_DEV_ID);
629         TEST_ASSERT_SUCCESS(ret, "Failed to start device%d", TEST_DEV_ID);
630
631         return TEST_SUCCESS;
632 }
633
634 static void
635 eventdev_stop_device(void)
636 {
637         rte_event_dev_stop(TEST_DEV_ID);
638 }
639
640 static int
641 test_eventdev_link(void)
642 {
643         int ret, nb_queues, i;
644         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
645         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
646
647         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
648         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
649                                  TEST_DEV_ID);
650
651         uint32_t queue_count;
652         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
653                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
654                             "Queue count get failed");
655         nb_queues = queue_count;
656         for (i = 0; i < nb_queues; i++) {
657                 queues[i] = i;
658                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
659         }
660
661         ret = rte_event_port_link(TEST_DEV_ID, 0, queues,
662                                         priorities, nb_queues);
663         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
664                                  TEST_DEV_ID, ret);
665         return TEST_SUCCESS;
666 }
667
668 static int
669 test_eventdev_unlink(void)
670 {
671         int ret, nb_queues, i;
672         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
673
674         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
675         TEST_ASSERT(ret >= 0, "Failed to unlink with NULL device%d",
676                                  TEST_DEV_ID);
677
678         uint32_t queue_count;
679         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
680                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
681                             "Queue count get failed");
682         nb_queues = queue_count;
683         for (i = 0; i < nb_queues; i++)
684                 queues[i] = i;
685
686
687         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
688         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
689                                  TEST_DEV_ID, ret);
690         return TEST_SUCCESS;
691 }
692
693 static int
694 test_eventdev_link_get(void)
695 {
696         int ret, i;
697         uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
698         uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
699
700         /* link all queues */
701         ret = rte_event_port_link(TEST_DEV_ID, 0, NULL, NULL, 0);
702         TEST_ASSERT(ret >= 0, "Failed to link with NULL device%d",
703                                  TEST_DEV_ID);
704
705         uint32_t queue_count;
706         TEST_ASSERT_SUCCESS(rte_event_dev_attr_get(TEST_DEV_ID,
707                             RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &queue_count),
708                             "Queue count get failed");
709         const int nb_queues = queue_count;
710         for (i = 0; i < nb_queues; i++)
711                 queues[i] = i;
712
713         ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, nb_queues);
714         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
715                                  TEST_DEV_ID, ret);
716
717         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
718         TEST_ASSERT(ret == 0, "(%d)Wrong link get=%d", TEST_DEV_ID, ret);
719
720         /* link all queues and get the links */
721         for (i = 0; i < nb_queues; i++) {
722                 queues[i] = i;
723                 priorities[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
724         }
725         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
726                                          nb_queues);
727         TEST_ASSERT(ret == nb_queues, "Failed to link(device%d) ret=%d",
728                                  TEST_DEV_ID, ret);
729         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
730         TEST_ASSERT(ret == nb_queues, "(%d)Wrong link get ret=%d expected=%d",
731                                  TEST_DEV_ID, ret, nb_queues);
732         /* unlink all*/
733         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
734         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
735                                  TEST_DEV_ID, ret);
736         /* link just one queue */
737         queues[0] = 0;
738         priorities[0] = RTE_EVENT_DEV_PRIORITY_NORMAL;
739
740         ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities, 1);
741         TEST_ASSERT(ret == 1, "Failed to link(device%d) ret=%d",
742                                  TEST_DEV_ID, ret);
743         ret = rte_event_port_links_get(TEST_DEV_ID, 0, queues, priorities);
744         TEST_ASSERT(ret == 1, "(%d)Wrong link get ret=%d expected=%d",
745                                         TEST_DEV_ID, ret, 1);
746         /* unlink all*/
747         ret = rte_event_port_unlink(TEST_DEV_ID, 0, NULL, 0);
748         TEST_ASSERT(ret == nb_queues, "Failed to unlink(device%d) ret=%d",
749                                  TEST_DEV_ID, ret);
750
751         /* 4links and 2 unlinks */
752         if (nb_queues >= 4) {
753                 for (i = 0; i < 4; i++) {
754                         queues[i] = i;
755                         priorities[i] = 0x40;
756                 }
757                 ret = rte_event_port_link(TEST_DEV_ID, 0, queues, priorities,
758                                                 4);
759                 TEST_ASSERT(ret == 4, "Failed to link(device%d) ret=%d",
760                                          TEST_DEV_ID, ret);
761
762                 for (i = 0; i < 2; i++)
763                         queues[i] = i;
764
765                 ret = rte_event_port_unlink(TEST_DEV_ID, 0, queues, 2);
766                 TEST_ASSERT(ret == 2, "Failed to unlink(device%d) ret=%d",
767                                          TEST_DEV_ID, ret);
768                 ret = rte_event_port_links_get(TEST_DEV_ID, 0,
769                                                 queues, priorities);
770                 TEST_ASSERT(ret == 2, "(%d)Wrong link get ret=%d expected=%d",
771                                                 TEST_DEV_ID, ret, 2);
772                 TEST_ASSERT(queues[0] == 2, "ret=%d expected=%d", ret, 2);
773                 TEST_ASSERT(priorities[0] == 0x40, "ret=%d expected=%d",
774                                                         ret, 0x40);
775                 TEST_ASSERT(queues[1] == 3, "ret=%d expected=%d", ret, 3);
776                 TEST_ASSERT(priorities[1] == 0x40, "ret=%d expected=%d",
777                                         ret, 0x40);
778         }
779
780         return TEST_SUCCESS;
781 }
782
783 static int
784 test_eventdev_close(void)
785 {
786         rte_event_dev_stop(TEST_DEV_ID);
787         return rte_event_dev_close(TEST_DEV_ID);
788 }
789
790 static struct unit_test_suite eventdev_common_testsuite  = {
791         .suite_name = "eventdev common code unit test suite",
792         .setup = testsuite_setup,
793         .teardown = testsuite_teardown,
794         .unit_test_cases = {
795                 TEST_CASE_ST(NULL, NULL,
796                         test_eventdev_count),
797                 TEST_CASE_ST(NULL, NULL,
798                         test_eventdev_get_dev_id),
799                 TEST_CASE_ST(NULL, NULL,
800                         test_eventdev_socket_id),
801                 TEST_CASE_ST(NULL, NULL,
802                         test_eventdev_info_get),
803                 TEST_CASE_ST(NULL, NULL,
804                         test_eventdev_configure),
805                 TEST_CASE_ST(eventdev_configure_setup, NULL,
806                         test_eventdev_queue_default_conf_get),
807                 TEST_CASE_ST(eventdev_configure_setup, NULL,
808                         test_eventdev_queue_setup),
809                 TEST_CASE_ST(eventdev_configure_setup, NULL,
810                         test_eventdev_queue_count),
811                 TEST_CASE_ST(eventdev_configure_setup, NULL,
812                         test_eventdev_queue_priority),
813                 TEST_CASE_ST(eventdev_configure_setup, NULL,
814                         test_eventdev_port_default_conf_get),
815                 TEST_CASE_ST(eventdev_configure_setup, NULL,
816                         test_eventdev_port_setup),
817                 TEST_CASE_ST(eventdev_configure_setup, NULL,
818                         test_eventdev_dequeue_depth),
819                 TEST_CASE_ST(eventdev_configure_setup, NULL,
820                         test_eventdev_enqueue_depth),
821                 TEST_CASE_ST(eventdev_configure_setup, NULL,
822                         test_eventdev_port_count),
823                 TEST_CASE_ST(eventdev_configure_setup, NULL,
824                         test_eventdev_timeout_ticks),
825                 TEST_CASE_ST(NULL, NULL,
826                         test_eventdev_start_stop),
827                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
828                         test_eventdev_link),
829                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
830                         test_eventdev_unlink),
831                 TEST_CASE_ST(eventdev_setup_device, eventdev_stop_device,
832                         test_eventdev_link_get),
833                 TEST_CASE_ST(eventdev_setup_device, NULL,
834                         test_eventdev_close),
835                 TEST_CASES_END() /**< NULL terminate unit test array */
836         }
837 };
838
839 static int
840 test_eventdev_common(void)
841 {
842         return unit_test_suite_runner(&eventdev_common_testsuite);
843 }
844
845 REGISTER_TEST_COMMAND(eventdev_common_autotest, test_eventdev_common);