diff mbox

[U-Boot,v2,23/24] dm: mmc: test: Add tests for MMC

Message ID 1462132365-11536-24-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass May 1, 2016, 7:52 p.m. UTC
Add a simple test which checks that a sandbox-emulated SD card can be used
correctly. This tests plumbing through the MMC stack's block-device
implementaion.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Rebase to master

 test/dm/Makefile |  4 +---
 test/dm/mmc.c    | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

Comments

Simon Glass May 14, 2016, 7:38 p.m. UTC | #1
On 1 May 2016 at 13:52, Simon Glass <sjg@chromium.org> wrote:
> Add a simple test which checks that a sandbox-emulated SD card can be used
> correctly. This tests plumbing through the MMC stack's block-device
> implementaion.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
> - Rebase to master
>
>  test/dm/Makefile |  4 +---
>  test/dm/mmc.c    | 19 +++++++++++++++++++
>  2 files changed, 20 insertions(+), 3 deletions(-)

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 8ec391b..9a11ae0 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -21,9 +21,7 @@  obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_LED) += led.o
-
-# Disable temporarily
-# obj-$(CONFIG_DM_MMC) += mmc.o
+obj-$(CONFIG_DM_MMC) += mmc.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_RAM) += ram.o
 obj-y += regmap.o
diff --git a/test/dm/mmc.c b/test/dm/mmc.c
index 0461423..5bca4b7 100644
--- a/test/dm/mmc.c
+++ b/test/dm/mmc.c
@@ -25,3 +25,22 @@  static int dm_test_mmc_base(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_mmc_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_mmc_blk(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	struct blk_desc *dev_desc;
+	char cmp[1024];
+
+	ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
+	ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
+
+	/* Read a few blocks and look for the string we expect */
+	ut_asserteq(512, dev_desc->blksz);
+	memset(cmp, '\0', sizeof(cmp));
+	ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp));
+	ut_assertok(strcmp(cmp, "this is a test"));
+
+	return 0;
+}
+DM_TEST(dm_test_mmc_blk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);