dm: mmc: test: Add tests for MMC
authorSimon Glass <sjg@chromium.org>
Sun, 1 May 2016 19:52:44 +0000 (13:52 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 17 May 2016 15:54:43 +0000 (09:54 -0600)
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>
test/dm/Makefile
test/dm/mmc.c

index 8ec391b6a4796380bd5bdde0e6b29dc37207cd96..9a11ae0a147a19a742440326b2e619839d771f83 100644 (file)
@@ -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
index 046142322da2c70f697f84bd61087f95a5e2dcbb..5bca4b79d597b43fe2ea0ffde788d422e5b2fa93 100644 (file)
@@ -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);