]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - lib/test_sort.c
Merge tag 'drm-misc-fixes-2017-08-28' of git://anongit.freedesktop.org/git/drm-misc...
[mirror_ubuntu-artful-kernel.git] / lib / test_sort.c
CommitLineData
c5adae95
KF
1#include <linux/sort.h>
2#include <linux/slab.h>
ebd03a9a 3#include <linux/module.h>
c5adae95 4
ebd03a9a 5/* a simple boot-time regression test */
c5adae95
KF
6
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}
ebd03a9a
GU
41
42module_init(test_sort_init);
43MODULE_LICENSE("GPL");