[U-Boot] [PATCH v3 10/11] clk: test: Provide unit test for clk_get_parent_rate() method
Lukasz Majewski
lukma at denx.de
Thu Apr 25 10:29:52 UTC 2019
This commit provides sandbox unit test for clk_get_parent_rate() method.
For testing the 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_parent_rate() relies on dev->driver_data having the pointer
to proper struct clk.
It uses internally clk_get_parent() method also tested by this test.
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 | 26 ++++++++++++++++++++++++++
test/dm/clk.c | 1 +
3 files changed, 35 insertions(+)
diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h
index 90f925109f..1df9534236 100644
--- a/arch/sandbox/include/asm/clk.h
+++ b/arch/sandbox/include/asm/clk.h
@@ -79,6 +79,14 @@ int sandbox_clk_test_get_by_id(struct udevice *dev);
*/
int sandbox_clk_test_get_bulk(struct udevice *dev);
/**
+ * sandbox_clk_test_get_parent_rate - Ask the sandbox clock test device to
+ * query a passed clock's parent rate.
+ *
+ * @dev: The sandbox clock test (client) devivce.
+ * @return: The rate of the clock
+ */
+ulong sandbox_clk_test_get_parent_rate(struct udevice *dev);
+/**
* sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
* clock's rate.
*
diff --git a/drivers/clk/clk_sandbox_test.c b/drivers/clk/clk_sandbox_test.c
index 4d276f55b9..8ea15614c1 100644
--- a/drivers/clk/clk_sandbox_test.c
+++ b/drivers/clk/clk_sandbox_test.c
@@ -64,6 +64,32 @@ int sandbox_clk_test_get_bulk(struct udevice *dev)
return clk_get_bulk(dev, &sbct->bulk);
}
+ulong sandbox_clk_test_get_parent_rate(struct udevice *dev)
+{
+ struct sandbox_clk_test *sbct = dev_get_priv(dev);
+ struct clk *i2c_clk, *parent_clk;
+ struct udevice *parent_bkp;
+ ulong rate;
+
+ parent_clk = &sbct->clks[SANDBOX_CLK_TEST_ID_FIXED];
+ i2c_clk = &sbct->clks[SANDBOX_CLK_TEST_ID_I2C];
+
+ parent_clk->dev->driver_data = (ulong)parent_clk;
+ parent_bkp = i2c_clk->dev->parent;
+ i2c_clk->dev->parent = parent_clk->dev;
+
+ rate = clk_get_parent_rate(i2c_clk);
+
+ i2c_clk->dev->parent = parent_bkp;
+ parent_clk->dev->driver_data = 0;
+
+ /* Check if cache'd value is correct */
+ if (parent_clk->rate != 1234)
+ return 0;
+
+ return rate;
+}
+
ulong sandbox_clk_test_get_rate(struct udevice *dev, int id)
{
struct sandbox_clk_test *sbct = dev_get_priv(dev);
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 8b858cee01..94f475bd8e 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -100,6 +100,7 @@ static int dm_test_clk(struct unit_test_state *uts)
ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
ut_asserteq(0, sandbox_clk_test_get_by_id(dev_test));
+ ut_asserteq(1234, sandbox_clk_test_get_parent_rate(dev_test));
ut_assertok(sandbox_clk_test_free(dev_test));
return 0;
--
2.11.0
More information about the U-Boot
mailing list