[U-Boot] [PATCH 21/25] dm: spi: Add tests
Simon Glass
sjg at chromium.org
Tue Jul 15 02:56:28 CEST 2014
These tests use SPI flash (and the sandbox emulation) to operate.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
test/dm/Makefile | 1 +
test/dm/spi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 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);
--
2.0.0.526.g5318336
More information about the U-Boot
mailing list