Patchwork [2/2] mtd: torturetest: add the support for random data pattern

login
register
mail settings
Submitter Huang Shijie
Date Feb. 5, 2013, 2:20 a.m.
Message ID <1360030820-21491-2-git-send-email-b32955@freescale.com>
Download mbox | patch
Permalink /patch/218142/
State New
Headers show

Comments

Huang Shijie - Feb. 5, 2013, 2:20 a.m.
Add a new module parameter 'pattern'. If it is set to zero,
we will use the 55/AA pattern to torture the nand blocks; if it is set
to a non-zero value, we will use the random data pattern.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 drivers/mtd/tests/mtd_torturetest.c |   72 ++++++++++++++++++++++++-----------
 1 files changed, 50 insertions(+), 22 deletions(-)
Ricard Wanderlof - Feb. 5, 2013, 8:05 a.m.
On Tue, 5 Feb 2013, Huang Shijie wrote:

> Add a new module parameter 'pattern'. If it is set to zero, we will use 
> the 55/AA pattern to torture the nand blocks; if it is set to a non-zero 
> value, we will use the random data pattern.

Not a big issue in any way, but if you're using a numeric parameter value 
anyway, could not one use a range of the permissable values to set a seed 
for the random generation, so that the test can be repeated with the same 
set of random numbers?

Something like

0 => 55/AA
-1 => random
1 and up => random, specifying seed for random number generator.

> +MODULE_PARM_DESC(pattern, "0 for 55/AA pattern(default), else for
> +				the random pattern");

I'd suggest something like "0 for 55/AA pattern (default), non-zero for 
random pattern".

(Or "-1 for 55/AA pattern (default), else random; >=1 sets seed" if 
changed according to the above).

/Ricard
Huang Shijie - Feb. 5, 2013, 8:21 a.m.
于 2013年02月05日 16:05, Ricard Wanderlof 写道:
>
> On Tue, 5 Feb 2013, Huang Shijie wrote:
>
>> Add a new module parameter 'pattern'. If it is set to zero, we will 
>> use the 55/AA pattern to torture the nand blocks; if it is set to a 
>> non-zero value, we will use the random data pattern.
>
> Not a big issue in any way, but if you're using a numeric parameter 
> value anyway, could not one use a range of the permissable values to 
> set a seed for the random generation, so that the test can be repeated 
> with the same set of random numbers?
It's ok to provide a seed to the mtd_torturetest.


>
> Something like
>
> 0 => 55/AA
> -1 => random
> 1 and up => random, specifying seed for random number generator.
>
I will add it in next version.

thanks for your review.

Huang Shijie

Patch

diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 516cf66..07655bc 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -32,6 +32,7 @@ 
 #include <linux/mtd/mtd.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/random.h>
 
 #define RETRIES 3
 
@@ -64,6 +65,11 @@  module_param(cycles_count, uint, S_IRUGO);
 MODULE_PARM_DESC(cycles_count, "how many erase cycles to do "
 			       "(infinite by default)");
 
+static int pattern;
+module_param(pattern, int, S_IRUGO);
+MODULE_PARM_DESC(pattern, "0 for 55/AA pattern(default), else for
+				the random pattern");
+
 static struct mtd_info *mtd;
 
 /* This buffer contains 0x555555...0xAAAAAA... pattern */
@@ -72,6 +78,8 @@  static unsigned char *patt_5A5;
 static unsigned char *patt_A5A;
 /* This buffer contains all 0xFF bytes */
 static unsigned char *patt_FF;
+/* This buffer contains the random data. */
+static unsigned char *patt_rd;
 /* This a temporary buffer is use when checking data */
 static unsigned char *check_buf;
 /* How many erase cycles were done */
@@ -228,6 +236,8 @@  static int __init tort_init(void)
 		pr_info("torturing just %d pages per eraseblock\n",
 			pgcnt);
 	pr_info("write verify %s\n", check ? "enabled" : "disabled");
+	pr_info("Test pattern is %s\n",
+			pattern ? "random data pattern" : "55/AA pattern");
 
 	mtd = get_mtd_device(NULL, dev);
 	if (IS_ERR(mtd)) {
@@ -249,16 +259,24 @@  static int __init tort_init(void)
 	}
 
 	err = -ENOMEM;
-	patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL);
-	if (!patt_5A5) {
-		pr_err("error: cannot allocate memory\n");
-		goto out_mtd;
-	}
+	if (!pattern) {
+		patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL);
+		if (!patt_5A5) {
+			pr_err("error: cannot allocate memory\n");
+			goto out_mtd;
+		}
 
-	patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL);
-	if (!patt_A5A) {
-		pr_err("error: cannot allocate memory\n");
-		goto out_patt_5A5;
+		patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL);
+		if (!patt_A5A) {
+			pr_err("error: cannot allocate memory\n");
+			goto out_patt_5A5;
+		}
+	} else {
+		patt_rd = kmalloc(mtd->erasesize, GFP_KERNEL);
+		if (!patt_rd) {
+			pr_err("error: cannot allocate memory\n");
+			goto out_patt_rd;
+		}
 	}
 
 	patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL);
@@ -277,13 +295,15 @@  static int __init tort_init(void)
 
 	/* Initialize patterns */
 	memset(patt_FF, 0xFF, mtd->erasesize);
-	for (i = 0; i < mtd->erasesize / pgsize; i++) {
-		if (!(i & 1)) {
-			memset(patt_5A5 + i * pgsize, 0x55, pgsize);
-			memset(patt_A5A + i * pgsize, 0xAA, pgsize);
-		} else {
-			memset(patt_5A5 + i * pgsize, 0xAA, pgsize);
-			memset(patt_A5A + i * pgsize, 0x55, pgsize);
+	if (!pattern) {
+		for (i = 0; i < mtd->erasesize / pgsize; i++) {
+			if (!(i & 1)) {
+				memset(patt_5A5 + i * pgsize, 0x55, pgsize);
+				memset(patt_A5A + i * pgsize, 0xAA, pgsize);
+			} else {
+				memset(patt_5A5 + i * pgsize, 0xAA, pgsize);
+				memset(patt_A5A + i * pgsize, 0x55, pgsize);
+			}
 		}
 	}
 
@@ -335,10 +355,15 @@  static int __init tort_init(void)
 			}
 
 			/* Write the pattern */
-			if ((eb + erase_cycles) & 1)
-				patt = patt_5A5;
-			else
-				patt = patt_A5A;
+			if (!pattern) {
+				if ((eb + erase_cycles) & 1)
+					patt = patt_5A5;
+				else
+					patt = patt_A5A;
+			} else {
+				patt = patt_rd;
+				prandom_bytes(patt, mtd->erasesize);
+			}
 			err = write_pattern(i, patt);
 			if (err)
 				goto out;
@@ -350,8 +375,9 @@  static int __init tort_init(void)
 				if (err) {
 					pr_info("verify failed for %s"
 					       " pattern\n",
-					       ((eb + erase_cycles) & 1) ?
-					       "0x55AA55..." : "0xAA55AA...");
+					       pattern ? "random pattern" :
+					       (((eb + erase_cycles) & 1) ?
+					       "0x55AA55..." : "0xAA55AA..."));
 					goto out;
 				}
 				cond_resched();
@@ -386,6 +412,8 @@  out_patt_A5A:
 	kfree(patt_A5A);
 out_patt_5A5:
 	kfree(patt_5A5);
+out_patt_rd:
+	kfree(patt_rd);
 out_mtd:
 	put_mtd_device(mtd);
 	if (err)