Re: [U-Boot] [PATCH v2 16/17] dm: i2c: Add tests for I2C

2014-11-16 Thread Tom Rini
On Tue, Nov 11, 2014 at 10:46:32AM -0700, Simon Glass wrote:

 Add some basic tests to check that the system works as expected.
 
 Signed-off-by: Simon Glass s...@chromium.org

Reviewed-by: Tom Rini tr...@ti.com

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 16/17] dm: i2c: Add tests for I2C

2014-11-16 Thread Heiko Schocher

Hello Simon,

Am 11.11.2014 18:46, schrieb Simon Glass:

Add some basic tests to check that the system works as expected.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2:
- Add a test for automatic binding of generic I2C devices
- Add a new asm/test.h header for tests in sandbox

  arch/sandbox/include/asm/test.h |  15 ++
  drivers/i2c/sandbox_i2c.c   |   8 +++
  test/dm/Makefile|   1 +
  test/dm/i2c.c   | 112 
  test/dm/test.dts|  17 ++
  5 files changed, 153 insertions(+)
  create mode 100644 arch/sandbox/include/asm/test.h
  create mode 100644 test/dm/i2c.c


Acked-by: Heiko Schocher h...@denx.de

bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 16/17] dm: i2c: Add tests for I2C

2014-11-11 Thread Simon Glass
Add some basic tests to check that the system works as expected.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v2:
- Add a test for automatic binding of generic I2C devices
- Add a new asm/test.h header for tests in sandbox

 arch/sandbox/include/asm/test.h |  15 ++
 drivers/i2c/sandbox_i2c.c   |   8 +++
 test/dm/Makefile|   1 +
 test/dm/i2c.c   | 112 
 test/dm/test.dts|  17 ++
 5 files changed, 153 insertions(+)
 create mode 100644 arch/sandbox/include/asm/test.h
 create mode 100644 test/dm/i2c.c

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
new file mode 100644
index 000..d7f7bb5
--- /dev/null
+++ b/arch/sandbox/include/asm/test.h
@@ -0,0 +1,15 @@
+/*
+ * Test-related constants for sandbox
+ *
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#ifndef __ASM_TEST_H
+#define __ASM_TEST_H
+
+/* The sandbox driver always permits an I2C device with this address */
+#define SANDBOX_I2C_TEST_ADDR  0x59
+
+#endif
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
index 3beb0f9..6d7f114 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -11,6 +11,7 @@
 #include errno.h
 #include fdtdec.h
 #include i2c.h
+#include asm/test.h
 #include dm/lists.h
 #include dm/device-internal.h
 
@@ -67,6 +68,10 @@ static int sandbox_i2c_probe_chip(struct udevice *bus, uint 
chip_addr)
struct udevice *emul;
int ret;
 
+   /* Special test code to return success but with no emulation */
+   if (chip_addr == SANDBOX_I2C_TEST_ADDR)
+   return 0;
+
ret = get_emul(bus, chip_addr, emul, ops);
if (ret)
return ret;
@@ -129,6 +134,9 @@ static int sandbox_i2c_child_pre_probe(struct udevice *dev)
 {
struct dm_i2c_chip *i2c_chip = dev_get_parentdata(dev);
 
+   /* Ignore our test address */
+   if (i2c_chip-chip_addr == SANDBOX_I2C_TEST_ADDR)
+   return 0;
return i2c_chip_ofdata_to_platdata(gd-fdt_blob, dev-of_offset,
   i2c_chip);
 }
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 75d3d41..612aa95 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -20,4 +20,5 @@ ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_GPIO) += gpio.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
+obj-$(CONFIG_DM_I2C) += i2c.o
 endif
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
new file mode 100644
index 000..3d5d066
--- /dev/null
+++ b/test/dm/i2c.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include common.h
+#include dm.h
+#include fdtdec.h
+#include i2c.h
+#include dm/device-internal.h
+#include dm/test.h
+#include dm/uclass-internal.h
+#include dm/ut.h
+#include dm/util.h
+#include asm/state.h
+#include asm/test.h
+
+static const int busnum;
+static const int chip = 0x2c;
+
+/* Test that we can find buses and chips */
+static int dm_test_i2c_find(struct dm_test_state *dms)
+{
+   struct udevice *bus, *dev;
+   const int no_chip = 0x10;
+
+   ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_I2C, busnum,
+  false, bus));
+
+   /*
+* i2c_post_bind() will bind devices to chip selects. Check this then
+* remove the emulation and the slave device.
+*/
+   ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, bus));
+   ut_assertok(i2c_probe(bus, chip, dev));
+   ut_asserteq(-ENODEV, i2c_probe(bus, no_chip, dev));
+   ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_I2C, 1, bus));
+
+   return 0;
+}
+DM_TEST(dm_test_i2c_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_i2c_read_write(struct dm_test_state *dms)
+{
+   struct udevice *bus, *dev;
+   uint8_t buf[5];
+
+   ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, bus));
+   ut_assertok(i2c_get_chip(bus, chip, dev));
+   ut_assertok(i2c_read(dev, 0, buf, 5));
+   ut_assertok(memcmp(buf, \0\0\0\0\0, sizeof(buf)));
+   ut_assertok(i2c_write(dev, 2, (uint8_t *)AB, 2));
+   ut_assertok(i2c_read(dev, 0, buf, 5));
+   ut_assertok(memcmp(buf, \0\0AB\0, sizeof(buf)));
+
+   return 0;
+}
+DM_TEST(dm_test_i2c_read_write, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_i2c_speed(struct dm_test_state *dms)
+{
+   struct udevice *bus, *dev;
+   uint8_t buf[5];
+
+   ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, bus));
+   ut_assertok(i2c_get_chip(bus, chip, dev));
+   ut_assertok(i2c_set_bus_speed(bus, 10));
+   ut_assertok(i2c_read(dev, 0, buf, 5));
+   ut_assertok(i2c_set_bus_speed(bus, 40));
+   ut_asserteq(40, i2c_get_bus_speed(bus));
+   ut_assertok(i2c_read(dev, 0, buf, 5));
+