[U-Boot] [PATCH v10 27/27] test: dm: add tests for mtd devices

Jagan Teki jagan at amarulasolutions.com
Thu Dec 28 06:12:33 UTC 2017


Add some tests to check that mtd devices work as expected,
more tests will add it in future.

Also removed CMD_MTDPARTS which breaking driver-model MTD.

Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
 configs/sandbox_defconfig |  8 +++++++-
 test/dm/Makefile          |  1 +
 test/dm/mtd.c             | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 test/dm/mtd.c

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 7efb4eb..658d9f2 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -65,7 +65,6 @@ CONFIG_CMD_BTRFS=y
 CONFIG_CMD_CBFS=y
 CONFIG_CMD_CRAMFS=y
 CONFIG_CMD_EXT4_WRITE=y
-CONFIG_CMD_MTDPARTS=y
 CONFIG_CMD_LOG=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
@@ -197,3 +196,10 @@ CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
 CONFIG_UT_OVERLAY=y
+CONFIG_MTD=y
+CONFIG_MTD_SPI_NOR=y
+CONFIG_MTD_M25P80=y
+CONFIG_SPI_NOR_STMICRO=y
+CONFIG_SPI_NOR_SPANSION=y
+CONFIG_SPI_NOR_WINBOND=y
+CONFIG_SPI_NOR_MACRONIX=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 513c456..55f7450 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
+obj-$(CONFIG_MTD) += mtd.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_PHY) += phy.o
diff --git a/test/dm/mtd.c b/test/dm/mtd.c
new file mode 100644
index 0000000..fe98593
--- /dev/null
+++ b/test/dm/mtd.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 Jagan Teki <jagan at openedev.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/state.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+#include <mtd.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/spi-nor.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Test that we can find mtd devices without probing them */
+static int dm_test_mtd_find(struct unit_test_state *uts)
+{
+	struct udevice *mtd, *spinor, *dev;
+
+	ut_assertok(mtd_create_device(mtd, "spinor_mtd", "test",
+				      MTD_IF_TYPE_SPI_NOR, &spinor));
+
+	ut_asserteq(-ENODEV, mtd_find_device(MTD_IF_TYPE_SPI_NOR, 1, &dev));
+	ut_assertok(mtd_find_device(MTD_IF_TYPE_SPI_NOR, 0, &dev));
+	ut_asserteq_ptr(spinor, dev);
+
+	return 0;
+}
+DM_TEST(dm_test_mtd_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.7.4



More information about the U-Boot mailing list