From: Huang Shijie <b32955@freescale.com>
To: <dwmw2@infradead.org>
Cc: ricard.wanderlof@axis.com, Huang Shijie <b32955@freescale.com>,
linux-mtd@lists.infradead.org, dedekind1@gmail.com
Subject: [PATCH v2] mtd: torturetest: add the support for random data pattern
Date: Tue, 5 Feb 2013 16:21:25 +0800 [thread overview]
Message-ID: <1360052485-11961-1-git-send-email-b32955@freescale.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1302050900010.3736@lnxricardw.se.axis.com>
Add a new module parameter 'pattern'. The meaning of the pattern is:
(1) pattern == 0 for 55/AA pattern.
(2) pattern < 0 for random pattern.
(3) pattern > 0 for random pattern too, the value of the pattern is used
as the seed for the random generator.
Signed-off-by: Huang Shijie <b32955@freescale.com>
---
v1 --> v2:
add the seed support.
---
drivers/mtd/tests/mtd_torturetest.c | 82 +++++++++++++++++++++++++---------
1 files changed, 60 insertions(+), 22 deletions(-)
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 516cf66..5481c99 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,13 @@ 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);"
+ "less then 0 for random pattern;"
+ "greater then 0 for random too, "
+ "the value of the pattern is the seed.");
+
static struct mtd_info *mtd;
/* This buffer contains 0x555555...0xAAAAAA... pattern */
@@ -72,6 +80,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 +238,12 @@ 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");
+ if (pattern == 0)
+ pr_info("Test pattern is 55/AA.\n");
+ else if (pattern < 0)
+ pr_info("Test pattern is random.\n");
+ else
+ pr_info("Test pattern is random, seed is 0x%d.\n", pattern);
mtd = get_mtd_device(NULL, dev);
if (IS_ERR(mtd)) {
@@ -249,16 +265,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,14 +301,20 @@ 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);
+ }
}
+ } else {
+ /* set the seed. */
+ if (pattern > 0)
+ prandom_seed(pattern);
}
/*
@@ -335,10 +365,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 +385,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 +422,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)
--
1.7.0.4
next prev parent reply other threads:[~2013-02-05 9:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-05 2:20 [PATCH 1/2] mtd: torturetest: rewrite the erase-write-verify process into one block unit Huang Shijie
2013-02-05 2:20 ` [PATCH 2/2] mtd: torturetest: add the support for random data pattern Huang Shijie
2013-02-05 8:05 ` Ricard Wanderlof
2013-02-05 8:21 ` Huang Shijie [this message]
2013-02-05 9:48 ` [PATCH v2] " Ricard Wanderlof
2013-02-05 10:01 ` Huang Shijie
2013-02-13 10:37 ` Artem Bityutskiy
2013-02-16 4:00 ` Huang Shijie
2013-03-02 14:44 ` Artem Bityutskiy
2013-03-04 2:29 ` Huang Shijie
2013-02-05 8:21 ` [PATCH 2/2] " Huang Shijie
2013-02-05 8:30 ` [PATCH V3] " Huang Shijie
2013-02-05 9:06 ` [PATCH v4] " Huang Shijie
2013-02-13 11:26 ` Ezequiel Garcia
2013-02-16 4:01 ` Huang Shijie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360052485-11961-1-git-send-email-b32955@freescale.com \
--to=b32955@freescale.com \
--cc=dedekind1@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=ricard.wanderlof@axis.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox