1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <sys/queue.h>
13 #include <rte_eal_memconfig.h>
14 #include <rte_string_fns.h>
15 #include <rte_tailq.h>
19 #define do_return(...) do { \
20 printf("Error at %s, line %d: ", __func__, __LINE__); \
21 printf(__VA_ARGS__); \
25 static struct rte_tailq_elem rte_dummy_tailq = {
28 EAL_REGISTER_TAILQ(rte_dummy_tailq)
30 static struct rte_tailq_elem rte_dummy_dyn_tailq = {
33 static struct rte_tailq_elem rte_dummy_dyn2_tailq = {
37 static struct rte_tailq_entry d_elem;
38 static struct rte_tailq_entry d_dyn_elem;
41 test_tailq_early(void)
43 struct rte_tailq_entry_head *d_head;
45 d_head = RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head);
47 do_return("Error %s has not been initialised\n",
48 rte_dummy_tailq.name);
50 /* check we can add an item to it */
51 TAILQ_INSERT_TAIL(d_head, &d_elem, next);
57 test_tailq_create(void)
59 struct rte_tailq_entry_head *d_head;
61 /* create a tailq and check its non-null (since we are post-eal init) */
62 if ((rte_eal_tailq_register(&rte_dummy_dyn_tailq) < 0) ||
63 (rte_dummy_dyn_tailq.head == NULL))
64 do_return("Error allocating %s\n", rte_dummy_dyn_tailq.name);
66 d_head = RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head);
68 /* check we can add an item to it */
69 TAILQ_INSERT_TAIL(d_head, &d_dyn_elem, next);
71 if (strcmp(rte_dummy_dyn2_tailq.name, rte_dummy_dyn_tailq.name))
72 do_return("Error, something is wrong in the tailq test\n");
74 /* try allocating again, and check for failure */
75 if (!rte_eal_tailq_register(&rte_dummy_dyn2_tailq))
76 do_return("Error, registering the same tailq %s did not fail\n",
77 rte_dummy_dyn2_tailq.name);
83 test_tailq_lookup(void)
85 /* run successful test - check result is found */
86 struct rte_tailq_entry_head *d_head;
87 struct rte_tailq_entry *d_ptr;
89 d_head = RTE_TAILQ_LOOKUP(rte_dummy_tailq.name, rte_tailq_entry_head);
90 /* rte_dummy_tailq has been registered by EAL_REGISTER_TAILQ */
92 d_head != RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head))
93 do_return("Error with tailq lookup\n");
95 TAILQ_FOREACH(d_ptr, d_head, next)
97 do_return("Error with tailq returned from lookup - "
98 "expected element not found\n");
100 d_head = RTE_TAILQ_LOOKUP(rte_dummy_dyn_tailq.name, rte_tailq_entry_head);
101 /* rte_dummy_dyn_tailq has been registered by test_tailq_create */
102 if (d_head == NULL ||
103 d_head != RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head))
104 do_return("Error with tailq lookup\n");
106 TAILQ_FOREACH(d_ptr, d_head, next)
107 if (d_ptr != &d_dyn_elem)
108 do_return("Error with tailq returned from lookup - "
109 "expected element not found\n");
111 /* now try a bad/error lookup */
112 d_head = RTE_TAILQ_LOOKUP("coucou", rte_tailq_entry_head);
114 do_return("Error, lookup does not return NULL for bad tailq name\n");
123 ret |= test_tailq_early();
124 ret |= test_tailq_create();
125 ret |= test_tailq_lookup();
129 REGISTER_TEST_COMMAND(tailq_autotest, test_tailq);