From patchwork Thu Oct 22 07:53:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 36653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32036B7BA8 for ; Thu, 22 Oct 2009 18:56:58 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1N0sUZ-00053e-7E; Thu, 22 Oct 2009 07:53:51 +0000 Received: from mail-gx0-f223.google.com ([209.85.217.223]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1N0sUS-00052c-7G for linux-mtd@lists.infradead.org; Thu, 22 Oct 2009 07:53:49 +0000 Received: by gxk23 with SMTP id 23so7723345gxk.2 for ; Thu, 22 Oct 2009 00:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=XFHqq9VK1VzGEEACOuu3JUxLGKqKg/kg0PnDIcqw5tg=; b=bJMHjt75x1VOgrSUoZXfmNUz0QtQux4kgvwetLaxSP2wUiT5fBFIoMmTUWFf+NefS/ dk4VCWT8AB3RmFy62XyYJNjypHTxYb97GkZFMic0vEVdeG8BRzSc7d+OYUX/dwaB95V8 GvypQaKgZypNUl12yb23/ia7oxj2QRiDD0GWo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=f0np3RNJP8vR27lnqkOcLtlyPh25jVDscs0Kz71xul3MdULEo7GL+SWw4bfskDgCSO omgL8HBdllEVhUWa8fSXSn50OYO1uaGOYn4v1T2BRUGUjYnOLfI+aIJ+3fGPn+lVUmKl g1oma9ZiTEn68HLHUFR+ztME08zpPZ/ivrLeI= Received: by 10.150.42.3 with SMTP id p3mr1346162ybp.63.1256198023128; Thu, 22 Oct 2009 00:53:43 -0700 (PDT) Received: from localhost ([220.110.185.192]) by mx.google.com with ESMTPS id 13sm81277gxk.5.2009.10.22.00.53.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 22 Oct 2009 00:53:41 -0700 (PDT) From: Akinobu Mita To: linux-mtd@lists.infradead.org Subject: [PATCH -v4 2/2] MTD: Add nand_ecc test module Date: Thu, 22 Oct 2009 16:53:33 +0900 Message-Id: <1256198013-10003-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.5.4.3 In-Reply-To: <1256198013-10003-1-git-send-email-akinobu.mita@gmail.com> References: <> <1256198013-10003-1-git-send-email-akinobu.mita@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20091022_035344_356136_4A3B1F9C X-CRM114-Status: GOOD ( 14.11 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- _SUMMARY_ Cc: Artem Bityutskiy , David Woodhouse , Akinobu Mita , vimal singh X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 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-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This module tests NAND ECC functions. The test is simple. 1. Create a 256 or 512 bytes block of data filled with random bytes (data) 2. Duplicate the data block and inject single bit error (error_data) 3. Try to correct error_data 4. Compare data and error_data Signed-off-by: Akinobu Mita Cc: David Woodhouse Cc: linux-mtd@lists.infradead.org Cc: Artem Bityutskiy Cc: vimal singh --- drivers/mtd/tests/Makefile | 1 + drivers/mtd/tests/mtd_nandecctest.c | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/tests/mtd_nandecctest.c diff --git a/drivers/mtd/tests/Makefile b/drivers/mtd/tests/Makefile index c1d5013..b44dcab 100644 --- a/drivers/mtd/tests/Makefile +++ b/drivers/mtd/tests/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o +obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c new file mode 100644 index 0000000..c1f3105 --- /dev/null +++ b/drivers/mtd/tests/mtd_nandecctest.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE) + +static void inject_single_bit_error(void *data, size_t size) +{ + unsigned long offset = random32() % (size * BITS_PER_BYTE); + + __change_bit(offset, data); +} + +static unsigned char 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]; + char testname[30]; + + BUG_ON(sizeof(data) < size); + + sprintf(testname, "nand-ecc-%zu", size); + + get_random_bytes(data, size); + + memcpy(error_data, 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); + + if (!memcmp(data, error_data, size)) { + printk(KERN_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); + + return -1; +} + +#else + +static int nand_ecc_test(const size_t size) +{ + return 0; +} + +#endif + +static int __init ecc_test_init(void) +{ + srandom32(jiffies); + + nand_ecc_test(256); + nand_ecc_test(512); + + return 0; +} + +static void __exit ecc_test_exit(void) +{ +} + +module_init(ecc_test_init); +module_exit(ecc_test_exit); + +MODULE_DESCRIPTION("NAND ECC function test module"); +MODULE_AUTHOR("Akinobu Mita"); +MODULE_LICENSE("GPL");