Lines Matching full:list
3 * KUnit test for the Kernel Linked-list structures.
10 #include <linux/list.h>
14 struct list_head list; member
19 /* Test the different ways of initialising a list. */ in list_test_list_init()
49 LIST_HEAD(list); in list_test_list_add()
51 list_add(&a, &list); in list_test_list_add()
52 list_add(&b, &list); in list_test_list_add()
54 /* should be [list] -> b -> a */ in list_test_list_add()
55 KUNIT_EXPECT_PTR_EQ(test, list.next, &b); in list_test_list_add()
56 KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); in list_test_list_add()
63 LIST_HEAD(list); in list_test_list_add_tail()
65 list_add_tail(&a, &list); in list_test_list_add_tail()
66 list_add_tail(&b, &list); in list_test_list_add_tail()
68 /* should be [list] -> a -> b */ in list_test_list_add_tail()
69 KUNIT_EXPECT_PTR_EQ(test, list.next, &a); in list_test_list_add_tail()
70 KUNIT_EXPECT_PTR_EQ(test, a.prev, &list); in list_test_list_add_tail()
77 LIST_HEAD(list); in list_test_list_del()
79 list_add_tail(&a, &list); in list_test_list_del()
80 list_add_tail(&b, &list); in list_test_list_del()
82 /* before: [list] -> a -> b */ in list_test_list_del()
85 /* now: [list] -> b */ in list_test_list_del()
86 KUNIT_EXPECT_PTR_EQ(test, list.next, &b); in list_test_list_del()
87 KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); in list_test_list_del()
93 LIST_HEAD(list); in list_test_list_replace()
95 list_add_tail(&a_old, &list); in list_test_list_replace()
96 list_add_tail(&b, &list); in list_test_list_replace()
98 /* before: [list] -> a_old -> b */ in list_test_list_replace()
101 /* now: [list] -> a_new -> b */ in list_test_list_replace()
102 KUNIT_EXPECT_PTR_EQ(test, list.next, &a_new); in list_test_list_replace()
109 LIST_HEAD(list); in list_test_list_replace_init()
111 list_add_tail(&a_old, &list); in list_test_list_replace_init()
112 list_add_tail(&b, &list); in list_test_list_replace_init()
114 /* before: [list] -> a_old -> b */ in list_test_list_replace_init()
117 /* now: [list] -> a_new -> b */ in list_test_list_replace_init()
118 KUNIT_EXPECT_PTR_EQ(test, list.next, &a_new); in list_test_list_replace_init()
128 LIST_HEAD(list); in list_test_list_swap()
130 list_add_tail(&a, &list); in list_test_list_swap()
131 list_add_tail(&b, &list); in list_test_list_swap()
133 /* before: [list] -> a -> b */ in list_test_list_swap()
136 /* after: [list] -> b -> a */ in list_test_list_swap()
137 KUNIT_EXPECT_PTR_EQ(test, &b, list.next); in list_test_list_swap()
138 KUNIT_EXPECT_PTR_EQ(test, &a, list.prev); in list_test_list_swap()
141 KUNIT_EXPECT_PTR_EQ(test, &list, b.prev); in list_test_list_swap()
143 KUNIT_EXPECT_PTR_EQ(test, &list, a.next); in list_test_list_swap()
150 LIST_HEAD(list); in list_test_list_del_init()
152 list_add_tail(&a, &list); in list_test_list_del_init()
153 list_add_tail(&b, &list); in list_test_list_del_init()
155 /* before: [list] -> a -> b */ in list_test_list_del_init()
157 /* after: [list] -> b, a initialised */ in list_test_list_del_init()
159 KUNIT_EXPECT_PTR_EQ(test, list.next, &b); in list_test_list_del_init()
160 KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); in list_test_list_del_init()
170 LIST_HEAD(list); in list_test_list_del_init_careful()
172 list_add_tail(&a, &list); in list_test_list_del_init_careful()
173 list_add_tail(&b, &list); in list_test_list_del_init_careful()
175 /* before: [list] -> a -> b */ in list_test_list_del_init_careful()
177 /* after: [list] -> b, a initialised */ in list_test_list_del_init_careful()
179 KUNIT_EXPECT_PTR_EQ(test, list.next, &b); in list_test_list_del_init_careful()
180 KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); in list_test_list_del_init_careful()
267 "Head element of same list"); in list_test_list_is_head()
269 "Non-head element of same list"); in list_test_list_is_head()
271 "Head element of different list"); in list_test_list_is_head()
278 LIST_HEAD(list); in list_test_list_is_first()
280 list_add_tail(&a, &list); in list_test_list_is_first()
281 list_add_tail(&b, &list); in list_test_list_is_first()
283 KUNIT_EXPECT_TRUE(test, list_is_first(&a, &list)); in list_test_list_is_first()
284 KUNIT_EXPECT_FALSE(test, list_is_first(&b, &list)); in list_test_list_is_first()
290 LIST_HEAD(list); in list_test_list_is_last()
292 list_add_tail(&a, &list); in list_test_list_is_last()
293 list_add_tail(&b, &list); in list_test_list_is_last()
295 KUNIT_EXPECT_FALSE(test, list_is_last(&a, &list)); in list_test_list_is_last()
296 KUNIT_EXPECT_TRUE(test, list_is_last(&b, &list)); in list_test_list_is_last()
327 LIST_HEAD(list); in list_test_list_rotate_left()
329 list_add_tail(&a, &list); in list_test_list_rotate_left()
330 list_add_tail(&b, &list); in list_test_list_rotate_left()
332 /* before: [list] -> a -> b */ in list_test_list_rotate_left()
333 list_rotate_left(&list); in list_test_list_rotate_left()
334 /* after: [list] -> b -> a */ in list_test_list_rotate_left()
336 KUNIT_EXPECT_PTR_EQ(test, list.next, &b); in list_test_list_rotate_left()
337 KUNIT_EXPECT_PTR_EQ(test, b.prev, &list); in list_test_list_rotate_left()
346 LIST_HEAD(list); in list_test_list_rotate_to_front()
349 list_add_tail(&a, &list); in list_test_list_rotate_to_front()
350 list_add_tail(&b, &list); in list_test_list_rotate_to_front()
351 list_add_tail(&c, &list); in list_test_list_rotate_to_front()
352 list_add_tail(&d, &list); in list_test_list_rotate_to_front()
354 /* before: [list] -> a -> b -> c -> d */ in list_test_list_rotate_to_front()
355 list_rotate_to_front(&c, &list); in list_test_list_rotate_to_front()
356 /* after: [list] -> c -> d -> a -> b */ in list_test_list_rotate_to_front()
358 list_for_each(ptr, &list) { in list_test_list_rotate_to_front()
368 LIST_HEAD(list); in list_test_list_is_singular()
370 /* [list] empty */ in list_test_list_is_singular()
371 KUNIT_EXPECT_FALSE(test, list_is_singular(&list)); in list_test_list_is_singular()
373 list_add_tail(&a, &list); in list_test_list_is_singular()
375 /* [list] -> a */ in list_test_list_is_singular()
376 KUNIT_EXPECT_TRUE(test, list_is_singular(&list)); in list_test_list_is_singular()
378 list_add_tail(&b, &list); in list_test_list_is_singular()
380 /* [list] -> a -> b */ in list_test_list_is_singular()
381 KUNIT_EXPECT_FALSE(test, list_is_singular(&list)); in list_test_list_is_singular()
548 KUNIT_EXPECT_PTR_EQ(test, &test_struct, list_entry(&(test_struct.list), in list_test_list_entry()
549 struct list_test_struct, list)); in list_test_list_entry()
556 INIT_LIST_HEAD(&test_struct1.list); in list_test_list_entry_is_head()
557 INIT_LIST_HEAD(&test_struct3.list); in list_test_list_entry_is_head()
559 list_add_tail(&test_struct2.list, &test_struct1.list); in list_test_list_entry_is_head()
562 list_entry_is_head((&test_struct1), &test_struct1.list, list), in list_test_list_entry_is_head()
563 "Head element of same list"); in list_test_list_entry_is_head()
565 list_entry_is_head((&test_struct2), &test_struct1.list, list), in list_test_list_entry_is_head()
566 "Non-head element of same list"); in list_test_list_entry_is_head()
568 list_entry_is_head((&test_struct3), &test_struct1.list, list), in list_test_list_entry_is_head()
569 "Head element of different list"); in list_test_list_entry_is_head()
575 LIST_HEAD(list); in list_test_list_first_entry()
577 list_add_tail(&test_struct1.list, &list); in list_test_list_first_entry()
578 list_add_tail(&test_struct2.list, &list); in list_test_list_first_entry()
581 KUNIT_EXPECT_PTR_EQ(test, &test_struct1, list_first_entry(&list, in list_test_list_first_entry()
582 struct list_test_struct, list)); in list_test_list_first_entry()
588 LIST_HEAD(list); in list_test_list_last_entry()
590 list_add_tail(&test_struct1.list, &list); in list_test_list_last_entry()
591 list_add_tail(&test_struct2.list, &list); in list_test_list_last_entry()
594 KUNIT_EXPECT_PTR_EQ(test, &test_struct2, list_last_entry(&list, in list_test_list_last_entry()
595 struct list_test_struct, list)); in list_test_list_last_entry()
601 LIST_HEAD(list); in list_test_list_first_entry_or_null()
603 KUNIT_EXPECT_FALSE(test, list_first_entry_or_null(&list, in list_test_list_first_entry_or_null()
604 struct list_test_struct, list)); in list_test_list_first_entry_or_null()
606 list_add_tail(&test_struct1.list, &list); in list_test_list_first_entry_or_null()
607 list_add_tail(&test_struct2.list, &list); in list_test_list_first_entry_or_null()
610 list_first_entry_or_null(&list, in list_test_list_first_entry_or_null()
611 struct list_test_struct, list)); in list_test_list_first_entry_or_null()
617 LIST_HEAD(list); in list_test_list_next_entry()
619 list_add_tail(&test_struct1.list, &list); in list_test_list_next_entry()
620 list_add_tail(&test_struct2.list, &list); in list_test_list_next_entry()
624 list)); in list_test_list_next_entry()
630 LIST_HEAD(list); in list_test_list_prev_entry()
632 list_add_tail(&test_struct1.list, &list); in list_test_list_prev_entry()
633 list_add_tail(&test_struct2.list, &list); in list_test_list_prev_entry()
637 list)); in list_test_list_prev_entry()
643 LIST_HEAD(list); in list_test_list_for_each()
646 list_add_tail(&entries[0], &list); in list_test_list_for_each()
647 list_add_tail(&entries[1], &list); in list_test_list_for_each()
648 list_add_tail(&entries[2], &list); in list_test_list_for_each()
650 list_for_each(cur, &list) { in list_test_list_for_each()
661 LIST_HEAD(list); in list_test_list_for_each_prev()
664 list_add_tail(&entries[0], &list); in list_test_list_for_each_prev()
665 list_add_tail(&entries[1], &list); in list_test_list_for_each_prev()
666 list_add_tail(&entries[2], &list); in list_test_list_for_each_prev()
668 list_for_each_prev(cur, &list) { in list_test_list_for_each_prev()
679 LIST_HEAD(list); in list_test_list_for_each_safe()
683 list_add_tail(&entries[0], &list); in list_test_list_for_each_safe()
684 list_add_tail(&entries[1], &list); in list_test_list_for_each_safe()
685 list_add_tail(&entries[2], &list); in list_test_list_for_each_safe()
687 list_for_each_safe(cur, n, &list) { in list_test_list_for_each_safe()
694 KUNIT_EXPECT_TRUE(test, list_empty(&list)); in list_test_list_for_each_safe()
700 LIST_HEAD(list); in list_test_list_for_each_prev_safe()
703 list_add_tail(&entries[0], &list); in list_test_list_for_each_prev_safe()
704 list_add_tail(&entries[1], &list); in list_test_list_for_each_prev_safe()
705 list_add_tail(&entries[2], &list); in list_test_list_for_each_prev_safe()
707 list_for_each_prev_safe(cur, n, &list) { in list_test_list_for_each_prev_safe()
714 KUNIT_EXPECT_TRUE(test, list_empty(&list)); in list_test_list_for_each_prev_safe()
720 LIST_HEAD(list); in list_test_list_for_each_entry()
725 list_add_tail(&entries[i].list, &list); in list_test_list_for_each_entry()
730 list_for_each_entry(cur, &list, list) { in list_test_list_for_each_entry()
741 LIST_HEAD(list); in list_test_list_for_each_entry_reverse()
746 list_add_tail(&entries[i].list, &list); in list_test_list_for_each_entry_reverse()
751 list_for_each_entry_reverse(cur, &list, list) { in list_test_list_for_each_entry_reverse()
803 .name = "list-kunit-test",
809 struct hlist_node list; member
814 /* Test the different ways of initialising a list. */ in hlist_test_init()
843 HLIST_HEAD(list); in hlist_test_unhashed()
850 hlist_add_head(&a, &list); in hlist_test_unhashed()
852 /* is hashed once added to list */ in hlist_test_unhashed()
865 HLIST_HEAD(list); in hlist_test_unhashed_lockless()
872 hlist_add_head(&a, &list); in hlist_test_unhashed_lockless()
874 /* is hashed once added to list */ in hlist_test_unhashed_lockless()
886 HLIST_HEAD(list); in hlist_test_del()
888 hlist_add_head(&a, &list); in hlist_test_del()
891 /* before: [list] -> a -> b */ in hlist_test_del()
894 /* now: [list] -> b */ in hlist_test_del()
895 KUNIT_EXPECT_PTR_EQ(test, list.first, &b); in hlist_test_del()
896 KUNIT_EXPECT_PTR_EQ(test, b.pprev, &list.first); in hlist_test_del()
902 HLIST_HEAD(list); in hlist_test_del_init()
904 hlist_add_head(&a, &list); in hlist_test_del_init()
907 /* before: [list] -> a -> b */ in hlist_test_del_init()
910 /* now: [list] -> b */ in hlist_test_del_init()
911 KUNIT_EXPECT_PTR_EQ(test, list.first, &b); in hlist_test_del_init()
912 KUNIT_EXPECT_PTR_EQ(test, b.pprev, &list.first); in hlist_test_del_init()
923 HLIST_HEAD(list); in hlist_test_add()
925 hlist_add_head(&a, &list); in hlist_test_add()
926 hlist_add_head(&b, &list); in hlist_test_add()
930 /* should be [list] -> b -> c -> a -> d */ in hlist_test_add()
931 KUNIT_EXPECT_PTR_EQ(test, list.first, &b); in hlist_test_add()
962 HLIST_HEAD(list); in hlist_test_is_singular_node()
965 KUNIT_EXPECT_FALSE(test, hlist_is_singular_node(&a, &list)); in hlist_test_is_singular_node()
967 hlist_add_head(&a, &list); in hlist_test_is_singular_node()
968 KUNIT_EXPECT_TRUE(test, hlist_is_singular_node(&a, &list)); in hlist_test_is_singular_node()
970 hlist_add_head(&b, &list); in hlist_test_is_singular_node()
971 KUNIT_EXPECT_FALSE(test, hlist_is_singular_node(&a, &list)); in hlist_test_is_singular_node()
972 KUNIT_EXPECT_FALSE(test, hlist_is_singular_node(&b, &list)); in hlist_test_is_singular_node()
978 HLIST_HEAD(list); in hlist_test_empty()
980 /* list starts off empty */ in hlist_test_empty()
981 KUNIT_EXPECT_TRUE(test, hlist_empty(&list)); in hlist_test_empty()
983 hlist_add_head(&a, &list); in hlist_test_empty()
985 /* list is no longer empty */ in hlist_test_empty()
986 KUNIT_EXPECT_FALSE(test, hlist_empty(&list)); in hlist_test_empty()
1010 hlist_entry(&(test_struct.list), in hlist_test_entry()
1011 struct hlist_test_struct, list)); in hlist_test_entry()
1019 hlist_entry_safe(&(test_struct.list), in hlist_test_entry_safe()
1020 struct hlist_test_struct, list)); in hlist_test_entry_safe()
1024 struct hlist_test_struct, list)); in hlist_test_entry_safe()
1030 HLIST_HEAD(list); in hlist_test_for_each()
1033 hlist_add_head(&entries[0], &list); in hlist_test_for_each()
1037 hlist_for_each(cur, &list) { in hlist_test_for_each()
1049 HLIST_HEAD(list); in hlist_test_for_each_safe()
1052 hlist_add_head(&entries[0], &list); in hlist_test_for_each_safe()
1056 hlist_for_each_safe(cur, n, &list) { in hlist_test_for_each_safe()
1063 KUNIT_EXPECT_TRUE(test, hlist_empty(&list)); in hlist_test_for_each_safe()
1069 HLIST_HEAD(list); in hlist_test_for_each_entry()
1073 hlist_add_head(&entries[0].list, &list); in hlist_test_for_each_entry()
1076 hlist_add_behind(&entries[i].list, &entries[i-1].list); in hlist_test_for_each_entry()
1081 hlist_for_each_entry(cur, &list, list) { in hlist_test_for_each_entry()
1092 HLIST_HEAD(list); in hlist_test_for_each_entry_continue()
1096 hlist_add_head(&entries[0].list, &list); in hlist_test_for_each_entry_continue()
1099 hlist_add_behind(&entries[i].list, &entries[i-1].list); in hlist_test_for_each_entry_continue()
1106 hlist_for_each_entry_continue(cur, list) { in hlist_test_for_each_entry_continue()
1123 HLIST_HEAD(list); in hlist_test_for_each_entry_from()
1127 hlist_add_head(&entries[0].list, &list); in hlist_test_for_each_entry_from()
1130 hlist_add_behind(&entries[i].list, &entries[i-1].list); in hlist_test_for_each_entry_from()
1136 hlist_for_each_entry_from(cur, list) { in hlist_test_for_each_entry_from()
1152 HLIST_HEAD(list); in hlist_test_for_each_entry_safe()
1156 hlist_add_head(&entries[0].list, &list); in hlist_test_for_each_entry_safe()
1159 hlist_add_behind(&entries[i].list, &entries[i-1].list); in hlist_test_for_each_entry_safe()
1164 hlist_for_each_entry_safe(cur, tmp_node, &list, list) { in hlist_test_for_each_entry_safe()
1166 hlist_del(&cur->list); in hlist_test_for_each_entry_safe()
1171 KUNIT_EXPECT_TRUE(test, hlist_empty(&list)); in hlist_test_for_each_entry_safe()