[U-Boot] [PATCH v4 10/13] clk: test: Provide unit test for clk_get_by_id() method
Lukasz Majewski
lukma at denx.de
Thu May 16 22:10:39 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 v4: None
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 f301ecbb45..1685532259 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -120,8 +120,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