[U-Boot] [PATCH v2 26/30] dm: spi: Add tests

Simon Glass sjg at chromium.org
Mon Sep 15 14:33:43 CEST 2014


These tests use SPI flash (and the sandbox emulation) to operate.

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

Changes in v2:
- Create a 'spi.bin' file for the SPI tests

 test/dm/Makefile   |  1 +
 test/dm/spi.c      | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 test/dm/test-dm.sh |  2 ++
 3 files changed, 50 insertions(+)
 create mode 100644 test/dm/spi.c

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 5c2415e..d1b9c9a 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -18,4 +18,5 @@ obj-$(CONFIG_DM_TEST) += core.o
 obj-$(CONFIG_DM_TEST) += ut.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_GPIO) += gpio.o
+obj-$(CONFIG_DM_SPI) += spi.o
 endif
diff --git a/test/dm/spi.c b/test/dm/spi.c
new file mode 100644
index 0000000..45aabeb
--- /dev/null
+++ b/test/dm/spi.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <spi.h>
+#include <spi_flash.h>
+#include <dm/test.h>
+#include <dm/ut.h>
+#include <dm/util.h>
+#include <asm/state.h>
+
+/* Test that sandbox SPI works correctly */
+static int dm_test_spi(struct dm_test_state *dms)
+{
+	struct spi_slave *slave;
+	struct udevice *dev;
+	const int busnum = 0, cs = 0, mode = 0;
+	const char dout[5] = {0x9f};
+	unsigned char din[5];
+
+	ut_assertok(spi_get_bus_and_cs(busnum, cs, 1000000, mode, NULL, 0,
+				       &dev, &slave));
+	ut_assertok(spi_claim_bus(slave));
+	ut_assertok(spi_xfer(slave, 40, dout, din,
+			     SPI_XFER_BEGIN | SPI_XFER_END));
+	ut_asserteq(0xff, din[0]);
+	ut_asserteq(0x20, din[1]);
+	ut_asserteq(0x20, din[2]);
+	ut_asserteq(0x15, din[3]);
+	spi_release_bus(slave);
+
+	/*
+	 * Since we are about to destroy all devices, we must tell sandbox
+	 * to forget the emulation device
+	 */
+#ifdef CONFIG_DM_SPI_FLASH
+	sandbox_sf_unbind_emul(state_get_current(), busnum, cs);
+#endif
+
+	return 0;
+}
+DM_TEST(dm_test_spi, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-dm.sh b/test/dm/test-dm.sh
index ef5aca5..bb99677 100755
--- a/test/dm/test-dm.sh
+++ b/test/dm/test-dm.sh
@@ -4,4 +4,6 @@ NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
 dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb
 make O=sandbox sandbox_config
 make O=sandbox -s -j${NUM_CPUS}
+dd if=/dev/zero of=spi.bin bs=1M count=2
 ./sandbox/u-boot -d test/dm/test.dtb -c "dm test"
+rm spi.bin
-- 
2.1.0.rc2.206.gedb03e5



More information about the U-Boot mailing list