mtd: mtd_nandecctest: add more tests
v3 cover mtd: mtd_nandecctest: add more tests
This patch series adds several tests cases to mtd_nandecctest module and includes several minor changes.
Changelog
* v3
- remove unnecessary include
- split into still smaller patches
* v2
- split one patch into smaller patches
Akinobu Mita (11):
mtd: mtd_nandecctest: remove unnecessary srandom32() call
mtd: mtd_nandecctest: make module_init() return an error code if test
fails
mtd: mtd_nandecctest: remove unnecessary include
mtd: mtd_nandecctest: make module_init() return appropriate errno
mtd: mtd_nandecctest: improve message output
mtd: mtd_nandecctest: ensure alignment requirement for bitops
mtd: mtd_nandecctest: generalize injecting bit errors function for
ecc code
mtd: mtd_nandecctest: rewrite the test routine
mtd: mtd_nandecctest: add no corruption test
mtd: mtd_nandecctest: add single bit error correction test
mtd: mtd_nandecctest: add double bit error detection tests
drivers/mtd/tests/mtd_nandecctest.c | 280 +++++++++++++++++++++++++++++++----- 1 file changed, 247 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.11.4
PATCH v3 1/11 mtd: mtd_nandecctest: remove unnecessary srandom32() call
It is unnecessary for this driver to call srandom32() in module_init.
---
No changes from previous version
drivers/mtd/tests/mtd_nandecctest.c | 2 -- 1 file changed, 2 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +0 -2
@@ -66,8 +66,6 @@ static int nand_ecc_test(const size_t size)static int __init ecc_test_init (void ) { -srandom32 (jiffies); -nand_ecc_test (256 );nand_ecc_test (512 );
Signature · 1 line
1.7.11.4
Re: [PATCH v3 01/11] mtd: mtd_nandecctest: remove unnecessary srandom32() call
Quoted 3 lines · Akinobu Mita
It is unnecessary for this driver to call
srandom32()inmodule_init.Signed-off-by Akinobu Mita <[email protected]>
Just FYI, patches 1 and 2 are already in l2-mtd.git, no need to re-send patches which are in the l2 tree again.
Signature · 2 lines
Best Regards, Artem Bityutskiy
PATCH v3 2/11 mtd: mtd_nandecctest: make module_init() return an error code if test fails
In reply to Akinobu MitaReturn an error code if test fails in order to detect a test case failure by invoking tests repeatedly like this:
while sudo modprobe mtd_nandecctest; do
sudo modprobe -r mtd_nandecctest
done
---
No changes from previous version
drivers/mtd/tests/mtd_nandecctest.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +6 -3
@@ -66,10 +66,13 @@ static int nand_ecc_test(const size_t size)static int __init ecc_test_init (void ) { -nand_ecc_test (256 ); -nand_ecc_test (512 ); +int err; -return 0 ; + err =nand_ecc_test (256 ); +if (err) +return err; + +return nand_ecc_test (512 ); } static void __exit ecc_test_exit(void)
Signature · 1 line
1.7.11.4
PATCH v3 3/11 mtd: mtd_nandecctest: remove unnecessary include
In reply to Akinobu MitaIncluding linux/jiffies.h was required for calling srandom32(jiffies) that has already been removed.
--- drivers/mtd/tests/mtd_nandecctest.c | 1 - 1 file changed, 1 deletion(-)
drivers/mtd/tests/mtd_nandecctest.c +0 -1
@@ -4,7 +4,6 @@#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 )
Signature · 1 line
1.7.11.4
PATCH v3 4/11 mtd: mtd_nandecctest: make module_init() return appropriate errno
In reply to Akinobu MitaReturn -EINVAL instead of -1 (-EPERM) when test fails.
--- drivers/mtd/tests/mtd_nandecctest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/tests/mtd_nandecctest.c +1 -1
@@ -51,7 +51,7 @@ static int nand_ecc_test(const size_t size)print_hex_dump (KERN_DEBUG ,"" ,DUMP_PREFIX_OFFSET ,16 ,4 , error_data, size, false); - return -1; + return -EINVAL; }#else
Signature · 1 line
1.7.11.4
PATCH v3 5/11 mtd: mtd_nandecctest: improve message output
In reply to Akinobu MitaThis includes the message related changes:
- Use pr_* instead of printk
- Print hexdump of ECC code if test fails
- Change log level for hexdump of data from KERN_DEBUG to KERN_INFO
- Factor out the hexdump code into a separate function
--- drivers/mtd/tests/mtd_nandecctest.c | 48 ++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +29 -19
@@ -15,41 +15,51 @@ static void inject_single_bit_error(void *data, size_t size)__change_bit (offset, data); } -static unsigned char data[512 ]; +static void dump_data_ecc (void *error_data,void *error_ecc,void *correct_data, +void *correct_ecc,const size_t size) +{ +pr_info ("hexdump of error data:\n" ); +print_hex_dump (KERN_INFO ,"" ,DUMP_PREFIX_OFFSET ,16 ,4 , + error_data, size, false); +print_hex_dump (KERN_INFO ,"hexdump of error ecc: " , +DUMP_PREFIX_NONE ,16 ,1 , error_ecc,3 , false); + +pr_info ("hexdump of correct data:\n" ); +print_hex_dump (KERN_INFO ,"" ,DUMP_PREFIX_OFFSET ,16 ,4 , + correct_data, size, false); +print_hex_dump (KERN_INFO ,"hexdump of correct ecc: " , +DUMP_PREFIX_NONE ,16 ,1 , correct_ecc,3 , false); +} + +static unsigned char correct_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 ]; +unsigned char correct_ecc[3 ]; +unsigned char error_ecc[3 ];char testname[30 ]; -BUG_ON (sizeof (data) < size); +BUG_ON (sizeof (correct_data) < size);sprintf (testname,"nand-ecc-%zu" , size); -get_random_bytes (data, size); +get_random_bytes (correct_data, size); -memcpy (error_data, data, size); +memcpy (error_data, correct_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); +__nand_calculate_ecc (correct_data, size, correct_ecc); +__nand_calculate_ecc (error_data, size, error_ecc); +__nand_correct_data (error_data, correct_ecc, error_ecc, size); -if (!memcmp (data, error_data, size)) { -printk (KERN_INFO "mtd_nandecctest: ok - %s\n" , testname); +if (!memcmp (correct_data, error_data, size)) { +pr_info ("mtd_nandecctest: ok - %s\n" , testname);return 0 ; } -printk (KERN_ERR "mtd_nandecctest: 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); +pr_err ("mtd_nandecctest: not ok - %s\n" , testname); +dump_data_ecc (error_data, error_ecc, correct_data, correct_ecc, size);return -EINVAL ; }
Signature · 1 line
1.7.11.4
PATCH v3 6/11 mtd: mtd_nandecctest: ensure alignment requirement for bitops
In reply to Akinobu MitaCurrently the data blocks which is used to test single bit error correction is allocated statically and injecting single bit error is implemented by using __change_bit() which must operate on the memory aligned to the size of an "unsigned long". But there is no such guarantee for statically allocated array.
This fix the issue by allocating the data block dynamically by kmalloc(). It also allocate the ecc code dynamically instead of allocating statically on stack.
The reason to allocate the ecc code dynamically is that later change will add tests which inject bit errors into the ecc code by bitops.
--- drivers/mtd/tests/mtd_nandecctest.c | 43 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +29 -14
@@ -4,6 +4,7 @@#include <linux/random.h> #include <linux/string.h> #include <linux/bitops.h> +#include <linux/slab.h> #include <linux/mtd/nand_ecc.h> #if defined(CONFIG_MTD_NAND ) || defined(CONFIG_MTD_NAND_MODULE )
@@ -31,16 +32,24 @@ static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data, DUMP_PREFIX_NONE, 16, 1, correct_ecc, 3, false); } -static unsigned char correct_data[512 ]; -static unsigned char error_data[512 ]; -static int nand_ecc_test (const size_t size) { -unsigned char correct_ecc[3 ]; -unsigned char error_ecc[3 ]; +int err =0 ; +void *error_data; +void *error_ecc; +void *correct_data; +void *correct_ecc;char testname[30 ]; -BUG_ON (sizeof (correct_data) < size); + error_data =kmalloc (size,GFP_KERNEL ); + error_ecc =kmalloc (3 ,GFP_KERNEL ); + correct_data =kmalloc (size,GFP_KERNEL ); + correct_ecc =kmalloc (3 ,GFP_KERNEL ); + +if (!error_data || !error_ecc || !correct_data || !correct_ecc) { + err = -ENOMEM ; + goto error; + }sprintf (testname,"nand-ecc-%zu" , size);
@@ -53,15 +62,21 @@ static int nand_ecc_test(const size_t size)__nand_calculate_ecc (error_data, size, error_ecc);__nand_correct_data (error_data, correct_ecc, error_ecc, size); -if (!memcmp (correct_data, error_data, size)) { -pr_info ("mtd_nandecctest: ok - %s\n" , testname); -return 0 ; +if (memcmp (correct_data, error_data, size)) { +pr_err ("mtd_nandecctest: not ok - %s\n" , testname); +dump_data_ecc (error_data, error_ecc, correct_data, correct_ecc, + size); + err = -EINVAL ; + goto error; } - -pr_err ("mtd_nandecctest: not ok - %s\n" , testname); -dump_data_ecc (error_data, error_ecc, correct_data, correct_ecc, size); - - return -EINVAL; +pr_info ("mtd_nandecctest: ok - %s\n" , testname); +error: +kfree (error_data); +kfree (error_ecc); +kfree (correct_data); +kfree (correct_ecc); + + return err; }#else
Signature · 1 line
1.7.11.4
PATCH v3 7/11 mtd: mtd_nandecctest: generalize injecting bit errors function for ecc code
In reply to Akinobu MitaIn order to inject deliberate bit errors into the ecc code which only has 3 bytes, this adjusts the bitops usage in inject_single_bit_error() which is currently only used for injecting into the 256 or 512 bytes data block.
--- drivers/mtd/tests/mtd_nandecctest.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +11 -2
@@ -7,13 +7,22 @@#include <linux/slab.h> #include <linux/mtd/nand_ecc.h> +#include <asm/byteorder.h> +#if defined(CONFIG_MTD_NAND ) || defined(CONFIG_MTD_NAND_MODULE ) +#ifdef __LITTLE_ENDIAN +#define __change_bit_le (nr, addr) __change_bit(nr, addr) +#else +#define __change_bit_le (nr, addr) \ + __change_bit((nr) ^ ((BITS_PER_LONG - 1) & ~0x7), addr) +#endif +static void inject_single_bit_error (void *data,size_t size) { -unsigned long offset =random32 () % (size *BITS_PER_BYTE ); +unsigned int offset =random32 () % (size *BITS_PER_BYTE ); -__change_bit (offset, data); +__change_bit_le (offset, data); } static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data,
Signature · 1 line
1.7.11.4
Re: [PATCH v3 07/11] mtd: mtd_nandecctest: generalize injecting bit errors function for ecc code
Quoted 9 lines · Akinobu Mita
In order to inject deliberate bit errors into the ecc code which only has 3 bytes, this adjusts the bitops usage in
inject_single_bit_error()which is currently only used for injecting into the 256 or 512 bytes data block.Signed-off-by Akinobu Mita <[email protected]>Cc David Woodhouse <[email protected]>Cc Artem Bityutskiy <[email protected]>
I do not understand the commit message and the patch.
drivers/mtd/tests/mtd_nandecctest.c line 10
Quoted 13 lines
--- drivers/mtd/tests/mtd_nandecctest.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/mtd/tests/mtd_nandecctest.c +1
-0@@ -7,13 +7,22 @@#include <linux/slab.h> #include <linux/mtd/nand_ecc.h> +#include <asm/byteorder.h>
I think you do not need to include this.
drivers/mtd/tests/mtd_nandecctest.c line 19
Quoted 9 lines
drivers/mtd/tests/mtd_nandecctest.c +7
-0+#if defined(CONFIG_MTD_NAND ) || defined(CONFIG_MTD_NAND_MODULE ) +#ifdef __LITTLE_ENDIAN +#define __change_bit_le (nr, addr) __change_bit(nr, addr) +#else +#define __change_bit_le (nr, addr) \ + __change_bit((nr) ^ ((BITS_PER_LONG - 1) & ~0x7), addr) +#endif
Why is this "#ifdef" needed? Can you please add a comment explaining this? Which problem do you solve by adding '__change_bit_le()' ?
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH v3 07/11] mtd: mtd_nandecctest: generalize injecting bit errors function for ecc code
2012/9/4 Artem Bityutskiy <[email protected]>:
Quoted 24 lines · Akinobu Mita
Quoted 9 lines
In order to inject deliberate bit errors into the ecc code which only has 3 bytes, this adjusts the bitops usage in
inject_single_bit_error()which is currently only used for injecting into the 256 or 512 bytes data block.Signed-off-by Akinobu Mita <[email protected]>Cc David Woodhouse <[email protected]>Cc Artem Bityutskiy <[email protected]>I do not understand the commit message and the patch.
Quoted 12 lines
--- drivers/mtd/tests/mtd_nandecctest.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/mtd/tests/mtd_nandecctest.c +0
-0@@ -7,13 +7,22 @@#include <linux/slab.h> #include <linux/mtd/nand_ecc.h>
Quoted 3 lines
drivers/mtd/tests/mtd_nandecctest.c line 10
Quoted 1 line
drivers/mtd/tests/mtd_nandecctest.c +1
-0+#include <asm/byteorder.h> I think you do not need to include this.
OK, I'll remove this.
Quoted 12 lines
drivers/mtd/tests/mtd_nandecctest.c line 19
Quoted 9 lines
drivers/mtd/tests/mtd_nandecctest.c +7
-0+#if defined(CONFIG_MTD_NAND ) || defined(CONFIG_MTD_NAND_MODULE ) +#ifdef __LITTLE_ENDIAN +#define __change_bit_le (nr, addr) __change_bit(nr, addr) +#else +#define __change_bit_le (nr, addr) \ + __change_bit((nr) ^ ((BITS_PER_LONG - 1) & ~0x7), addr) +#endif Why is this "#ifdef" needed? Can you please add a comment explaining this? Which problem do you solve by adding '
__change_bit_le()' ?
Sorry for that imcomplete commit message. I'll update with this:
mtd: mtd_nandecctest: support injecting bit error for ecc code
Currently inject_single_bit_error() is used to inject single bit error into randomly selected bit position of the 256 or 512 bytes data block.
Later change will add tests which inject bit errors into the ecc code. Unfortunately, inject_single_bit_error() doesn't work for the ecc code which is not a multiple of sizeof(unsigned long).
Because bit fliping at random position is done by __change_bit(). For example, flipping bit position 0 by __change_bit(0, addr) modifies 3rd byte (32bit) or 7th byte (64bit) on big-endian systems.
Using little-endian version of bitops can fix this issue. But little-endian version of __change_bit is not yet available. So this defines __change_bit_le() locally in a similar fashion to asm-generic/bitops/le.h and use it.
...
Also I'll add this comment:
/*
* The reason for this __change_bit_le() instead of __change_bit()
* is to inject bit error properly within the region which is not a
* multiple of sizeof(unsigned long) on big-endian systems */
PATCH v3 8/11 mtd: mtd_nandecctest: rewrite the test routine
In reply to Akinobu MitaThis rewrites the entire test routine in order to make it easy to add more tests by later changes and minimize duplication of each tests as much as possible.
--- drivers/mtd/tests/mtd_nandecctest.c | 83 +++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 23 deletions(-)
drivers/mtd/tests/mtd_nandecctest.c +60 -23
@@ -11,6 +11,12 @@#if defined(CONFIG_MTD_NAND ) || defined(CONFIG_MTD_NAND_MODULE ) +struct nand_ecc_test { +const char *name; +void (*prepare)(void *,void *,void *,void *,const size_t ); +int (*verify)(void *,void *,void *,const size_t ); +}; +#ifdef __LITTLE_ENDIAN#define __change_bit_le (nr, addr) __change_bit(nr, addr)#else
@@ -18,13 +24,44 @@ __change_bit((nr) ^ ((BITS_PER_LONG - 1) & ~0x7), addr)#endif -static void inject_single_bit_error (void *data,size_t size) +static void single_bit_error_data (void *error_data,void *correct_data, +size_t size) {unsigned int offset =random32 () % (size *BITS_PER_BYTE ); -__change_bit_le (offset, data); +memcpy (error_data, correct_data, size); +__change_bit_le (offset, error_data); +} + +static void single_bit_error_in_data (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +single_bit_error_data (error_data, correct_data, size); +memcpy (error_ecc, correct_ecc,3 ); } +static int single_bit_error_correct (void *error_data,void *error_ecc, +void *correct_data,const size_t size) +{ +unsigned char calc_ecc[3 ]; +int ret; + +__nand_calculate_ecc (error_data, size, calc_ecc); + ret =__nand_correct_data (error_data, calc_ecc, error_ecc, size); +if (ret ==1 && !memcmp (correct_data, error_data, size)) +return 0 ; + +return -EINVAL ; +} + +static const struct nand_ecc_test nand_ecc_test[] = { + { + .name ="single-bit-error-in-data-correct" , + .prepare = single_bit_error_in_data, + .verify = single_bit_error_correct, + }, +}; +static void dump_data_ecc (void *error_data,void *error_ecc,void *correct_data,void *correct_ecc,const size_t size) {
@@ -41,14 +78,14 @@ static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data, DUMP_PREFIX_NONE, 16, 1, correct_ecc, 3, false); } -static int nand_ecc_test (const size_t size) +static int nand_ecc_test_run (const size_t size) { +int i;int err =0 ;void *error_data;void *error_ecc;void *correct_data;void *correct_ecc; -char testname[30 ]; error_data =kmalloc (size,GFP_KERNEL ); error_ecc =kmalloc (3 ,GFP_KERNEL );
@@ -60,25 +97,25 @@ static int nand_ecc_test(const size_t size) goto error; } -sprintf (testname,"nand-ecc-%zu" , size); -get_random_bytes (correct_data, size); - -memcpy (error_data, correct_data, size); -inject_single_bit_error (error_data, size); -__nand_calculate_ecc (correct_data, size, correct_ecc); -__nand_calculate_ecc (error_data, size, error_ecc); -__nand_correct_data (error_data, correct_ecc, error_ecc, size); - -if (memcmp (correct_data, error_data, size)) { -pr_err ("mtd_nandecctest: not ok - %s\n" , testname); -dump_data_ecc (error_data, error_ecc, correct_data, correct_ecc, - size); - err = -EINVAL ; - goto error; + +for (i =0 ; i <ARRAY_SIZE (nand_ecc_test); i++) { + nand_ecc_test[i].prepare (error_data, error_ecc, + correct_data, correct_ecc, size); + err = nand_ecc_test[i].verify (error_data, error_ecc, + correct_data, size); + +if (err) { +pr_err ("mtd_nandecctest: not ok - %s-%zd\n" , + nand_ecc_test[i].name, size); +dump_data_ecc (error_data, error_ecc, + correct_data, correct_ecc, size); +break ; + } +pr_info ("mtd_nandecctest: ok - %s-%zd\n" , + nand_ecc_test[i].name, size); } -pr_info ("mtd_nandecctest: ok - %s\n" , testname); error:kfree (error_data);kfree (error_ecc);
@@ -90,7 +127,7 @@ error:#else -static int nand_ecc_test (const size_t size) +static int nand_ecc_test_run (const size_t size) {return 0 ; }
@@ -101,11 +138,11 @@ static int __init ecc_test_init(void) {int err; - err =nand_ecc_test (256 ); + err =nand_ecc_test_run (256 );if (err)return err; -return nand_ecc_test (512 ); +return nand_ecc_test_run (512 ); } static void __exit ecc_test_exit(void)
Signature · 1 line
1.7.11.4
PATCH v3 9/11 mtd: mtd_nandecctest: add no corruption test
In reply to Akinobu MitaThis adds no corruptin test case listed below:
Prepare data block and ECC data with no corruption, and verify that the data block is preserved by __nand_correct_data()
---
No changes from previous version
drivers/mtd/tests/mtd_nandecctest.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/mtd/tests/mtd_nandecctest.c +26 -0
@@ -33,6 +33,27 @@ static void single_bit_error_data(void *error_data, void *correct_data,__change_bit_le (offset, error_data); } +static void no_bit_error (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +memcpy (error_data, correct_data, size); +memcpy (error_ecc, correct_ecc,3 ); +} + +static int no_bit_error_verify (void *error_data,void *error_ecc, +void *correct_data,const size_t size) +{ +unsigned char calc_ecc[3 ]; +int ret; + +__nand_calculate_ecc (error_data, size, calc_ecc); + ret =__nand_correct_data (error_data, calc_ecc, error_ecc, size); +if (ret ==0 && !memcmp (correct_data, error_data, size)) +return 0 ; + +return -EINVAL ; +} +static void single_bit_error_in_data (void *error_data,void *error_ecc,void *correct_data,void *correct_ecc,const size_t size) {
@@ -56,6 +77,11 @@ static int single_bit_error_correct(void *error_data, void *error_ecc,static const struct nand_ecc_test nand_ecc_test[] = { { + .name ="no-bit-error" , + .prepare = no_bit_error, + .verify = no_bit_error_verify, + }, + { .name ="single-bit-error-in-data-correct" , .prepare = single_bit_error_in_data, .verify = single_bit_error_correct,
Signature · 1 line
1.7.11.4
PATCH v3 10/11 mtd: mtd_nandecctest: add single bit error correction test
In reply to Akinobu MitaThis adds the single bit error correction test case listed below:
Prepare data block without corruption and ECC data with single bit error, and verify that the data block is preserved by __nand_correct_data().
---
No changes from previous version
drivers/mtd/tests/mtd_nandecctest.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/mtd/tests/mtd_nandecctest.c +37 -0
@@ -33,6 +33,31 @@ static void single_bit_error_data(void *error_data, void *correct_data,__change_bit_le (offset, error_data); } +static unsigned int random_ecc_bit (size_t size) +{ +unsigned int offset =random32 () % (3 *BITS_PER_BYTE ); + +if (size ==256 ) { +/* +* Don't inject a bit error into the insignificant bits (16th +* and 17th bit) in ECC code for 256 byte data block +*/ +while (offset ==16 || offset ==17 ) + offset =random32 () % (3 *BITS_PER_BYTE ); + } + +return offset; +} + +static void single_bit_error_ecc (void *error_ecc,void *correct_ecc, +size_t size) +{ +unsigned int offset =random_ecc_bit (size); + +memcpy (error_ecc, correct_ecc,3 ); +__change_bit_le (offset, error_ecc); +} +static void no_bit_error (void *error_data,void *error_ecc,void *correct_data,void *correct_ecc,const size_t size) {
@@ -61,6 +86,13 @@ static void single_bit_error_in_data(void *error_data, void *error_ecc,memcpy (error_ecc, correct_ecc,3 ); } +static void single_bit_error_in_ecc (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +memcpy (error_data, correct_data, size); +single_bit_error_ecc (error_ecc, correct_ecc, size); +} +static int single_bit_error_correct (void *error_data,void *error_ecc,void *correct_data,const size_t size) {
@@ -86,6 +118,11 @@ static const struct nand_ecc_test nand_ecc_test[] = { .prepare = single_bit_error_in_data, .verify = single_bit_error_correct, }, + { + .name = "single-bit-error-in-ecc-correct", + .prepare = single_bit_error_in_ecc, + .verify = single_bit_error_correct, + }, }; static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data,
Signature · 1 line
1.7.11.4
PATCH v3 11/11 mtd: mtd_nandecctest: add double bit error detection tests
In reply to Akinobu MitaThis adds the double bit error detection test cases listed below:
* Prepare data block with double bit error and ECC data without corruption, and verify that the uncorrectable error is detected by __nand_correct_data().
* Prepare data block with single bit error and ECC data with single bit error, and verify that the uncorrectable error is detected.
* Prepare data block without corruption and ECC data with double bit error, and verify that the uncorrectable error is detected.
---
No changes from previous version
drivers/mtd/tests/mtd_nandecctest.c | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/mtd/tests/mtd_nandecctest.c +80 -0
@@ -33,6 +33,22 @@ static void single_bit_error_data(void *error_data, void *correct_data,__change_bit_le (offset, error_data); } +static void double_bit_error_data (void *error_data,void *correct_data, +size_t size) +{ +unsigned int offset[2 ]; + + offset[0 ] =random32 () % (size *BITS_PER_BYTE ); +do { + offset[1 ] =random32 () % (size *BITS_PER_BYTE ); + }while (offset[0 ] == offset[1 ]); + +memcpy (error_data, correct_data, size); + +__change_bit_le (offset[0 ], error_data); +__change_bit_le (offset[1 ], error_data); +} +static unsigned int random_ecc_bit (size_t size) {unsigned int offset =random32 () % (3 *BITS_PER_BYTE );
@@ -58,6 +74,21 @@ static void single_bit_error_ecc(void *error_ecc, void *correct_ecc,__change_bit_le (offset, error_ecc); } +static void double_bit_error_ecc (void *error_ecc,void *correct_ecc, +size_t size) +{ +unsigned int offset[2 ]; + + offset[0 ] =random_ecc_bit (size); +do { + offset[1 ] =random_ecc_bit (size); + }while (offset[0 ] == offset[1 ]); + +memcpy (error_ecc, correct_ecc,3 ); +__change_bit_le (offset[0 ], error_ecc); +__change_bit_le (offset[1 ], error_ecc); +} +static void no_bit_error (void *error_data,void *error_ecc,void *correct_data,void *correct_ecc,const size_t size) {
@@ -107,6 +138,40 @@ static int single_bit_error_correct(void *error_data, void *error_ecc,return -EINVAL ; } +static void double_bit_error_in_data (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +double_bit_error_data (error_data, correct_data, size); +memcpy (error_ecc, correct_ecc,3 ); +} + +static void single_bit_error_in_data_and_ecc (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +single_bit_error_data (error_data, correct_data, size); +single_bit_error_ecc (error_ecc, correct_ecc, size); +} + +static void double_bit_error_in_ecc (void *error_data,void *error_ecc, +void *correct_data,void *correct_ecc,const size_t size) +{ +memcpy (error_data, correct_data, size); +double_bit_error_ecc (error_ecc, correct_ecc, size); +} + +static int double_bit_error_detect (void *error_data,void *error_ecc, +void *correct_data,const size_t size) + +{ +unsigned char calc_ecc[3 ]; +int ret; + +__nand_calculate_ecc (error_data, size, calc_ecc); + ret =__nand_correct_data (error_data, calc_ecc, error_ecc, size); + +return (ret ==-1 ) ?0 : -EINVAL ; +} +static const struct nand_ecc_test nand_ecc_test[] = { { .name ="no-bit-error" ,
@@ -123,6 +188,21 @@ static const struct nand_ecc_test nand_ecc_test[] = { .prepare = single_bit_error_in_ecc, .verify = single_bit_error_correct, }, + { + .name = "double-bit-error-in-data-detect", + .prepare = double_bit_error_in_data, + .verify = double_bit_error_detect, + }, + { + .name = "single-bit-error-in-data-and-ecc-detect", + .prepare = single_bit_error_in_data_and_ecc, + .verify = double_bit_error_detect, + }, + { + .name = "double-bit-error-in-ecc-detect", + .prepare = double_bit_error_in_ecc, + .verify = double_bit_error_detect, + }, }; static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data,
Signature · 1 line
1.7.11.4
Quoted 2 lines · Akinobu Mita
This patch series adds several tests cases to
mtd_nandecctestmodule and includes several minor changes.
I've pushed patches 3-6 to the l2-mtd.git, thanks! Please, do not re-send patches 1-6 since I already have them, and David will find them in my tree.
Signature · 2 lines
Best Regards, Artem Bityutskiy