diff options
author | Lai Jiangshan <laijs@cn.fujitsu.com> | 2010-12-21 04:55:18 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-03-11 15:14:48 -0500 |
commit | 6d55da53db3d9b911f69f2ce1e5fb8943eafe057 (patch) | |
tree | f812fcb0cedfddb562fdc4cb25d3394e5325ccbf /lib | |
parent | bf6a9b8336ba12672755c2ae898b0abe42c7a5ac (diff) |
plist: Add priority list test
Add test code for checking plist when the kernel is booting.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
LKML-Reference: <4D107986.1010302@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/plist.c | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/lib/plist.c b/lib/plist.c index 8c614d0e6c35..0ae7e6431726 100644 --- a/lib/plist.c +++ b/lib/plist.c | |||
@@ -28,6 +28,8 @@ | |||
28 | 28 | ||
29 | #ifdef CONFIG_DEBUG_PI_LIST | 29 | #ifdef CONFIG_DEBUG_PI_LIST |
30 | 30 | ||
31 | static struct plist_head test_head; | ||
32 | |||
31 | static void plist_check_prev_next(struct list_head *t, struct list_head *p, | 33 | static void plist_check_prev_next(struct list_head *t, struct list_head *p, |
32 | struct list_head *n) | 34 | struct list_head *n) |
33 | { | 35 | { |
@@ -54,7 +56,7 @@ static void plist_check_list(struct list_head *top) | |||
54 | 56 | ||
55 | static void plist_check_head(struct plist_head *head) | 57 | static void plist_check_head(struct plist_head *head) |
56 | { | 58 | { |
57 | WARN_ON(!head->rawlock && !head->spinlock); | 59 | WARN_ON(head != &test_head && !head->rawlock && !head->spinlock); |
58 | if (head->rawlock) | 60 | if (head->rawlock) |
59 | WARN_ON_SMP(!raw_spin_is_locked(head->rawlock)); | 61 | WARN_ON_SMP(!raw_spin_is_locked(head->rawlock)); |
60 | if (head->spinlock) | 62 | if (head->spinlock) |
@@ -135,3 +137,80 @@ void plist_del(struct plist_node *node, struct plist_head *head) | |||
135 | 137 | ||
136 | plist_check_head(head); | 138 | plist_check_head(head); |
137 | } | 139 | } |
140 | |||
141 | #ifdef CONFIG_DEBUG_PI_LIST | ||
142 | #include <linux/sched.h> | ||
143 | #include <linux/module.h> | ||
144 | #include <linux/init.h> | ||
145 | |||
146 | static struct plist_node __initdata test_node[241]; | ||
147 | |||
148 | static void __init plist_test_check(int nr_expect) | ||
149 | { | ||
150 | struct plist_node *first, *prio_pos, *node_pos; | ||
151 | |||
152 | if (plist_head_empty(&test_head)) { | ||
153 | BUG_ON(nr_expect != 0); | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | prio_pos = first = plist_first(&test_head); | ||
158 | plist_for_each(node_pos, &test_head) { | ||
159 | if (nr_expect-- < 0) | ||
160 | break; | ||
161 | if (node_pos == first) | ||
162 | continue; | ||
163 | if (node_pos->prio == prio_pos->prio) { | ||
164 | BUG_ON(!list_empty(&node_pos->prio_list)); | ||
165 | continue; | ||
166 | } | ||
167 | |||
168 | BUG_ON(prio_pos->prio > node_pos->prio); | ||
169 | BUG_ON(prio_pos->prio_list.next != &node_pos->prio_list); | ||
170 | prio_pos = node_pos; | ||
171 | } | ||
172 | |||
173 | BUG_ON(nr_expect != 0); | ||
174 | BUG_ON(prio_pos->prio_list.next != &first->prio_list); | ||
175 | } | ||
176 | |||
177 | static int __init plist_test(void) | ||
178 | { | ||
179 | int nr_expect = 0, i, loop; | ||
180 | unsigned int r = local_clock(); | ||
181 | |||
182 | printk(KERN_INFO "start plist test\n"); | ||
183 | plist_head_init(&test_head, NULL); | ||
184 | for (i = 0; i < ARRAY_SIZE(test_node); i++) | ||
185 | plist_node_init(test_node + i, 0); | ||
186 | |||
187 | for (loop = 0; loop < 1000; loop++) { | ||
188 | r = r * 193939 % 47629; | ||
189 | i = r % ARRAY_SIZE(test_node); | ||
190 | if (plist_node_empty(test_node + i)) { | ||
191 | r = r * 193939 % 47629; | ||
192 | test_node[i].prio = r % 99; | ||
193 | plist_add(test_node + i, &test_head); | ||
194 | nr_expect++; | ||
195 | } else { | ||
196 | plist_del(test_node + i, &test_head); | ||
197 | nr_expect--; | ||
198 | } | ||
199 | plist_test_check(nr_expect); | ||
200 | } | ||
201 | |||
202 | for (i = 0; i < ARRAY_SIZE(test_node); i++) { | ||
203 | if (plist_node_empty(test_node + i)) | ||
204 | continue; | ||
205 | plist_del(test_node + i, &test_head); | ||
206 | nr_expect--; | ||
207 | plist_test_check(nr_expect); | ||
208 | } | ||
209 | |||
210 | printk(KERN_INFO "end plist test\n"); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | module_init(plist_test); | ||
215 | |||
216 | #endif | ||