dm: core: Allow writing to a flat tree with ofnode
[platform/kernel/u-boot.git] / test / dm / sf.c
index 3788d59..17d43fe 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <mapmem.h>
@@ -14,6 +15,7 @@
 #include <asm/test.h>
 #include <dm/test.h>
 #include <dm/util.h>
+#include <test/test.h>
 #include <test/ut.h>
 
 /* Simple test of sandbox SPI flash */
@@ -23,6 +25,9 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
        int full_size = 0x200000;
        int size = 0x10000;
        u8 *src, *dst;
+       uint map_size;
+       ulong map_base;
+       uint offset;
        int i;
 
        src = map_sysmem(0x20000, full_size);
@@ -31,7 +36,7 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
 
        dst = map_sysmem(0x20000 + full_size, full_size);
        ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
-       ut_assertok(memcmp(src, dst, size));
+       ut_asserteq_mem(src, dst, size);
 
        /* Erase */
        ut_assertok(spi_flash_erase_dm(dev, 0, size));
@@ -44,7 +49,7 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
                src[i] = i;
        ut_assertok(spi_flash_write_dm(dev, 0, size, src));
        ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
-       ut_assertok(memcmp(src, dst, size));
+       ut_asserteq_mem(src, dst, size);
 
        /* Try the write-protect stuff */
        ut_assertok(uclass_first_device_err(UCLASS_SPI_EMUL, &emul));
@@ -54,6 +59,12 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
        sandbox_sf_set_block_protect(emul, 0);
        ut_asserteq(0, spl_flash_get_sw_write_prot(dev));
 
+       /* Check mapping */
+       ut_assertok(dm_spi_get_mmap(dev, &map_base, &map_size, &offset));
+       ut_asserteq(0x1000, map_base);
+       ut_asserteq(0x2000, map_size);
+       ut_asserteq(0x100, offset);
+
        /*
         * Since we are about to destroy all devices, we must tell sandbox
         * to forget the emulation device
@@ -62,7 +73,7 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
 
        return 0;
 }
-DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_flash, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
 /* Functional test that sandbox SPI flash works correctly */
 static int dm_test_spi_flash_func(struct unit_test_state *uts)
@@ -90,4 +101,4 @@ static int dm_test_spi_flash_func(struct unit_test_state *uts)
 
        return 0;
 }
-DM_TEST(dm_test_spi_flash_func, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_flash_func, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);