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>
18 #define do_return(...) do { \
19 printf("Error at %s, line %d: ", __func__, __LINE__); \
20 printf(__VA_ARGS__); \
24 static struct rte_tailq_elem rte_dummy_tailq = {
27 EAL_REGISTER_TAILQ(rte_dummy_tailq)
29 static struct rte_tailq_elem rte_dummy_dyn_tailq = {
32 static struct rte_tailq_elem rte_dummy_dyn2_tailq = {
36 static struct rte_tailq_entry d_elem;
37 static struct rte_tailq_entry d_dyn_elem;
40 test_tailq_early(void)
42 struct rte_tailq_entry_head *d_head;
44 d_head = RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head);
46 do_return("Error %s has not been initialised\n",
47 rte_dummy_tailq.name);
49 /* check we can add an item to it */
50 TAILQ_INSERT_TAIL(d_head, &d_elem, next);
56 test_tailq_create(void)
58 struct rte_tailq_entry_head *d_head;
60 /* create a tailq and check its non-null (since we are post-eal init) */
61 if ((rte_eal_tailq_register(&rte_dummy_dyn_tailq) < 0) ||
62 (rte_dummy_dyn_tailq.head == NULL))
63 do_return("Error allocating %s\n", rte_dummy_dyn_tailq.name);
65 d_head = RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head);
67 /* check we can add an item to it */
68 TAILQ_INSERT_TAIL(d_head, &d_dyn_elem, next);
70 if (strcmp(rte_dummy_dyn2_tailq.name, rte_dummy_dyn_tailq.name))
71 do_return("Error, something is wrong in the tailq test\n");
73 /* try allocating again, and check for failure */
74 if (!rte_eal_tailq_register(&rte_dummy_dyn2_tailq))
75 do_return("Error, registering the same tailq %s did not fail\n",
76 rte_dummy_dyn2_tailq.name);
82 test_tailq_lookup(void)
84 /* run successful test - check result is found */
85 struct rte_tailq_entry_head *d_head;
86 struct rte_tailq_entry *d_ptr;
88 d_head = RTE_TAILQ_LOOKUP(rte_dummy_tailq.name, rte_tailq_entry_head);
89 /* rte_dummy_tailq has been registered by EAL_REGISTER_TAILQ */
91 d_head != RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head))
92 do_return("Error with tailq lookup\n");
94 TAILQ_FOREACH(d_ptr, d_head, next)
96 do_return("Error with tailq returned from lookup - "
97 "expected element not found\n");
99 d_head = RTE_TAILQ_LOOKUP(rte_dummy_dyn_tailq.name, rte_tailq_entry_head);
100 /* rte_dummy_dyn_tailq has been registered by test_tailq_create */
101 if (d_head == NULL ||
102 d_head != RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head))
103 do_return("Error with tailq lookup\n");
105 TAILQ_FOREACH(d_ptr, d_head, next)
106 if (d_ptr != &d_dyn_elem)
107 do_return("Error with tailq returned from lookup - "
108 "expected element not found\n");
110 /* now try a bad/error lookup */
111 d_head = RTE_TAILQ_LOOKUP("coucou", rte_tailq_entry_head);
113 do_return("Error, lookup does not return NULL for bad tailq name\n");
122 ret |= test_tailq_early();
123 ret |= test_tailq_create();
124 ret |= test_tailq_lookup();
128 REGISTER_TEST_COMMAND(tailq_autotest, test_tailq);