* [PATCH 3/3 -v3] MTD: Add nand_ecc test module
@ 2009-10-21 8:34 Akinobu Mita
2009-10-21 8:51 ` Artem Bityutskiy
0 siblings, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2009-10-21 8:34 UTC (permalink / raw)
To: linux-mtd; +Cc: Artem Bityutskiy, David Woodhouse, Akinobu Mita, vimal singh
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>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: vimal singh <vimal.newwork@gmail.com>
---
drivers/mtd/tests/Makefile | 1 +
drivers/mtd/tests/nand_ecc-test.c | 87 +++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 0 deletions(-)
create mode 100644 drivers/mtd/tests/nand_ecc-test.c
diff --git a/drivers/mtd/tests/Makefile b/drivers/mtd/tests/Makefile
index 919d066..8371b60 100644
--- a/drivers/mtd/tests/Makefile
+++ b/drivers/mtd/tests/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
obj-$(CONFIG_MTD_NAND_TESTS) += mtd_oobtest.o
obj-$(CONFIG_MTD_NAND_TESTS) += mtd_pagetest.o
obj-$(CONFIG_MTD_NAND_TESTS) += mtd_subpagetest.o
+obj-$(CONFIG_MTD_NAND_TESTS) += nand_ecc-test.o
diff --git a/drivers/mtd/tests/nand_ecc-test.c b/drivers/mtd/tests/nand_ecc-test.c
new file mode 100644
index 0000000..63ae856
--- /dev/null
+++ b/drivers/mtd/tests/nand_ecc-test.c
@@ -0,0 +1,87 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/string.h>
+#include <linux/bitops.h>
+#include <linux/jiffies.h>
+#include <linux/mtd/nand_ecc.h>
+
+#if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE)
+
+static void inject_single_bit_error(void *data, size_t size)
+{
+ unsigned long offset = random32() % (size * BITS_PER_BYTE);
+
+ __change_bit(offset, data);
+}
+
+static unsigned char data[512];
+static unsigned char error_data[512];
+
+static int nand_ecc_test(const size_t size)
+{
+ unsigned char code[3];
+ unsigned char error_code[3];
+ char testname[30];
+
+ BUG_ON(sizeof(data) < size);
+
+ sprintf(testname, "nand-ecc-%zu", size);
+
+ get_random_bytes(data, size);
+
+ memcpy(error_data, data, size);
+ inject_single_bit_error(error_data, size);
+
+ __nand_calculate_ecc(data, size, code);
+ __nand_calculate_ecc(error_data, size, error_code);
+ __nand_correct_data(error_data, code, error_code, size);
+
+ if (!memcmp(data, error_data, size)) {
+ printk(KERN_INFO "nand_ecc-test: ok - %s\n", testname);
+ return 0;
+ }
+
+ printk(KERN_ERR "nand_ecc-test: not ok - %s\n", testname);
+
+ printk(KERN_DEBUG "hexdump of data:\n");
+ print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
+ data, size, false);
+ printk(KERN_DEBUG "hexdump of error data:\n");
+ print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
+ error_data, size, false);
+
+ return -1;
+}
+
+#else
+
+static int nand_ecc_test(const size_t size)
+{
+ return 0;
+}
+
+#endif
+
+static int __init ecc_test_init(void)
+{
+ srandom32(jiffies);
+
+ nand_ecc_test(256);
+ nand_ecc_test(512);
+
+ return 0;
+}
+
+static void __exit ecc_test_exit(void)
+{
+}
+
+module_init(ecc_test_init);
+module_exit(ecc_test_exit);
+
+MODULE_DESCRIPTION("ECC test module");
+MODULE_AUTHOR("Akinobu Mita");
+MODULE_LICENSE("GPL");
--
1.5.4.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 3/3 -v3] MTD: Add nand_ecc test module
2009-10-21 8:34 [PATCH 3/3 -v3] MTD: Add nand_ecc test module Akinobu Mita
@ 2009-10-21 8:51 ` Artem Bityutskiy
2009-10-21 9:06 ` vimal singh
2009-10-22 3:24 ` Akinobu Mita
0 siblings, 2 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2009-10-21 8:51 UTC (permalink / raw)
To: Akinobu Mita; +Cc: David Woodhouse, linux-mtd, vimal singh
On Wed, 2009-10-21 at 17:34 +0900, Akinobu Mita wrote:
> 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>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: linux-mtd@lists.infradead.org
> Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
> Cc: vimal singh <vimal.newwork@gmail.com>
> ---
> drivers/mtd/tests/Makefile | 1 +
> drivers/mtd/tests/nand_ecc-test.c | 87 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 88 insertions(+), 0 deletions(-)
> create mode 100644 drivers/mtd/tests/nand_ecc-test.c
How about a consistent name for the test? All current tests have 'mtd_'
prefix. How about make the file to be 'mtd_ecctest.c' ?
Also, since you anyway need to use these "#defines", I think there is
not need to use this splitting. I apologize for leading you that way at
the beginning.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3 -v3] MTD: Add nand_ecc test module
2009-10-21 8:51 ` Artem Bityutskiy
@ 2009-10-21 9:06 ` vimal singh
2009-10-21 9:43 ` Artem Bityutskiy
2009-10-22 3:24 ` Akinobu Mita
1 sibling, 1 reply; 6+ messages in thread
From: vimal singh @ 2009-10-21 9:06 UTC (permalink / raw)
To: Artem.Bityutskiy; +Cc: David Woodhouse, linux-mtd, Akinobu Mita
On Wed, Oct 21, 2009 at 2:21 PM, Artem Bityutskiy
<Artem.Bityutskiy@nokia.com> wrote:
> On Wed, 2009-10-21 at 17:34 +0900, Akinobu Mita wrote:
>> 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>
>> Cc: David Woodhouse <dwmw2@infradead.org>
>> Cc: linux-mtd@lists.infradead.org
>> Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
>> Cc: vimal singh <vimal.newwork@gmail.com>
>> ---
>> drivers/mtd/tests/Makefile | 1 +
>> drivers/mtd/tests/nand_ecc-test.c | 87 +++++++++++++++++++++++++++++++++++++
>> 2 files changed, 88 insertions(+), 0 deletions(-)
>> create mode 100644 drivers/mtd/tests/nand_ecc-test.c
>
> How about a consistent name for the test? All current tests have 'mtd_'
> prefix. How about make the file to be 'mtd_ecctest.c' ?
Or 'mtd_nandecctest.c'..? Since, anyways, this test is only for nand.
--
Regards,
Vimal Singh
>
> Also, since you anyway need to use these "#defines", I think there is
> not need to use this splitting. I apologize for leading you that way at
> the beginning.
>
> --
> Best Regards,
> Artem Bityutskiy (Артём Битюцкий)
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3 -v3] MTD: Add nand_ecc test module
2009-10-21 9:06 ` vimal singh
@ 2009-10-21 9:43 ` Artem Bityutskiy
0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2009-10-21 9:43 UTC (permalink / raw)
To: vimal singh; +Cc: linux-mtd, David Woodhouse, Akinobu Mita
On Wed, 2009-10-21 at 14:36 +0530, vimal singh wrote:
> > How about a consistent name for the test? All current tests have 'mtd_'
> > prefix. How about make the file to be 'mtd_ecctest.c' ?
>
> Or 'mtd_nandecctest.c'..? Since, anyways, this test is only for nand.
Fair enough.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3 -v3] MTD: Add nand_ecc test module
2009-10-21 8:51 ` Artem Bityutskiy
2009-10-21 9:06 ` vimal singh
@ 2009-10-22 3:24 ` Akinobu Mita
2009-10-22 5:13 ` Artem Bityutskiy
1 sibling, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2009-10-22 3:24 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: David Woodhouse, linux-mtd, vimal singh
On Wed, Oct 21, 2009 at 11:51:35AM +0300, Artem Bityutskiy wrote:
> On Wed, 2009-10-21 at 17:34 +0900, Akinobu Mita wrote:
> > 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>
> > Cc: David Woodhouse <dwmw2@infradead.org>
> > Cc: linux-mtd@lists.infradead.org
> > Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
> > Cc: vimal singh <vimal.newwork@gmail.com>
> > ---
> > drivers/mtd/tests/Makefile | 1 +
> > drivers/mtd/tests/nand_ecc-test.c | 87 +++++++++++++++++++++++++++++++++++++
> > 2 files changed, 88 insertions(+), 0 deletions(-)
> > create mode 100644 drivers/mtd/tests/nand_ecc-test.c
>
> How about a consistent name for the test? All current tests have 'mtd_'
> prefix. How about make the file to be 'mtd_ecctest.c' ?
OK. I'll rename to mtd_nandecctest.c as vimal said.
> Also, since you anyway need to use these "#defines", I think there is
> not need to use this splitting. I apologize for leading you that way at
> the beginning.
Does it mean we don't need MTD_NAND_TESTS and the new mtd_nandecctest
should exist in MTD_TESTS with that #ifdef checks as I originally did?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3 -v3] MTD: Add nand_ecc test module
2009-10-22 3:24 ` Akinobu Mita
@ 2009-10-22 5:13 ` Artem Bityutskiy
0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2009-10-22 5:13 UTC (permalink / raw)
To: Akinobu Mita; +Cc: David Woodhouse, linux-mtd@lists.infradead.org, vimal singh
On Thu, 2009-10-22 at 05:24 +0200, ext Akinobu Mita wrote:
> On Wed, Oct 21, 2009 at 11:51:35AM +0300, Artem Bityutskiy wrote:
> > On Wed, 2009-10-21 at 17:34 +0900, Akinobu Mita wrote:
> > > 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>
> > > Cc: David Woodhouse <dwmw2@infradead.org>
> > > Cc: linux-mtd@lists.infradead.org
> > > Cc: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
> > > Cc: vimal singh <vimal.newwork@gmail.com>
> > > ---
> > > drivers/mtd/tests/Makefile | 1 +
> > > drivers/mtd/tests/nand_ecc-test.c | 87 +++++++++++++++++++++++++++++++++++++
> > > 2 files changed, 88 insertions(+), 0 deletions(-)
> > > create mode 100644 drivers/mtd/tests/nand_ecc-test.c
> >
> > How about a consistent name for the test? All current tests have 'mtd_'
> > prefix. How about make the file to be 'mtd_ecctest.c' ?
>
> OK. I'll rename to mtd_nandecctest.c as vimal said.
>
> > Also, since you anyway need to use these "#defines", I think there is
> > not need to use this splitting. I apologize for leading you that way at
> > the beginning.
>
> Does it mean we don't need MTD_NAND_TESTS and the new mtd_nandecctest
> should exist in MTD_TESTS with that #ifdef checks as I originally did?
Right. The idea was to avoid the ifdefs by cheap price, but now it seems
that was bad idea.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-10-22 5:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-21 8:34 [PATCH 3/3 -v3] MTD: Add nand_ecc test module Akinobu Mita
2009-10-21 8:51 ` Artem Bityutskiy
2009-10-21 9:06 ` vimal singh
2009-10-21 9:43 ` Artem Bityutskiy
2009-10-22 3:24 ` Akinobu Mita
2009-10-22 5:13 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox