blob: 385c0ed5202ffbf9bdd9a18d39b2ab229f6b437d [file] [log] [blame]
Kostenzer Felixc5adae92017-02-24 15:01:07 -08001#include <linux/sort.h>
2#include <linux/slab.h>
Geert Uytterhoevenebd03a92017-05-08 15:55:20 -07003#include <linux/module.h>
Kostenzer Felixc5adae92017-02-24 15:01:07 -08004
Geert Uytterhoevenebd03a92017-05-08 15:55:20 -07005/* a simple boot-time regression test */
Kostenzer Felixc5adae92017-02-24 15:01:07 -08006
7#define TEST_LEN 1000
8
9static int __init cmpint(const void *a, const void *b)
10{
11 return *(int *)a - *(int *)b;
12}
13
14static int __init test_sort_init(void)
15{
16 int *a, i, r = 1, err = -ENOMEM;
17
18 a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
19 if (!a)
20 return err;
21
22 for (i = 0; i < TEST_LEN; i++) {
23 r = (r * 725861) % 6599;
24 a[i] = r;
25 }
26
27 sort(a, TEST_LEN, sizeof(*a), cmpint, NULL);
28
29 err = -EINVAL;
30 for (i = 0; i < TEST_LEN-1; i++)
31 if (a[i] > a[i+1]) {
32 pr_err("test has failed\n");
33 goto exit;
34 }
35 err = 0;
36 pr_info("test passed\n");
37exit:
38 kfree(a);
39 return err;
40}
Geert Uytterhoevenebd03a92017-05-08 15:55:20 -070041
Pravin Shedge92fc7cb2018-02-06 15:38:42 -080042static void __exit test_sort_exit(void)
43{
44}
45
Geert Uytterhoevenebd03a92017-05-08 15:55:20 -070046module_init(test_sort_init);
Pravin Shedge92fc7cb2018-02-06 15:38:42 -080047module_exit(test_sort_exit);
48
Geert Uytterhoevenebd03a92017-05-08 15:55:20 -070049MODULE_LICENSE("GPL");