From patchwork Sat Aug 3 09:52:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 264406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D3C52C0098 for ; Sat, 3 Aug 2013 19:54:00 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YWj-0002ah-0y; Sat, 03 Aug 2013 09:53:33 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YWh-0006Z8-93; Sat, 03 Aug 2013 09:53:31 +0000 Received: from mail-pd0-x231.google.com ([2607:f8b0:400e:c02::231]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V5YWd-0006Xu-OI for linux-mtd@lists.infradead.org; Sat, 03 Aug 2013 09:53:29 +0000 Received: by mail-pd0-f177.google.com with SMTP id u10so1492933pdi.36 for ; Sat, 03 Aug 2013 02:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=YqQCnwHCUni0OA/4CsMdBHluuKuIeuk3WTuQxhPvd4A=; b=wIHpBYP+7Ei+Hk5BhStUC/2fvJX61Hig5VIWiKQTSUtP7eZHjwuWvLXXWBZrTx0ud0 pbkzlkzLVWkgn0LNbA6M3WNgWt+Me0taDXxoipYpsmGvjl7WbUNm0OUw0ADTSYoeFBt4 pXkMchtp5kl56dcEmL1Sei9hDOMDVhDmX4IBqzAIWKgkG154Cq180xIvR5wQfDn+jBxt Q4j8V/KmO3ggbM++aa8TtJWNy9zbcZYMjaacT85Cn7T3RPvIpc4lU7zPaTGff0ilZKLk CCH4DTABYFHT8m3F9LwqGMHIg/TRH3waxYoZo+BFs2l8qDRJ186xkgE5g5NwaGr0Fo1s WIdw== X-Received: by 10.66.2.7 with SMTP id 7mr14848870paq.181.1375523583923; Sat, 03 Aug 2013 02:53:03 -0700 (PDT) Received: from localhost.localdomain (KD113145060135.ppp-bb.dion.ne.jp. [113.145.60.135]) by mx.google.com with ESMTPSA id ib9sm15295755pbc.43.2013.08.03.02.53.02 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 03 Aug 2013 02:53:03 -0700 (PDT) From: Akinobu Mita To: linux-mtd@lists.infradead.org Subject: [PATCH -next v2 01/10] mtd: tests: introduce helper functions Date: Sat, 3 Aug 2013 18:52:07 +0900 Message-Id: <1375523536-32671-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1375523536-32671-1-git-send-email-akinobu.mita@gmail.com> References: <1375523536-32671-1-git-send-email-akinobu.mita@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130803_055327_942728_57EE9A86 X-CRM114-Status: GOOD ( 17.95 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (akinobu.mita[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Artem Bityutskiy , Vikram Narayanan , Akinobu Mita , Adrian Hunter , Brian Norris , David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This introduces the helper functions which can be used by several mtd/tests modules. The following three functions are used all over the test modules. - mtdtest_erase_eraseblock() - mtdtest_scan_for_bad_eraseblocks() - mtdtest_erase_good_eraseblocks() The following are wrapper functions for mtd_read() and mtd_write() which can simplify the return value check. - mtdtest_read() - mtdtest_write() All helpers are put into a single .c file and it will be linked to every test module later. The code will actually be copied to every test module, but it is fine for our small test infrastructure. Signed-off-by: Akinobu Mita Cc: Brian Norris Cc: Vikram Narayanan Cc: Adrian Hunter Cc: Artem Bityutskiy Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org --- * Changes from v1 - link a signle object including helper functions to the test modules, instead of providing a separate module. - extend mtdtest_scan_for_bad_eraseblocks() so that it can specify any contiguous erase blocks. - rename mtdtest_erase_whole_device() to mtdtest_erase_good_eraseblocks() and extend it so that it can specify any contiguous erase blocks. drivers/mtd/tests/mtd_test.c | 110 +++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/tests/mtd_test.h | 11 +++++ 2 files changed, 121 insertions(+) create mode 100644 drivers/mtd/tests/mtd_test.c create mode 100644 drivers/mtd/tests/mtd_test.h diff --git a/drivers/mtd/tests/mtd_test.c b/drivers/mtd/tests/mtd_test.c new file mode 100644 index 0000000..9e63896 --- /dev/null +++ b/drivers/mtd/tests/mtd_test.c @@ -0,0 +1,110 @@ +#define pr_fmt(fmt) "mtd_test: " fmt + +#include +#include +#include +#include + +#include "mtd_test.h" + +int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned 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_info("error %d while erasing EB %d\n", err, ebnum); + return err; + } + + if (ei.state == MTD_ERASE_FAILED) { + pr_info("some erase error occurred at EB %d\n", ebnum); + return -EIO; + } + return 0; +} + +static int is_block_bad(struct mtd_info *mtd, unsigned 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; +} + +int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, + unsigned int eb, int ebcnt) +{ + int i, bad = 0; + + 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(mtd, eb + i) ? 1 : 0; + if (bbt[i]) + bad += 1; + cond_resched(); + } + pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); + + return 0; +} + +int mtdtest_erase_good_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, + unsigned int eb, int ebcnt) +{ + int err; + unsigned int i; + + for (i = 0; i < ebcnt; ++i) { + if (bbt[i]) + continue; + err = mtdtest_erase_eraseblock(mtd, eb + i); + if (err) + return err; + cond_resched(); + } + + return 0; +} + +int mtdtest_read(struct mtd_info *mtd, loff_t addr, size_t size, void *buf) +{ + size_t read; + int err; + + err = mtd_read(mtd, addr, size, &read, buf); + /* Ignore corrected ECC errors */ + if (mtd_is_bitflip(err)) + err = 0; + if (!err && read != size) + err = -EINVAL; + + return err; +} + +int mtdtest_write(struct mtd_info *mtd, loff_t addr, size_t size, + const void *buf) +{ + size_t written; + int err; + + err = mtd_write(mtd, addr, size, &written, buf); + if (!err && written != size) + err = -EIO; + + return err; +} diff --git a/drivers/mtd/tests/mtd_test.h b/drivers/mtd/tests/mtd_test.h new file mode 100644 index 0000000..f437c77 --- /dev/null +++ b/drivers/mtd/tests/mtd_test.h @@ -0,0 +1,11 @@ +#include + +int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum); +int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, + unsigned int eb, int ebcnt); +int mtdtest_erase_good_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, + unsigned int eb, 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);