Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/list_sort: test: use generic random32

Instead of using own pseudo-random generator, use generic linux
'random32()' function. Presumably, this should improve test coverage.

At the same time, do the following changes:
o Use shorter macro name for test list length
o Do not use strange 'l_h' name for 'struct list_head' element,
use 'list', because it is traditional name and thus, makes the
code more obvious and readable.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: Don Mullis <don.mullis@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Artem Bityutskiy and committed by
Linus Torvalds
eeee9ebb bb2ab10f

+15 -12
+15 -12
lib/list_sort.c
··· 142 142 EXPORT_SYMBOL(list_sort); 143 143 144 144 #ifdef CONFIG_TEST_LIST_SORT 145 + 146 + #include <linux/random.h> 147 + 145 148 struct debug_el { 146 - struct list_head l_h; 149 + struct list_head list; 147 150 int value; 148 151 unsigned serial; 149 152 }; 150 153 151 154 static int cmp(void *priv, struct list_head *a, struct list_head *b) 152 155 { 153 - return container_of(a, struct debug_el, l_h)->value 154 - - container_of(b, struct debug_el, l_h)->value; 156 + return container_of(a, struct debug_el, list)->value 157 + - container_of(b, struct debug_el, list)->value; 155 158 } 156 159 157 160 /* 158 161 * The pattern of set bits in the list length determines which cases 159 162 * are hit in list_sort(). 160 163 */ 161 - #define LIST_SORT_TEST_LENGTH (512+128+2) /* not including head */ 164 + #define TEST_LIST_LEN (512+128+2) /* not including head */ 162 165 163 166 static int __init list_sort_test(void) 164 167 { 165 - int i, r = 1, count; 168 + int i, count; 166 169 struct list_head *head = kmalloc(sizeof(*head), GFP_KERNEL); 167 170 struct list_head *cur; 168 171 169 172 printk(KERN_DEBUG "testing list_sort()\n"); 170 173 171 174 cur = head; 172 - for (i = 0; i < LIST_SORT_TEST_LENGTH; i++) { 175 + for (i = 0; i < TEST_LIST_LEN; i++) { 173 176 struct debug_el *el = kmalloc(sizeof(*el), GFP_KERNEL); 174 177 BUG_ON(!el); 175 178 /* force some equivalencies */ 176 - el->value = (r = (r * 725861) % 6599) % (LIST_SORT_TEST_LENGTH/3); 179 + el->value = random32() % (TEST_LIST_LEN/3); 177 180 el->serial = i; 178 181 179 - el->l_h.prev = cur; 180 - cur->next = &el->l_h; 182 + el->list.prev = cur; 183 + cur->next = &el->list; 181 184 cur = cur->next; 182 185 } 183 186 head->prev = cur; ··· 189 186 190 187 count = 1; 191 188 for (cur = head->next; cur->next != head; cur = cur->next) { 192 - struct debug_el *el = container_of(cur, struct debug_el, l_h); 189 + struct debug_el *el = container_of(cur, struct debug_el, list); 193 190 int cmp_result = cmp(NULL, cur, cur->next); 194 191 if (cur->next->prev != cur) { 195 192 printk(KERN_ERR "list_sort() returned " ··· 200 197 return 1; 201 198 } else if (cmp_result == 0 && 202 199 el->serial >= container_of(cur->next, 203 - struct debug_el, l_h)->serial) { 200 + struct debug_el, list)->serial) { 204 201 printk(KERN_ERR "list_sort() failed to preserve order " 205 202 "of equivalent elements!\n"); 206 203 return 1; ··· 209 206 count++; 210 207 } 211 208 kfree(cur); 212 - if (count != LIST_SORT_TEST_LENGTH) { 209 + if (count != TEST_LIST_LEN) { 213 210 printk(KERN_ERR "list_sort() returned list of " 214 211 "different length!\n"); 215 212 return 1;