1 #include <linux/module.h>
2 #include <linux/printk.h>
3 #include <linux/slab.h>
4 #include <linux/string.h>
6 static __init
int memset16_selftest(void)
11 p
= kmalloc(256 * 2 * 2, GFP_KERNEL
);
15 for (i
= 0; i
< 256; i
++) {
16 for (j
= 0; j
< 256; j
++) {
17 memset(p
, 0xa1, 256 * 2 * sizeof(v
));
18 memset16(p
+ i
, 0xb1b2, j
);
19 for (k
= 0; k
< 512; k
++) {
24 } else if (k
< i
+ j
) {
38 return (i
<< 24) | (j
<< 16) | k
| 0x8000;
42 static __init
int memset32_selftest(void)
47 p
= kmalloc(256 * 2 * 4, GFP_KERNEL
);
51 for (i
= 0; i
< 256; i
++) {
52 for (j
= 0; j
< 256; j
++) {
53 memset(p
, 0xa1, 256 * 2 * sizeof(v
));
54 memset32(p
+ i
, 0xb1b2b3b4, j
);
55 for (k
= 0; k
< 512; k
++) {
60 } else if (k
< i
+ j
) {
74 return (i
<< 24) | (j
<< 16) | k
| 0x8000;
78 static __init
int memset64_selftest(void)
83 p
= kmalloc(256 * 2 * 8, GFP_KERNEL
);
87 for (i
= 0; i
< 256; i
++) {
88 for (j
= 0; j
< 256; j
++) {
89 memset(p
, 0xa1, 256 * 2 * sizeof(v
));
90 memset64(p
+ i
, 0xb1b2b3b4b5b6b7b8ULL
, j
);
91 for (k
= 0; k
< 512; k
++) {
94 if (v
!= 0xa1a1a1a1a1a1a1a1ULL
)
96 } else if (k
< i
+ j
) {
97 if (v
!= 0xb1b2b3b4b5b6b7b8ULL
)
100 if (v
!= 0xa1a1a1a1a1a1a1a1ULL
)
110 return (i
<< 24) | (j
<< 16) | k
| 0x8000;
114 static __init
int string_selftest_init(void)
119 subtest
= memset16_selftest();
124 subtest
= memset32_selftest();
129 subtest
= memset64_selftest();
133 pr_info("String selftests succeeded\n");
136 pr_crit("String selftest failure %d.%08x\n", test
, subtest
);
140 module_init(string_selftest_init
);
141 MODULE_LICENSE("GPL v2");