diff options
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r-- | lib/test_xarray.c | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 4676c0a1eeca..c596a957f764 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -199,7 +199,7 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) | |||
199 | XA_BUG_ON(xa, xa_store_index(xa, index + 1, GFP_KERNEL)); | 199 | XA_BUG_ON(xa, xa_store_index(xa, index + 1, GFP_KERNEL)); |
200 | xa_set_mark(xa, index + 1, XA_MARK_0); | 200 | xa_set_mark(xa, index + 1, XA_MARK_0); |
201 | XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL)); | 201 | XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL)); |
202 | xa_set_mark(xa, index + 2, XA_MARK_1); | 202 | xa_set_mark(xa, index + 2, XA_MARK_2); |
203 | XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL)); | 203 | XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL)); |
204 | xa_store_order(xa, index, order, xa_mk_index(index), | 204 | xa_store_order(xa, index, order, xa_mk_index(index), |
205 | GFP_KERNEL); | 205 | GFP_KERNEL); |
@@ -209,8 +209,8 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) | |||
209 | void *entry; | 209 | void *entry; |
210 | 210 | ||
211 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); | 211 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); |
212 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_1)); | 212 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_1)); |
213 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_2)); | 213 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_2)); |
214 | 214 | ||
215 | /* We should see two elements in the array */ | 215 | /* We should see two elements in the array */ |
216 | rcu_read_lock(); | 216 | rcu_read_lock(); |
@@ -357,7 +357,7 @@ static noinline void check_cmpxchg(struct xarray *xa) | |||
357 | static noinline void check_reserve(struct xarray *xa) | 357 | static noinline void check_reserve(struct xarray *xa) |
358 | { | 358 | { |
359 | void *entry; | 359 | void *entry; |
360 | unsigned long index = 0; | 360 | unsigned long index; |
361 | 361 | ||
362 | /* An array with a reserved entry is not empty */ | 362 | /* An array with a reserved entry is not empty */ |
363 | XA_BUG_ON(xa, !xa_empty(xa)); | 363 | XA_BUG_ON(xa, !xa_empty(xa)); |
@@ -382,10 +382,12 @@ static noinline void check_reserve(struct xarray *xa) | |||
382 | xa_erase_index(xa, 12345678); | 382 | xa_erase_index(xa, 12345678); |
383 | XA_BUG_ON(xa, !xa_empty(xa)); | 383 | XA_BUG_ON(xa, !xa_empty(xa)); |
384 | 384 | ||
385 | /* And so does xa_insert */ | 385 | /* But xa_insert does not */ |
386 | xa_reserve(xa, 12345678, GFP_KERNEL); | 386 | xa_reserve(xa, 12345678, GFP_KERNEL); |
387 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != 0); | 387 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != |
388 | xa_erase_index(xa, 12345678); | 388 | -EEXIST); |
389 | XA_BUG_ON(xa, xa_empty(xa)); | ||
390 | XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL); | ||
389 | XA_BUG_ON(xa, !xa_empty(xa)); | 391 | XA_BUG_ON(xa, !xa_empty(xa)); |
390 | 392 | ||
391 | /* Can iterate through a reserved entry */ | 393 | /* Can iterate through a reserved entry */ |
@@ -393,7 +395,7 @@ static noinline void check_reserve(struct xarray *xa) | |||
393 | xa_reserve(xa, 6, GFP_KERNEL); | 395 | xa_reserve(xa, 6, GFP_KERNEL); |
394 | xa_store_index(xa, 7, GFP_KERNEL); | 396 | xa_store_index(xa, 7, GFP_KERNEL); |
395 | 397 | ||
396 | xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { | 398 | xa_for_each(xa, index, entry) { |
397 | XA_BUG_ON(xa, index != 5 && index != 7); | 399 | XA_BUG_ON(xa, index != 5 && index != 7); |
398 | } | 400 | } |
399 | xa_destroy(xa); | 401 | xa_destroy(xa); |
@@ -812,17 +814,16 @@ static noinline void check_find_1(struct xarray *xa) | |||
812 | static noinline void check_find_2(struct xarray *xa) | 814 | static noinline void check_find_2(struct xarray *xa) |
813 | { | 815 | { |
814 | void *entry; | 816 | void *entry; |
815 | unsigned long i, j, index = 0; | 817 | unsigned long i, j, index; |
816 | 818 | ||
817 | xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { | 819 | xa_for_each(xa, index, entry) { |
818 | XA_BUG_ON(xa, true); | 820 | XA_BUG_ON(xa, true); |
819 | } | 821 | } |
820 | 822 | ||
821 | for (i = 0; i < 1024; i++) { | 823 | for (i = 0; i < 1024; i++) { |
822 | xa_store_index(xa, index, GFP_KERNEL); | 824 | xa_store_index(xa, index, GFP_KERNEL); |
823 | j = 0; | 825 | j = 0; |
824 | index = 0; | 826 | xa_for_each(xa, index, entry) { |
825 | xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { | ||
826 | XA_BUG_ON(xa, xa_mk_index(index) != entry); | 827 | XA_BUG_ON(xa, xa_mk_index(index) != entry); |
827 | XA_BUG_ON(xa, index != j++); | 828 | XA_BUG_ON(xa, index != j++); |
828 | } | 829 | } |
@@ -839,6 +840,7 @@ static noinline void check_find_3(struct xarray *xa) | |||
839 | 840 | ||
840 | for (i = 0; i < 100; i++) { | 841 | for (i = 0; i < 100; i++) { |
841 | for (j = 0; j < 100; j++) { | 842 | for (j = 0; j < 100; j++) { |
843 | rcu_read_lock(); | ||
842 | for (k = 0; k < 100; k++) { | 844 | for (k = 0; k < 100; k++) { |
843 | xas_set(&xas, j); | 845 | xas_set(&xas, j); |
844 | xas_for_each_marked(&xas, entry, k, XA_MARK_0) | 846 | xas_for_each_marked(&xas, entry, k, XA_MARK_0) |
@@ -847,6 +849,7 @@ static noinline void check_find_3(struct xarray *xa) | |||
847 | XA_BUG_ON(xa, | 849 | XA_BUG_ON(xa, |
848 | xas.xa_node != XAS_RESTART); | 850 | xas.xa_node != XAS_RESTART); |
849 | } | 851 | } |
852 | rcu_read_unlock(); | ||
850 | } | 853 | } |
851 | xa_store_index(xa, i, GFP_KERNEL); | 854 | xa_store_index(xa, i, GFP_KERNEL); |
852 | xa_set_mark(xa, i, XA_MARK_0); | 855 | xa_set_mark(xa, i, XA_MARK_0); |
@@ -1183,6 +1186,35 @@ static noinline void check_store_range(struct xarray *xa) | |||
1183 | } | 1186 | } |
1184 | } | 1187 | } |
1185 | 1188 | ||
1189 | static void check_align_1(struct xarray *xa, char *name) | ||
1190 | { | ||
1191 | int i; | ||
1192 | unsigned int id; | ||
1193 | unsigned long index; | ||
1194 | void *entry; | ||
1195 | |||
1196 | for (i = 0; i < 8; i++) { | ||
1197 | id = 0; | ||
1198 | XA_BUG_ON(xa, xa_alloc(xa, &id, UINT_MAX, name + i, GFP_KERNEL) | ||
1199 | != 0); | ||
1200 | XA_BUG_ON(xa, id != i); | ||
1201 | } | ||
1202 | xa_for_each(xa, index, entry) | ||
1203 | XA_BUG_ON(xa, xa_is_err(entry)); | ||
1204 | xa_destroy(xa); | ||
1205 | } | ||
1206 | |||
1207 | static noinline void check_align(struct xarray *xa) | ||
1208 | { | ||
1209 | char name[] = "Motorola 68000"; | ||
1210 | |||
1211 | check_align_1(xa, name); | ||
1212 | check_align_1(xa, name + 1); | ||
1213 | check_align_1(xa, name + 2); | ||
1214 | check_align_1(xa, name + 3); | ||
1215 | // check_align_2(xa, name); | ||
1216 | } | ||
1217 | |||
1186 | static LIST_HEAD(shadow_nodes); | 1218 | static LIST_HEAD(shadow_nodes); |
1187 | 1219 | ||
1188 | static void test_update_node(struct xa_node *node) | 1220 | static void test_update_node(struct xa_node *node) |
@@ -1332,6 +1364,7 @@ static int xarray_checks(void) | |||
1332 | check_create_range(&array); | 1364 | check_create_range(&array); |
1333 | check_store_range(&array); | 1365 | check_store_range(&array); |
1334 | check_store_iter(&array); | 1366 | check_store_iter(&array); |
1367 | check_align(&xa0); | ||
1335 | 1368 | ||
1336 | check_workingset(&array, 0); | 1369 | check_workingset(&array, 0); |
1337 | check_workingset(&array, 64); | 1370 | check_workingset(&array, 64); |