aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2009-10-22 03:53:33 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2009-11-30 04:41:49 -0500
commit7126bd8be4ee009c56c4ec037f07f2c0884413fc (patch)
tree0c453ef8f478f10d70aa5a913a36795244711bfc
parent1c63aca32903efc219fb9df72bae5344f3e54ed5 (diff)
mtd: add nand_ecc test module
This module tests NAND ECC functions. The test is simple. 1. Create a 256 or 512 bytes block of data filled with random bytes (data) 2. Duplicate the data block and inject single bit error (error_data) 3. Try to correct error_data 4. Compare data and error_data Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Acked-by: Vimal Singh <vimalsingh@ti.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/tests/Makefile1
-rw-r--r--drivers/mtd/tests/mtd_nandecctest.c87
2 files changed, 88 insertions, 0 deletions
diff --git a/drivers/mtd/tests/Makefile b/drivers/mtd/tests/Makefile
index c1d501335006..b44dcab940d8 100644
--- a/drivers/mtd/tests/Makefile
+++ b/drivers/mtd/tests/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o
5obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o 5obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o
6obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o 6obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o
7obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o 7obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
8obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o
diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c
new file mode 100644
index 000000000000..c1f31051784c
--- /dev/null
+++ b/drivers/mtd/tests/mtd_nandecctest.c
@@ -0,0 +1,87 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/list.h>
4#include <linux/slab.h>
5#include <linux/random.h>
6#include <linux/string.h>
7#include <linux/bitops.h>
8#include <linux/jiffies.h>
9#include <linux/mtd/nand_ecc.h>
10
11#if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE)
12
13static void inject_single_bit_error(void *data, size_t size)
14{
15 unsigned long offset = random32() % (size * BITS_PER_BYTE);
16
17 __change_bit(offset, data);
18}
19
20static unsigned char data[512];
21static unsigned char error_data[512];
22
23static int nand_ecc_test(const size_t size)
24{
25 unsigned char code[3];
26 unsigned char error_code[3];
27 char testname[30];
28
29 BUG_ON(sizeof(data) < size);
30
31 sprintf(testname, "nand-ecc-%zu", size);
32
33 get_random_bytes(data, size);
34
35 memcpy(error_data, data, size);
36 inject_single_bit_error(error_data, size);
37
38 __nand_calculate_ecc(data, size, code);
39 __nand_calculate_ecc(error_data, size, error_code);
40 __nand_correct_data(error_data, code, error_code, size);
41
42 if (!memcmp(data, error_data, size)) {
43 printk(KERN_INFO "mtd_nandecctest: ok - %s\n", testname);
44 return 0;
45 }
46
47 printk(KERN_ERR "mtd_nandecctest: not ok - %s\n", testname);
48
49 printk(KERN_DEBUG "hexdump of data:\n");
50 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
51 data, size, false);
52 printk(KERN_DEBUG "hexdump of error data:\n");
53 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
54 error_data, size, false);
55
56 return -1;
57}
58
59#else
60
61static int nand_ecc_test(const size_t size)
62{
63 return 0;
64}
65
66#endif
67
68static int __init ecc_test_init(void)
69{
70 srandom32(jiffies);
71
72 nand_ecc_test(256);
73 nand_ecc_test(512);
74
75 return 0;
76}
77
78static void __exit ecc_test_exit(void)
79{
80}
81
82module_init(ecc_test_init);
83module_exit(ecc_test_exit);
84
85MODULE_DESCRIPTION("NAND ECC function test module");
86MODULE_AUTHOR("Akinobu Mita");
87MODULE_LICENSE("GPL");