[U-Boot] [PATCH v3 09/11] clk: test: Provide unit test for clk_get_by_id() method

Lukasz Majewski lukma at denx.de
Thu Apr 25 10:29:51 UTC 2019


This commit provides sandbox unit test for clk_get_by_id() method.

To test it default test clocks setup had to be adjusted to emulate
structure similar to clocks in the Common Clock Framework [CCF] (for
iMX devices).

The clk_get_by_id() relies on dev->driver_data having the pointer to
struct clk.

Signed-off-by: Lukasz Majewski <lukma at denx.de>

---

Changes in v3:
- New patch

 arch/sandbox/include/asm/clk.h |  8 ++++++++
 drivers/clk/clk_sandbox_test.c | 23 +++++++++++++++++++++++
 test/dm/clk.c                  |  3 ++-
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h
index 2b1c49f783..90f925109f 100644
--- a/arch/sandbox/include/asm/clk.h
+++ b/arch/sandbox/include/asm/clk.h
@@ -63,6 +63,14 @@ int sandbox_clk_query_enable(struct udevice *dev, int id);
  */
 int sandbox_clk_test_get(struct udevice *dev);
 /**
+ * sandbox_clk_test_get_by_id - Ask the sandbox clock test device to request its
+ * clocks by using clock id.
+ *
+ * @dev:	The sandbox clock test (client) devivce.
+ * @return:	0 if OK, or a negative error code.
+ */
+int sandbox_clk_test_get_by_id(struct udevice *dev);
+/**
  * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
  * clocks with the bulk clk API.
  *
diff --git a/drivers/clk/clk_sandbox_test.c b/drivers/clk/clk_sandbox_test.c
index e8465dbfad..4d276f55b9 100644
--- a/drivers/clk/clk_sandbox_test.c
+++ b/drivers/clk/clk_sandbox_test.c
@@ -34,6 +34,29 @@ int sandbox_clk_test_get(struct udevice *dev)
 	return 0;
 }
 
+int sandbox_clk_test_get_by_id(struct udevice *dev)
+{
+	struct sandbox_clk_test *sbct = dev_get_priv(dev);
+	struct clk *clkp, *i2c_clk;
+	ulong driver_data_bkp;
+	const int id = 24;
+	int ret, id_bkp;
+
+	i2c_clk = &sbct->clks[SANDBOX_CLK_TEST_ID_I2C];
+
+	id_bkp = i2c_clk->id;
+	i2c_clk->id = id;
+	driver_data_bkp = i2c_clk->dev->driver_data;
+	i2c_clk->dev->driver_data = (ulong)i2c_clk;
+
+	ret = clk_get_by_id(id, &clkp);
+
+	i2c_clk->id = id_bkp;
+	i2c_clk->dev->driver_data = driver_data_bkp;
+
+	return ret;
+}
+
 int sandbox_clk_test_get_bulk(struct udevice *dev)
 {
 	struct sandbox_clk_test *sbct = dev_get_priv(dev);
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 112d5cbbc9..8b858cee01 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -99,8 +99,9 @@ static int dm_test_clk(struct unit_test_state *uts)
 	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
 	ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
 
-	ut_assertok(sandbox_clk_test_free(dev_test));
+	ut_asserteq(0, sandbox_clk_test_get_by_id(dev_test));
 
+	ut_assertok(sandbox_clk_test_free(dev_test));
 	return 0;
 }
 DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT);
-- 
2.11.0



More information about the U-Boot mailing list