7e2fb2cf27c6e175fd15b6efbdb5640647ac9bb2
[dpdk.git] / app / test / test_rawdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 NXP
3  */
4 #include <rte_common.h>
5 #include <rte_mbuf.h>
6 #include <rte_malloc.h>
7 #include <rte_memcpy.h>
8 #include <rte_dev.h>
9 #include <rte_rawdev.h>
10 #include <rte_bus_vdev.h>
11
12 #include "test.h"
13
14 static int
15 test_rawdev_selftest_impl(const char *pmd, const char *opts)
16 {
17         int ret;
18
19         printf("\n### Test rawdev infrastructure using skeleton driver\n");
20         rte_vdev_init(pmd, opts);
21         ret = rte_rawdev_selftest(rte_rawdev_get_dev_id(pmd));
22         rte_vdev_uninit(pmd);
23         return ret;
24 }
25
26 static int
27 test_rawdev_selftest_skeleton(void)
28 {
29         return test_rawdev_selftest_impl("rawdev_skeleton", "");
30 }
31
32 static int
33 test_rawdev_selftests(void)
34 {
35         const int count = rte_rawdev_count();
36         int ret = 0;
37         int i;
38
39         /* basic sanity on rawdev infrastructure */
40         if (test_rawdev_selftest_skeleton() < 0)
41                 return -1;
42
43         /* now run self-test on all rawdevs */
44         if (count > 0)
45                 printf("\n### Run selftest on each available rawdev\n");
46         for (i = 0; i < count; i++) {
47                 int result = rte_rawdev_selftest(i);
48                 printf("Rawdev %u (%s) selftest: %s\n", i,
49                                 rte_rawdevs[i].name,
50                                 result == 0 ? "Passed" : "Failed");
51                 ret |=  result;
52         }
53
54         return ret;
55 }
56
57 REGISTER_TEST_COMMAND(rawdev_autotest, test_rawdev_selftests);
58
59 static int
60 test_rawdev_selftest_ioat(void)
61 {
62         const int count = rte_rawdev_count();
63         int i;
64
65         for (i = 0; i < count; i++) {
66                 struct rte_rawdev_info info = { .dev_private = NULL };
67                 if (rte_rawdev_info_get(i, &info, 0) == 0 &&
68                                 strstr(info.driver_name, "ioat") != NULL)
69                         return rte_rawdev_selftest(i) == 0 ?
70                                         TEST_SUCCESS : TEST_FAILED;
71         }
72
73         printf("No IOAT rawdev found, skipping tests\n");
74         return TEST_SKIPPED;
75 }
76
77 REGISTER_TEST_COMMAND(ioat_rawdev_autotest, test_rawdev_selftest_ioat);