4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/queue.h>
42 #include <rte_eal_memconfig.h>
43 #include <rte_string_fns.h>
47 #define do_return(...) do { \
48 printf("Error at %s, line %d: ", __func__, __LINE__); \
49 printf(__VA_ARGS__); \
53 static struct rte_tailq_elem rte_dummy_tailq = {
56 EAL_REGISTER_TAILQ(rte_dummy_tailq)
58 static struct rte_tailq_elem rte_dummy_dyn_tailq = {
61 static struct rte_tailq_elem rte_dummy_dyn2_tailq = {
65 static struct rte_tailq_entry d_elem;
66 static struct rte_tailq_entry d_dyn_elem;
69 test_tailq_early(void)
71 struct rte_tailq_entry_head *d_head;
73 d_head = RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head);
75 do_return("Error %s has not been initialised\n",
76 rte_dummy_tailq.name);
78 /* check we can add an item to it */
79 TAILQ_INSERT_TAIL(d_head, &d_elem, next);
85 test_tailq_create(void)
87 struct rte_tailq_entry_head *d_head;
89 /* create a tailq and check its non-null (since we are post-eal init) */
90 if ((rte_eal_tailq_register(&rte_dummy_dyn_tailq) < 0) ||
91 (rte_dummy_dyn_tailq.head == NULL))
92 do_return("Error allocating %s\n", rte_dummy_dyn_tailq.name);
94 d_head = RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head);
96 /* check we can add an item to it */
97 TAILQ_INSERT_TAIL(d_head, &d_dyn_elem, next);
99 if (strcmp(rte_dummy_dyn2_tailq.name, rte_dummy_dyn_tailq.name))
100 do_return("Error, something is wrong in the tailq test\n");
102 /* try allocating again, and check for failure */
103 if (!rte_eal_tailq_register(&rte_dummy_dyn2_tailq))
104 do_return("Error, registering the same tailq %s did not fail\n",
105 rte_dummy_dyn2_tailq.name);
111 test_tailq_lookup(void)
113 /* run successful test - check result is found */
114 struct rte_tailq_entry_head *d_head;
115 struct rte_tailq_entry *d_ptr;
117 d_head = RTE_TAILQ_LOOKUP(rte_dummy_tailq.name, rte_tailq_entry_head);
118 /* rte_dummy_tailq has been registered by EAL_REGISTER_TAILQ */
119 if (d_head == NULL ||
120 d_head != RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head))
121 do_return("Error with tailq lookup\n");
123 TAILQ_FOREACH(d_ptr, d_head, next)
124 if (d_ptr != &d_elem)
125 do_return("Error with tailq returned from lookup - "
126 "expected element not found\n");
128 d_head = RTE_TAILQ_LOOKUP(rte_dummy_dyn_tailq.name, rte_tailq_entry_head);
129 /* rte_dummy_dyn_tailq has been registered by test_tailq_create */
130 if (d_head == NULL ||
131 d_head != RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head))
132 do_return("Error with tailq lookup\n");
134 TAILQ_FOREACH(d_ptr, d_head, next)
135 if (d_ptr != &d_dyn_elem)
136 do_return("Error with tailq returned from lookup - "
137 "expected element not found\n");
139 /* now try a bad/error lookup */
140 d_head = RTE_TAILQ_LOOKUP("coucou", rte_tailq_entry_head);
142 do_return("Error, lookup does not return NULL for bad tailq name\n");
151 ret |= test_tailq_early();
152 ret |= test_tailq_create();
153 ret |= test_tailq_lookup();
157 static struct test_command tailq_cmd = {
158 .command = "tailq_autotest",
159 .callback = test_tailq,
161 REGISTER_TEST_COMMAND(tailq_cmd);