Skip to contentSkip to conversation

mtd: tests: reduce duplication among mtd tests modules

PATCH Superseded Akinobu Mita 4 participants 15 messages Jul 27, 2013 – Aug 3, 2013 Memory technology devices (MTD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mtd: tests: reduce duplication among mtd tests modules

This patch set reduces code duplication among mtd/tests modules by moving common helper functions into mtd_test module.

Akinobu Mita (7):
mtd: tests: introduce mtd_test module
mtd: mtd_oobtest: use mtd_test module
mtd: mtd_pagetest: use mtd_test module
mtd: mtd_readtest: use mtd_test module
mtd: mtd_speedtest: use mtd_test module
mtd: mtd_stresstest: use mtd_test module
mtd: mtd_subpagetest: use mtd_test module

 drivers/mtd/tests/Makefile          |   1 +
 drivers/mtd/tests/mtd_oobtest.c     |  92 +++--------------
 drivers/mtd/tests/mtd_pagetest.c    | 199 ++++++++++--------------------------
 drivers/mtd/tests/mtd_readtest.c    |  51 ++-------
 drivers/mtd/tests/mtd_speedtest.c   | 180 +++++++-------------------------
 drivers/mtd/tests/mtd_stresstest.c  |  86 +++-------------
 drivers/mtd/tests/mtd_subpagetest.c |  87 ++--------------
 drivers/mtd/tests/mtd_test.c        | 117 +++++++++++++++++++++
 drivers/mtd/tests/mtd_test.h        |  11 ++
 9 files changed, 262 insertions(+), 562 deletions(-)
 create mode 100644 drivers/mtd/tests/mtd_test.c
 create mode 100644 drivers/mtd/tests/mtd_test.h
Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/7 mtd: tests: introduce mtd_test module

This introduces mtd_test module which contains the following functions used by several mtd/tests modules.

- mtdtest_erase_eraseblock()
- mtdtest_scan_for_bad_eraseblocks()
- mtdtest_erase_whole_device()

This mtd_test module also provides the following wrapper functions for mtd_read() and mtd_write() in order to simplify the return value check in mtd/tests modules.

- mtdtest_read()
- mtdtest_write()

These functions will be used for reducing code duplication among mtd/tests modules later.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/Makefile   |   1 +
 drivers/mtd/tests/mtd_test.c | 117 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/tests/mtd_test.h |  11 ++++
 3 files changed, 129 insertions(+)
 create mode 100644 drivers/mtd/tests/mtd_test.c
 create mode 100644 drivers/mtd/tests/mtd_test.h
drivers/mtd/tests/Makefile +1 -0
index bd0065c..3d642f4 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_MTD_TESTS) += mtd_test.o
 obj-$(CONFIG_MTD_TESTS) += mtd_oobtest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_pagetest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_readtest.o
drivers/mtd/tests/mtd_test.c new file +117 -0

117 lines not on this page · raw message

drivers/mtd/tests/mtd_test.h new file +11 -0
new file mode 100644
index 0000000..e61fb67
@@ -0,0 +1,11 @@
+#include <linux/mtd/mtd.h>
+
+int mtdtest_erase_eraseblock(struct mtd_info *mtd, int ebnum);
+int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt,
+					int ebcnt);
+int mtdtest_erase_whole_device(struct mtd_info *mtd, unsigned char *bbt,
+				int ebcnt);
+
+int mtdtest_read(struct mtd_info *mtd, loff_t addr, size_t size, void *buf);
+int mtdtest_write(struct mtd_info *mtd, loff_t addr, size_t size,
+		const void *buf);
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 2/7 mtd: mtd_oobtest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_scan_for_bad_eraseblocks(), mtdtest_erase_whole_device(), and mtdtest_erase_eraseblock() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_oobtest.c | 92 ++++++-----------------------------------
 1 file changed, 12 insertions(+), 80 deletions(-)
drivers/mtd/tests/mtd_oobtest.c +12 -80
index ab81e9a..8d5e35c 100644
@@ -31,6 +31,8 @@
 #include <linux/sched.h>
 #include <linux/random.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -49,49 +51,6 @@ static int use_len_max;
 static int vary_offset;
 static struct rnd_state rnd_state;
 
-static int erase_eraseblock(int ebnum)
-{
-	int err;
-	struct erase_info ei;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	memset(&ei, 0, sizeof(struct erase_info));
-	ei.mtd  = mtd;
-	ei.addr = addr;
-	ei.len  = mtd->erasesize;
-
-	err = mtd_erase(mtd, &ei);
-	if (err) {
-		pr_err("error %d while erasing EB %d\n", err, ebnum);
-		return err;
-	}
-
-	if (ei.state == MTD_ERASE_FAILED) {
-		pr_err("some erase error occurred at EB %d\n", ebnum);
-		return -EIO;
-	}
-
-	return 0;
-}
-
-static int erase_whole_device(void)
-{
-	int err;
-	unsigned int i;
-
-	pr_info("erasing whole device\n");
-	for (i = 0; i < ebcnt; ++i) {
-		if (bbt[i])
-			continue;
-		err = erase_eraseblock(i);
-		if (err)
-			return err;
-		cond_resched();
-	}
-	pr_info("erased %u eraseblocks\n", i);
-	return 0;
-}
-
 static void do_vary_offset(void)
 {
 	use_len -= 1;
@@ -304,36 +263,6 @@ static int verify_all_eraseblocks(void)
 	return 0;
 }
 
-static int is_block_bad(int ebnum)
-{
-	int ret;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kmalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-	return 0;
-}
-
 static int __init mtd_oobtest_init(void)
 {
 	int err = 0;
@@ -383,8 +312,11 @@ static int __init mtd_oobtest_init(void)
 	writebuf = kmalloc(mtd->erasesize, GFP_KERNEL);
 	if (!writebuf)
 		goto out;
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
 
-	err = scan_for_bad_eraseblocks();
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -396,7 +328,7 @@ static int __init mtd_oobtest_init(void)
 	/* First test: write all OOB, read it back and verify */
 	pr_info("test 1 of 5\n");
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -416,7 +348,7 @@ static int __init mtd_oobtest_init(void)
 	 */
 	pr_info("test 2 of 5\n");
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -446,7 +378,7 @@ static int __init mtd_oobtest_init(void)
 	 */
 	pr_info("test 3 of 5\n");
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -479,7 +411,7 @@ static int __init mtd_oobtest_init(void)
 	/* Fourth test: try to write off end of device */
 	pr_info("test 4 of 5\n");
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -571,7 +503,7 @@ static int __init mtd_oobtest_init(void)
 			errcnt += 1;
 		}
 
-		err = erase_eraseblock(ebcnt - 1);
+		err = mtdtest_erase_eraseblock(mtd, ebcnt - 1);
 		if (err)
 			goto out;
 
@@ -620,7 +552,7 @@ static int __init mtd_oobtest_init(void)
 	pr_info("test 5 of 5\n");
 
 	/* Erase all eraseblocks */
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 4/7 mtd: mtd_readtest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_read() and mtdtest_scan_for_bad_eraseblocks() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_readtest.c | 51 +++++++---------------------------------
 1 file changed, 9 insertions(+), 42 deletions(-)
drivers/mtd/tests/mtd_readtest.c +9 -42
index 2cdd0c4..bb30773 100644
@@ -29,6 +29,8 @@
 #include <linux/slab.h>
 #include <linux/sched.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -44,24 +46,19 @@ static int pgcnt;
 
 static int read_eraseblock_by_page(int ebnum)
 {
-	size_t read;
 	int i, ret, err = 0;
 	loff_t addr = ebnum * mtd->erasesize;
 	void *buf = iobuf;
 	void *oobbuf = iobuf1;
 
 	for (i = 0; i < pgcnt; i++) {
-		memset(buf, 0 , pgsize);
-		ret = mtd_read(mtd, addr, pgsize, &read, buf);
-		if (ret == -EUCLEAN)
-			ret = 0;
-		if (ret || read != pgsize) {
+		memset(buf, 0 , pgcnt);
+		ret = mtdtest_read(mtd, addr, pgsize, buf);
+		if (ret) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)addr);
 			if (!err)
 				err = ret;
-			if (!err)
-				err = -EINVAL;
 		}
 		if (mtd->oobsize) {
 			struct mtd_oob_ops ops;
@@ -127,39 +124,6 @@ static void dump_eraseblock(int ebnum)
 		}
 }
 
-static int is_block_bad(int ebnum)
-{
-	loff_t addr = ebnum * mtd->erasesize;
-	int ret;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kzalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	if (!mtd_can_have_bb(mtd))
-		return 0;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-	return 0;
-}
-
 static int __init mtd_readtest_init(void)
 {
 	uint64_t tmp;
@@ -208,7 +172,10 @@ static int __init mtd_readtest_init(void)
 	if (!iobuf1)
 		goto out;
 
-	err = scan_for_bad_eraseblocks();
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH 6/7 mtd: mtd_stresstest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_read(), mtdtest_write(), mtdtest_erase_eraseblock(), and mtdtest_scan_for_bad_eraseblocks() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_stresstest.c | 86 ++++++--------------------------------
 1 file changed, 12 insertions(+), 74 deletions(-)
drivers/mtd/tests/mtd_stresstest.c +12 -74
index 3a95e61..1e075bf 100644
@@ -31,6 +31,8 @@
 #include <linux/vmalloc.h>
 #include <linux/random.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -81,46 +83,8 @@ static int rand_len(int offs)
 	return len;
 }
 
-static int erase_eraseblock(int ebnum)
-{
-	int err;
-	struct erase_info ei;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	memset(&ei, 0, sizeof(struct erase_info));
-	ei.mtd  = mtd;
-	ei.addr = addr;
-	ei.len  = mtd->erasesize;
-
-	err = mtd_erase(mtd, &ei);
-	if (unlikely(err)) {
-		pr_err("error %d while erasing EB %d\n", err, ebnum);
-		return err;
-	}
-
-	if (unlikely(ei.state == MTD_ERASE_FAILED)) {
-		pr_err("some erase error occurred at EB %d\n",
-		       ebnum);
-		return -EIO;
-	}
-
-	return 0;
-}
-
-static int is_block_bad(int ebnum)
-{
-	loff_t addr = ebnum * mtd->erasesize;
-	int ret;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
 static int do_read(void)
 {
-	size_t read;
 	int eb = rand_eb();
 	int offs = rand_offs();
 	int len = rand_len(offs), err;
@@ -133,14 +97,10 @@ static int do_read(void)
 			len = mtd->erasesize - offs;
 	}
 	addr = eb * mtd->erasesize + offs;
-	err = mtd_read(mtd, addr, len, &read, readbuf);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (unlikely(err || read != len)) {
+	err = mtdtest_read(mtd, addr, len, readbuf);
+	if (unlikely(err)) {
 		pr_err("error: read failed at 0x%llx\n",
 		       (long long)addr);
-		if (!err)
-			err = -EINVAL;
 		return err;
 	}
 	return 0;
@@ -149,12 +109,11 @@ static int do_read(void)
 static int do_write(void)
 {
 	int eb = rand_eb(), offs, err, len;
-	size_t written;
 	loff_t addr;
 
 	offs = offsets[eb];
 	if (offs >= mtd->erasesize) {
-		err = erase_eraseblock(eb);
+		err = mtdtest_erase_eraseblock(mtd, eb);
 		if (err)
 			return err;
 		offs = offsets[eb] = 0;
@@ -165,19 +124,17 @@ static int do_write(void)
 		if (bbt[eb + 1])
 			len = mtd->erasesize - offs;
 		else {
-			err = erase_eraseblock(eb + 1);
+			err = mtdtest_erase_eraseblock(mtd, eb + 1);
 			if (err)
 				return err;
 			offsets[eb + 1] = 0;
 		}
 	}
 	addr = eb * mtd->erasesize + offs;
-	err = mtd_write(mtd, addr, len, &written, writebuf);
-	if (unlikely(err || written != len)) {
+	err = mtdtest_write(mtd, addr, len, writebuf);
+	if (unlikely(err)) {
 		pr_err("error: write failed at 0x%llx\n",
 		       (long long)addr);
-		if (!err)
-			err = -EINVAL;
 		return err;
 	}
 	offs += len;
@@ -197,28 +154,6 @@ static int do_operation(void)
 		return do_write();
 }
 
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kzalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	if (!mtd_can_have_bb(mtd))
-		return 0;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-	return 0;
-}
-
 static int __init mtd_stresstest_init(void)
 {
 	int err;
@@ -280,7 +215,10 @@ static int __init mtd_stresstest_init(void)
 		offsets[i] = mtd->erasesize;
 	prandom_bytes(writebuf, bufsize);
 
-	err = scan_for_bad_eraseblocks();
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 3/7 mtd: mtd_pagetest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_write(), mtdtest_read(), mtdtest_erase_eraseblock(), mtdtest_scan_for_bad_eraseblocks(), and mtdtest_erase_whole_device() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_pagetest.c | 199 +++++++++++----------------------------
 1 file changed, 55 insertions(+), 144 deletions(-)
drivers/mtd/tests/mtd_pagetest.c +55 -144
index acd991f..87a8ee9 100644
@@ -31,6 +31,8 @@
 #include <linux/sched.h>
 #include <linux/random.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -48,42 +50,15 @@ static int pgcnt;
 static int errcnt;
 static struct rnd_state rnd_state;
 
-static int erase_eraseblock(int ebnum)
-{
-	int err;
-	struct erase_info ei;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	memset(&ei, 0, sizeof(struct erase_info));
-	ei.mtd  = mtd;
-	ei.addr = addr;
-	ei.len  = mtd->erasesize;
-
-	err = mtd_erase(mtd, &ei);
-	if (err) {
-		pr_err("error %d while erasing EB %d\n", err, ebnum);
-		return err;
-	}
-
-	if (ei.state == MTD_ERASE_FAILED) {
-		pr_err("some erase error occurred at EB %d\n",
-		       ebnum);
-		return -EIO;
-	}
-
-	return 0;
-}
-
 static int write_eraseblock(int ebnum)
 {
-	int err = 0;
-	size_t written;
+	int err;
 	loff_t addr = ebnum * mtd->erasesize;
 
 	prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
 	cond_resched();
-	err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf);
-	if (err || written != mtd->erasesize)
+	err = mtdtest_write(mtd, addr, mtd->erasesize, writebuf);
+	if (err)
 		pr_err("error: write failed at %#llx\n",
 		       (long long)addr);
 
@@ -93,7 +68,6 @@ static int write_eraseblock(int ebnum)
 static int verify_eraseblock(int ebnum)
 {
 	uint32_t j;
-	size_t read;
 	int err = 0, i;
 	loff_t addr0, addrn;
 	loff_t addr = ebnum * mtd->erasesize;
@@ -109,27 +83,21 @@ static int verify_eraseblock(int ebnum)
 	prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
 	for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
 		/* Do a read to set the internal dataRAMs to different data */
-		err = mtd_read(mtd, addr0, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addr0, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)addr0);
 			return err;
 		}
-		err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)(addrn - bufsize));
 			return err;
 		}
 		memset(twopages, 0, bufsize);
-		err = mtd_read(mtd, addr, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addr, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)addr);
 			break;
@@ -145,27 +113,21 @@ static int verify_eraseblock(int ebnum)
 		struct rnd_state old_state = rnd_state;
 
 		/* Do a read to set the internal dataRAMs to different data */
-		err = mtd_read(mtd, addr0, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addr0, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)addr0);
 			return err;
 		}
-		err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)(addrn - bufsize));
 			return err;
 		}
 		memset(twopages, 0, bufsize);
-		err = mtd_read(mtd, addr, bufsize, &read, twopages);
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != bufsize) {
+		err = mtdtest_read(mtd, addr, bufsize, twopages);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       (long long)addr);
 			return err;
@@ -184,7 +146,6 @@ static int verify_eraseblock(int ebnum)
 
 static int crosstest(void)
 {
-	size_t read;
 	int err = 0, i;
 	loff_t addr, addr0, addrn;
 	unsigned char *pp1, *pp2, *pp3, *pp4;
@@ -208,10 +169,8 @@ static int crosstest(void)
 
 	/* Read 2nd-to-last page to pp1 */
 	addr = addrn - pgsize - pgsize;
-	err = mtd_read(mtd, addr, pgsize, &read, pp1);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr, pgsize, pp1);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr);
 		kfree(pp1);
@@ -220,10 +179,8 @@ static int crosstest(void)
 
 	/* Read 3rd-to-last page to pp1 */
 	addr = addrn - pgsize - pgsize - pgsize;
-	err = mtd_read(mtd, addr, pgsize, &read, pp1);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr, pgsize, pp1);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr);
 		kfree(pp1);
@@ -233,10 +190,8 @@ static int crosstest(void)
 	/* Read first page to pp2 */
 	addr = addr0;
 	pr_info("reading page at %#llx\n", (long long)addr);
-	err = mtd_read(mtd, addr, pgsize, &read, pp2);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr, pgsize, pp2);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr);
 		kfree(pp1);
@@ -246,10 +201,8 @@ static int crosstest(void)
 	/* Read last page to pp3 */
 	addr = addrn - pgsize;
 	pr_info("reading page at %#llx\n", (long long)addr);
-	err = mtd_read(mtd, addr, pgsize, &read, pp3);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr, pgsize, pp3);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr);
 		kfree(pp1);
@@ -259,10 +212,8 @@ static int crosstest(void)
 	/* Read first page again to pp4 */
 	addr = addr0;
 	pr_info("reading page at %#llx\n", (long long)addr);
-	err = mtd_read(mtd, addr, pgsize, &read, pp4);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr, pgsize, pp4);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr);
 		kfree(pp1);
@@ -283,7 +234,6 @@ static int crosstest(void)
 
 static int erasecrosstest(void)
 {
-	size_t read, written;
 	int err = 0, i, ebnum, ebnum2;
 	loff_t addr0;
 	char *readbuf = twopages;
@@ -302,26 +252,24 @@ static int erasecrosstest(void)
 		ebnum2 -= 1;
 
 	pr_info("erasing block %d\n", ebnum);
-	err = erase_eraseblock(ebnum);
+	err = mtdtest_erase_eraseblock(mtd, ebnum);
 	if (err)
 		return err;
 
 	pr_info("writing 1st page of block %d\n", ebnum);
 	prandom_bytes_state(&rnd_state, writebuf, pgsize);
 	strcpy(writebuf, "There is no data like this!");
-	err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
-	if (err || written != pgsize) {
+	err = mtdtest_write(mtd, addr0, pgsize, writebuf);
+	if (err) {
 		pr_info("error: write failed at %#llx\n",
 		       (long long)addr0);
-		return err ? err : -1;
+		return err;
 	}
 
 	pr_info("reading 1st page of block %d\n", ebnum);
 	memset(readbuf, 0, pgsize);
-	err = mtd_read(mtd, addr0, pgsize, &read, readbuf);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr0, pgsize, readbuf);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr0);
 		return err ? err : -1;
@@ -335,31 +283,29 @@ static int erasecrosstest(void)
 	}
 
 	pr_info("erasing block %d\n", ebnum);
-	err = erase_eraseblock(ebnum);
+	err = mtdtest_erase_eraseblock(mtd, ebnum);
 	if (err)
 		return err;
 
 	pr_info("writing 1st page of block %d\n", ebnum);
 	prandom_bytes_state(&rnd_state, writebuf, pgsize);
 	strcpy(writebuf, "There is no data like this!");
-	err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
-	if (err || written != pgsize) {
+	err = mtdtest_write(mtd, addr0, pgsize, writebuf);
+	if (err) {
 		pr_err("error: write failed at %#llx\n",
 		       (long long)addr0);
-		return err ? err : -1;
+		return err;
 	}
 
 	pr_info("erasing block %d\n", ebnum2);
-	err = erase_eraseblock(ebnum2);
+	err = mtdtest_erase_eraseblock(mtd, ebnum2);
 	if (err)
 		return err;
 
 	pr_info("reading 1st page of block %d\n", ebnum);
 	memset(readbuf, 0, pgsize);
-	err = mtd_read(mtd, addr0, pgsize, &read, readbuf);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr0, pgsize, readbuf);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr0);
 		return err ? err : -1;
@@ -379,7 +325,6 @@ static int erasecrosstest(void)
 
 static int erasetest(void)
 {
-	size_t read, written;
 	int err = 0, i, ebnum, ok = 1;
 	loff_t addr0;
 
@@ -393,29 +338,27 @@ static int erasetest(void)
 	}
 
 	pr_info("erasing block %d\n", ebnum);
-	err = erase_eraseblock(ebnum);
+	err = mtdtest_erase_eraseblock(mtd, ebnum);
 	if (err)
 		return err;
 
 	pr_info("writing 1st page of block %d\n", ebnum);
 	prandom_bytes_state(&rnd_state, writebuf, pgsize);
-	err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
-	if (err || written != pgsize) {
+	err = mtdtest_write(mtd, addr0, pgsize, writebuf);
+	if (err) {
 		pr_err("error: write failed at %#llx\n",
 		       (long long)addr0);
-		return err ? err : -1;
+		return err;
 	}
 
 	pr_info("erasing block %d\n", ebnum);
-	err = erase_eraseblock(ebnum);
+	err = mtdtest_erase_eraseblock(mtd, ebnum);
 	if (err)
 		return err;
 
 	pr_info("reading 1st page of block %d\n", ebnum);
-	err = mtd_read(mtd, addr0, pgsize, &read, twopages);
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != pgsize) {
+	err = mtdtest_read(mtd, addr0, pgsize, twopages);
+	if (err) {
 		pr_err("error: read failed at %#llx\n",
 		       (long long)addr0);
 		return err ? err : -1;
@@ -438,36 +381,6 @@ static int erasetest(void)
 	return err;
 }
 
-static int is_block_bad(int ebnum)
-{
-	loff_t addr = ebnum * mtd->erasesize;
-	int ret;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kzalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-	return 0;
-}
-
 static int __init mtd_pagetest_init(void)
 {
 	int err = 0;
@@ -521,21 +434,19 @@ static int __init mtd_pagetest_init(void)
 	if (!boundary)
 		goto out;
 
-	err = scan_for_bad_eraseblocks();
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
 	/* Erase all eraseblocks */
 	pr_info("erasing whole device\n");
-	for (i = 0; i < ebcnt; ++i) {
-		if (bbt[i])
-			continue;
-		err = erase_eraseblock(i);
-		if (err)
-			goto out;
-		cond_resched();
-	}
-	pr_info("erased %u eraseblocks\n", i);
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
+	if (err)
+		goto out;
+	pr_info("erased %u eraseblocks\n", ebcnt);
 
 	/* Write all eraseblocks */
 	prandom_seed_state(&rnd_state, 1);
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 5/7 mtd: mtd_speedtest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_write(), mtdtest_read(), mtdtest_scan_for_bad_eraseblocks(), mtdtest_erase_whole_device() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_speedtest.c | 180 ++++++++------------------------------
 1 file changed, 36 insertions(+), 144 deletions(-)
drivers/mtd/tests/mtd_speedtest.c +36 -144
index 20b63d1..77ed5ba 100644
@@ -30,6 +30,8 @@
 #include <linux/sched.h>
 #include <linux/random.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -49,33 +51,6 @@ static int pgcnt;
 static int goodebcnt;
 static struct timeval start, finish;
 
-
-static int erase_eraseblock(int ebnum)
-{
-	int err;
-	struct erase_info ei;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	memset(&ei, 0, sizeof(struct erase_info));
-	ei.mtd  = mtd;
-	ei.addr = addr;
-	ei.len  = mtd->erasesize;
-
-	err = mtd_erase(mtd, &ei);
-	if (err) {
-		pr_err("error %d while erasing EB %d\n", err, ebnum);
-		return err;
-	}
-
-	if (ei.state == MTD_ERASE_FAILED) {
-		pr_err("some erase error occurred at EB %d\n",
-		       ebnum);
-		return -EIO;
-	}
-
-	return 0;
-}
-
 static int multiblock_erase(int ebnum, int blocks)
 {
 	int err;
@@ -103,52 +78,29 @@ static int multiblock_erase(int ebnum, int blocks)
 	return 0;
 }
 
-static int erase_whole_device(void)
-{
-	int err;
-	unsigned int i;
-
-	for (i = 0; i < ebcnt; ++i) {
-		if (bbt[i])
-			continue;
-		err = erase_eraseblock(i);
-		if (err)
-			return err;
-		cond_resched();
-	}
-	return 0;
-}
-
 static int write_eraseblock(int ebnum)
 {
-	size_t written;
-	int err = 0;
+	int err;
 	loff_t addr = ebnum * mtd->erasesize;
 
-	err = mtd_write(mtd, addr, mtd->erasesize, &written, iobuf);
-	if (err || written != mtd->erasesize) {
+	err = mtdtest_write(mtd, addr, mtd->erasesize, iobuf);
+	if (err)
 		pr_err("error: write failed at %#llx\n", addr);
-		if (!err)
-			err = -EINVAL;
-	}
 
 	return err;
 }
 
 static int write_eraseblock_by_page(int ebnum)
 {
-	size_t written;
 	int i, err = 0;
 	loff_t addr = ebnum * mtd->erasesize;
 	void *buf = iobuf;
 
 	for (i = 0; i < pgcnt; i++) {
-		err = mtd_write(mtd, addr, pgsize, &written, buf);
-		if (err || written != pgsize) {
+		err = mtdtest_write(mtd, addr, pgsize, buf);
+		if (err) {
 			pr_err("error: write failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 			break;
 		}
 		addr += pgsize;
@@ -160,30 +112,26 @@ static int write_eraseblock_by_page(int ebnum)
 
 static int write_eraseblock_by_2pages(int ebnum)
 {
-	size_t written, sz = pgsize * 2;
+	size_t sz = pgsize * 2;
 	int i, n = pgcnt / 2, err = 0;
 	loff_t addr = ebnum * mtd->erasesize;
 	void *buf = iobuf;
 
 	for (i = 0; i < n; i++) {
-		err = mtd_write(mtd, addr, sz, &written, buf);
-		if (err || written != sz) {
+		err = mtdtest_write(mtd, addr, sz, buf);
+		if (err) {
 			pr_err("error: write failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 			return err;
 		}
 		addr += sz;
 		buf += sz;
 	}
 	if (pgcnt % 2) {
-		err = mtd_write(mtd, addr, pgsize, &written, buf);
-		if (err || written != pgsize) {
+		err = mtdtest_write(mtd, addr, pgsize, buf);
+		if (err) {
 			pr_err("error: write failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 		}
 	}
 
@@ -192,40 +140,27 @@ static int write_eraseblock_by_2pages(int ebnum)
 
 static int read_eraseblock(int ebnum)
 {
-	size_t read;
-	int err = 0;
+	int err;
 	loff_t addr = ebnum * mtd->erasesize;
 
-	err = mtd_read(mtd, addr, mtd->erasesize, &read, iobuf);
-	/* Ignore corrected ECC errors */
-	if (mtd_is_bitflip(err))
-		err = 0;
-	if (err || read != mtd->erasesize) {
+	err = mtdtest_read(mtd, addr, mtd->erasesize, iobuf);
+	if (err)
 		pr_err("error: read failed at %#llx\n", addr);
-		if (!err)
-			err = -EINVAL;
-	}
 
 	return err;
 }
 
 static int read_eraseblock_by_page(int ebnum)
 {
-	size_t read;
 	int i, err = 0;
 	loff_t addr = ebnum * mtd->erasesize;
 	void *buf = iobuf;
 
 	for (i = 0; i < pgcnt; i++) {
-		err = mtd_read(mtd, addr, pgsize, &read, buf);
-		/* Ignore corrected ECC errors */
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != pgsize) {
+		err = mtdtest_read(mtd, addr, pgsize, buf);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 			break;
 		}
 		addr += pgsize;
@@ -237,53 +172,32 @@ static int read_eraseblock_by_page(int ebnum)
 
 static int read_eraseblock_by_2pages(int ebnum)
 {
-	size_t read, sz = pgsize * 2;
+	size_t sz = pgsize * 2;
 	int i, n = pgcnt / 2, err = 0;
 	loff_t addr = ebnum * mtd->erasesize;
 	void *buf = iobuf;
 
 	for (i = 0; i < n; i++) {
-		err = mtd_read(mtd, addr, sz, &read, buf);
-		/* Ignore corrected ECC errors */
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != sz) {
+		err = mtdtest_read(mtd, addr, sz, buf);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 			return err;
 		}
 		addr += sz;
 		buf += sz;
 	}
 	if (pgcnt % 2) {
-		err = mtd_read(mtd, addr, pgsize, &read, buf);
-		/* Ignore corrected ECC errors */
-		if (mtd_is_bitflip(err))
-			err = 0;
-		if (err || read != pgsize) {
+		err = mtdtest_read(mtd, addr, pgsize, buf);
+		if (err) {
 			pr_err("error: read failed at %#llx\n",
 			       addr);
-			if (!err)
-				err = -EINVAL;
 		}
 	}
 
 	return err;
 }
 
-static int is_block_bad(int ebnum)
-{
-	loff_t addr = ebnum * mtd->erasesize;
-	int ret;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
 static inline void start_timing(void)
 {
 	do_gettimeofday(&start);
@@ -308,30 +222,6 @@ static long calc_speed(void)
 	return k;
 }
 
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kzalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	if (!mtd_can_have_bb(mtd))
-		goto out;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-out:
-	goodebcnt = ebcnt - bad;
-	return 0;
-}
-
 static int __init mtd_speedtest_init(void)
 {
 	int err, i, blocks, j, k;
@@ -387,11 +277,18 @@ static int __init mtd_speedtest_init(void)
 
 	prandom_bytes(iobuf, mtd->erasesize);
 
-	err = scan_for_bad_eraseblocks();
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
+	for (i = 0; i < ebcnt; i++) {
+		if (!bbt[i])
+			goodebcnt++;
+	}
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -425,7 +322,7 @@ static int __init mtd_speedtest_init(void)
 	speed = calc_speed();
 	pr_info("eraseblock read speed is %ld KiB/s\n", speed);
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -459,7 +356,7 @@ static int __init mtd_speedtest_init(void)
 	speed = calc_speed();
 	pr_info("page read speed is %ld KiB/s\n", speed);
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -496,14 +393,9 @@ static int __init mtd_speedtest_init(void)
 	/* Erase all eraseblocks */
 	pr_info("Testing erase speed\n");
 	start_timing();
-	for (i = 0; i < ebcnt; ++i) {
-		if (bbt[i])
-			continue;
-		err = erase_eraseblock(i);
-		if (err)
-			goto out;
-		cond_resched();
-	}
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
+	if (err)
+		goto out;
 	stop_timing();
 	speed = calc_speed();
 	pr_info("erase speed is %ld KiB/s\n", speed);
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 7/7 mtd: mtd_subpagetest: use mtd_test module

In reply to Akinobu Mita

Use mtdtest_scan_for_bad_eraseblocks() and mtdtest_erase_whole_device() in mtd_test module.

Cc Adrian Hunter <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/mtd/tests/mtd_subpagetest.c | 87 ++++---------------------------------
 1 file changed, 9 insertions(+), 78 deletions(-)
drivers/mtd/tests/mtd_subpagetest.c +9 -78
index e41a04f..0db1247 100644
@@ -30,6 +30,8 @@
 #include <linux/sched.h>
 #include <linux/random.h>
 
+#include "mtd_test.h"
+
 static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -51,50 +53,6 @@ static inline void clear_data(unsigned char *buf, size_t len)
 	memset(buf, 0, len);
 }
 
-static int erase_eraseblock(int ebnum)
-{
-	int err;
-	struct erase_info ei;
-	loff_t addr = ebnum * mtd->erasesize;
-
-	memset(&ei, 0, sizeof(struct erase_info));
-	ei.mtd  = mtd;
-	ei.addr = addr;
-	ei.len  = mtd->erasesize;
-
-	err = mtd_erase(mtd, &ei);
-	if (err) {
-		pr_err("error %d while erasing EB %d\n", err, ebnum);
-		return err;
-	}
-
-	if (ei.state == MTD_ERASE_FAILED) {
-		pr_err("some erase error occurred at EB %d\n",
-		       ebnum);
-		return -EIO;
-	}
-
-	return 0;
-}
-
-static int erase_whole_device(void)
-{
-	int err;
-	unsigned int i;
-
-	pr_info("erasing whole device\n");
-	for (i = 0; i < ebcnt; ++i) {
-		if (bbt[i])
-			continue;
-		err = erase_eraseblock(i);
-		if (err)
-			return err;
-		cond_resched();
-	}
-	pr_info("erased %u eraseblocks\n", i);
-	return 0;
-}
-
 static int write_eraseblock(int ebnum)
 {
 	size_t written;
@@ -317,36 +275,6 @@ static int verify_all_eraseblocks_ff(void)
 	return 0;
 }
 
-static int is_block_bad(int ebnum)
-{
-	loff_t addr = ebnum * mtd->erasesize;
-	int ret;
-
-	ret = mtd_block_isbad(mtd, addr);
-	if (ret)
-		pr_info("block %d is bad\n", ebnum);
-	return ret;
-}
-
-static int scan_for_bad_eraseblocks(void)
-{
-	int i, bad = 0;
-
-	bbt = kzalloc(ebcnt, GFP_KERNEL);
-	if (!bbt)
-		return -ENOMEM;
-
-	pr_info("scanning for bad eraseblocks\n");
-	for (i = 0; i < ebcnt; ++i) {
-		bbt[i] = is_block_bad(i) ? 1 : 0;
-		if (bbt[i])
-			bad += 1;
-		cond_resched();
-	}
-	pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
-	return 0;
-}
-
 static int __init mtd_subpagetest_init(void)
 {
 	int err = 0;
@@ -396,12 +324,15 @@ static int __init mtd_subpagetest_init(void)
 	readbuf = kmalloc(bufsize, GFP_KERNEL);
 	if (!readbuf)
 		goto out;
+	bbt = kzalloc(ebcnt, GFP_KERNEL);
+	if (!bbt)
+		goto out;
 
-	err = scan_for_bad_eraseblocks();
+	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -433,7 +364,7 @@ static int __init mtd_subpagetest_init(void)
 	}
 	pr_info("verified %u eraseblocks\n", i);
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
@@ -471,7 +402,7 @@ static int __init mtd_subpagetest_init(void)
 	}
 	pr_info("verified %u eraseblocks\n", i);
 
-	err = erase_whole_device();
+	err = mtdtest_erase_whole_device(mtd, bbt, ebcnt);
 	if (err)
 		goto out;
 
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

In reply to Akinobu Mita
Quoted 11 lines · Akinobu Mita

This introduces mtd_test module which contains the following functions used by several mtd/tests modules.

- mtdtest_erase_eraseblock()
- mtdtest_scan_for_bad_eraseblocks()
- mtdtest_erase_whole_device()

This mtd_test module also provides the following wrapper functions for mtd_read() and mtd_write() in order to simplify the return value check in mtd/tests modules.

Quoted 5 lines

- mtdtest_read()
- mtdtest_write()

These functions will be used for reducing code duplication among mtd/tests modules later.

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

[* modprobe would solve this problem, but these tests are often compiled and run by hand, sometimes on systems without the convenience of modprobe ]

We could still accomplish the reduction in (source) code duplication by simply including these simple routines in a header, then the code would be compiled into each test module. I realize this isn't typically the "best" way to share code, but since these are just test modules and really don't need to be optimized for code size, I think it is worth avoiding the extra step of inserting another module.

Quoted 7 lines
---
 drivers/mtd/tests/Makefile   |   1 +
 drivers/mtd/tests/mtd_test.c | 117 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/tests/mtd_test.h |  11 ++++
 3 files changed, 129 insertions(+)
 create mode 100644 drivers/mtd/tests/mtd_test.c
 create mode 100644 drivers/mtd/tests/mtd_test.h

If we still keep the mtd_test module separate, I might rename it to help distinguish it from any of the other modules, which actually run tests. Perhaps include "lib" in the name? Like "libmtdtest.{c,h}"?

Quoted 6 lines
drivers/mtd/tests/mtd_test.c new file +0 -0
new file mode 100644
index 0000000..1fa1d63
@@ -0,0 +1,117 @@

...

Quoted 1 line

+MODULE_LICENSE("GPL");

If we're keeping this as a module, we might want at least a MODULE_DESCRIPTION (to help a user understand why they need this extra module) and possibly a MODULE_AUTHOR?

Brian

#3 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

2013/7/28 Brian Norris <[email protected]>:

Quoted 12 lines

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

[* modprobe would solve this problem, but these tests are often compiled and run by hand, sometimes on systems without the convenience of modprobe ]

Quoted 6 lines

We could still accomplish the reduction in (source) code duplication by simply including these simple routines in a header, then the code would be compiled into each test module. I realize this isn't typically the "best" way to share code, but since these are just test modules and really don't need to be optimized for code size, I think it is worth avoiding the extra step of inserting another module.

I understand your concern and I'm going to change this series to move all these functions into a header file. But I'll wait other opinion for a while.

#4 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

Quoted 20 lines · Akinobu Mita

2013/7/28 Brian Norris <[email protected]>:

Quoted 12 lines

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

[* modprobe would solve this problem, but these tests are often compiled and run by hand, sometimes on systems without the convenience of modprobe ]

Quoted 6 lines

We could still accomplish the reduction in (source) code duplication by simply including these simple routines in a header, then the code would be compiled into each test module. I realize this isn't typically the "best" way to share code, but since these are just test modules and really don't need to be optimized for code size, I think it is worth avoiding the extra step of inserting another module.

Quoted 3 lines

I understand your concern and I'm going to change this series to move all these functions into a header file. But I'll wait other opinion for a while.

You can refer this.
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

And also Artem's feedback here
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

However, I didn't get much time to make this patch better as Artem suggested.

~Vikram

#5 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

Quoted 21 lines · Vikram Narayanan
Quoted 20 lines · Akinobu Mita

2013/7/28 Brian Norris <[email protected]>:

Quoted 18 lines

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

[* modprobe would solve this problem, but these tests are often compiled and run by hand, sometimes on systems without the convenience of modprobe ]

We could still accomplish the reduction in (source) code duplication by simply including these simple routines in a header, then the code would be compiled into each test module. I realize this isn't typically the "best" way to share code, but since these are just test modules and really don't need to be optimized for code size, I think it is worth avoiding the extra step of inserting another module.

Quoted 6 lines
Quoted 3 lines

I understand your concern and I'm going to change this series to move all these functions into a header file. But I'll wait other opinion for a while.

You can refer this.
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

http://article.gmane.org/gmane.linux.drivers.mtd/43933

Quoted 2 lines

And also Artem's feedback here
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

http://article.gmane.org/gmane.linux.drivers.mtd/44007

Quoted 5 lines

However, I didn't get much time to make this patch better as Artem suggested.

~Vikram

Sorry, Now updated the thread with correct links.

~Vikram

#6 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

2013/7/28 Vikram Narayanan <[email protected]>:

Quoted 31 lines · Vikram Narayanan
Quoted 30 lines · Akinobu Mita
Quoted 26 lines

2013/7/28 Brian Norris <[email protected]>:

Quoted 13 lines

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

[* modprobe would solve this problem, but these tests are often compiled and run by hand, sometimes on systems without the convenience of modprobe ]

Quoted 6 lines

We could still accomplish the reduction in (source) code duplication by simply including these simple routines in a header, then the code would be compiled into each test module. I realize this isn't typically the "best" way to share code, but since these are just test modules and really don't need to be optimized for code size, I think it is worth avoiding the extra step of inserting another module.

I understand your concern and I'm going to change this series to move all these functions into a header file. But I'll wait other opinion for a while.

Quoted 5 lines
Quoted 2 lines

You can refer this.
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

http://article.gmane.org/gmane.linux.drivers.mtd/43933

Thanks. I noticed that there were a few more places where erase_eraseblock() could be used in mtd/tests modules. I'll include these in next version of this patch set.

Quoted 5 lines
Quoted 2 lines

And also Artem's feedback here
<http://thread.gmane.org/gmane.linux.drivers.mtd/43932/focus=43941>

http://article.gmane.org/gmane.linux.drivers.mtd/44007

I checked all callsites of mtd_erase() in the tree, but there is no places where we can simply use erase_eraseblock(). If erase_eraseblock() can take additional arguments (callback and priv), there are only a few places (in mtdswap.c and ubi/io.c) where we can use it. So I think we don't need to extend mtdcore.c for now.

#7 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

In reply to Brian Norris
Quoted 10 lines · Brian Norris
Quoted 2 lines

These functions will be used for reducing code duplication among mtd/tests modules later.

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

The helpers do not have to be in a separate module. Here is a short patch demonstrating how we could put all the helpers to a single .c file and then just link it to the tests.

It renames mtd_oobtest.c to oobtest.c, and this part of the patch is omitted. Do it by hand if you want to try this patch:

$ mv drivers/mtd/tests/mtd_oobtest.c drivers/mtd/tests/oobtest.c

Note, I do realize that the code will actually be copied to every test module, but I think it is fine for our small test infrastructure.

From: Artem Bityutskiy <[email protected]>
Date: Fri, 2 Aug 2013 16:41:37 +0300
Subject: [PATCH] tmp: a patch to demonstrate a possible way of having test
helpers

---
 drivers/mtd/tests/Makefile       |   2 +
 drivers/mtd/tests/mtd_oobtest.c  | 714 --------------------------------------
 drivers/mtd/tests/oobtest.c      | 718 +++++++++++++++++++++++++++++++++++++++
 drivers/mtd/tests/test_helpers.c |   6 +
 drivers/mtd/tests/test_helpers.h |   1 +
 5 files changed, 727 insertions(+), 714 deletions(-)
 delete mode 100644 drivers/mtd/tests/mtd_oobtest.c
 create mode 100644 drivers/mtd/tests/oobtest.c
 create mode 100644 drivers/mtd/tests/test_helpers.c
 create mode 100644 drivers/mtd/tests/test_helpers.h
drivers/mtd/tests/Makefile +2 -0
index bd0065c..41a34d3 100644
@@ -7,3 +7,5 @@ obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o
 obj-$(CONFIG_MTD_TESTS) += mtd_nandbiterrs.o
+
+mtd_oobtest-objs := oobtest.o test_helpers.o
drivers/mtd/tests/test_helpers.c new file +6 -0
new file mode 100644
index 0000000..70c4692
@@ -0,0 +1,6 @@
+#include "test_helpers.h"
+
+int a_helper(void)
+{
+       return 0;
+}
drivers/mtd/tests/test_helpers.h new file +1 -0
new file mode 100644
index 0000000..0948a6e
@@ -0,0 +1 @@
+int a_helper(void);
Signature · 2 lines
Best Regards,
Artem Bityutskiy
#8 lore raw

Re: [PATCH -next 1/7] mtd: tests: introduce mtd_test module

2013/8/2 Artem Bityutskiy <[email protected]>:

Quoted 16 lines · Brian Norris
Quoted 10 lines
Quoted 2 lines

These functions will be used for reducing code duplication among mtd/tests modules later.

I like this idea. There is definitely too much code duplication.

However, there is an important tradeoff here: now to run these (very simple) tests, we have a two-step process*:

insmod mtd_test.ko
insmod mtd_<actualtest>.ko dev=<MTD>

The helpers do not have to be in a separate module. Here is a short patch demonstrating how we could put all the helpers to a single .c file and then just link it to the tests.

Quoted 7 lines

It renames mtd_oobtest.c to oobtest.c, and this part of the patch is omitted. Do it by hand if you want to try this patch:

$ mv drivers/mtd/tests/mtd_oobtest.c drivers/mtd/tests/oobtest.c

Note, I do realize that the code will actually be copied to every test module, but I think it is fine for our small test infrastructure.

I took this idea. I have finished rewriting this patch series and testing with nandsim using badblocks module parameter. I'll send next version later on.