2019-05-19 05:08:20 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-02-24 16:01:07 -07:00
|
|
|
#include <linux/sort.h>
|
|
|
|
#include <linux/slab.h>
|
2017-05-08 15:55:20 -07:00
|
|
|
#include <linux/module.h>
|
2017-02-24 16:01:07 -07:00
|
|
|
|
2017-05-08 15:55:20 -07:00
|
|
|
/* a simple boot-time regression test */
|
2017-02-24 16:01:07 -07:00
|
|
|
|
|
|
|
#define TEST_LEN 1000
|
|
|
|
|
|
|
|
static int __init cmpint(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return *(int *)a - *(int *)b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init test_sort_init(void)
|
|
|
|
{
|
|
|
|
int *a, i, r = 1, err = -ENOMEM;
|
|
|
|
|
|
|
|
a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
|
|
|
|
if (!a)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
for (i = 0; i < TEST_LEN; i++) {
|
|
|
|
r = (r * 725861) % 6599;
|
|
|
|
a[i] = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
sort(a, TEST_LEN, sizeof(*a), cmpint, NULL);
|
|
|
|
|
|
|
|
err = -EINVAL;
|
|
|
|
for (i = 0; i < TEST_LEN-1; i++)
|
|
|
|
if (a[i] > a[i+1]) {
|
|
|
|
pr_err("test has failed\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
err = 0;
|
|
|
|
pr_info("test passed\n");
|
|
|
|
exit:
|
|
|
|
kfree(a);
|
|
|
|
return err;
|
|
|
|
}
|
2017-05-08 15:55:20 -07:00
|
|
|
|
2018-02-06 16:38:42 -07:00
|
|
|
static void __exit test_sort_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-08 15:55:20 -07:00
|
|
|
module_init(test_sort_init);
|
2018-02-06 16:38:42 -07:00
|
|
|
module_exit(test_sort_exit);
|
|
|
|
|
2017-05-08 15:55:20 -07:00
|
|
|
MODULE_LICENSE("GPL");
|