Kostenzer Felix | c5adae9 | 2017-02-24 15:01:07 -0800 | [diff] [blame] | 1 | #include <linux/sort.h> |
| 2 | #include <linux/slab.h> |
Paul Gortmaker | 8893f51 | 2017-02-24 15:01:09 -0800 | [diff] [blame] | 3 | #include <linux/init.h> |
Kostenzer Felix | c5adae9 | 2017-02-24 15:01:07 -0800 | [diff] [blame] | 4 | |
Paul Gortmaker | 8893f51 | 2017-02-24 15:01:09 -0800 | [diff] [blame] | 5 | /* |
| 6 | * A simple boot-time regression test |
| 7 | * License: GPL |
| 8 | */ |
Kostenzer Felix | c5adae9 | 2017-02-24 15:01:07 -0800 | [diff] [blame] | 9 | |
| 10 | #define TEST_LEN 1000 |
| 11 | |
| 12 | static int __init cmpint(const void *a, const void *b) |
| 13 | { |
| 14 | return *(int *)a - *(int *)b; |
| 15 | } |
| 16 | |
| 17 | static int __init test_sort_init(void) |
| 18 | { |
| 19 | int *a, i, r = 1, err = -ENOMEM; |
| 20 | |
| 21 | a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL); |
| 22 | if (!a) |
| 23 | return err; |
| 24 | |
| 25 | for (i = 0; i < TEST_LEN; i++) { |
| 26 | r = (r * 725861) % 6599; |
| 27 | a[i] = r; |
| 28 | } |
| 29 | |
| 30 | sort(a, TEST_LEN, sizeof(*a), cmpint, NULL); |
| 31 | |
| 32 | err = -EINVAL; |
| 33 | for (i = 0; i < TEST_LEN-1; i++) |
| 34 | if (a[i] > a[i+1]) { |
| 35 | pr_err("test has failed\n"); |
| 36 | goto exit; |
| 37 | } |
| 38 | err = 0; |
| 39 | pr_info("test passed\n"); |
| 40 | exit: |
| 41 | kfree(a); |
| 42 | return err; |
| 43 | } |
Paul Gortmaker | 8893f51 | 2017-02-24 15:01:09 -0800 | [diff] [blame] | 44 | subsys_initcall(test_sort_init); |